MCPcopy Create free account
hub / github.com/KDE/labplot / fileNameChanged

Method fileNameChanged

src/frontend/datasources/ImportFileWidget.cpp:1103–1188  ·  view source on GitHub ↗

SLOTS **************************************************************/ ! called on file name changes. Determines the file format (ASCII, binary etc.), if the file exists, and activates the corresponding options. */

Source from the content-addressed store, hash-verified

1101 and activates the corresponding options.
1102*/
1103void ImportFileWidget::fileNameChanged(const QString& name) {
1104 DEBUG(Q_FUNC_INFO << ", file name = " << STDSTRING(name))
1105 Q_EMIT error(QString()); // clear previous errors
1106
1107 const QString fileName = absolutePath(name);
1108 bool fileExists = QFile::exists(fileName);
1109 ui.gbOptions->setEnabled(fileExists);
1110 ui.cbFilter->setEnabled(fileExists);
1111 ui.cbFileType->setEnabled(fileExists);
1112 ui.bFileInfo->setEnabled(fileExists);
1113 ui.gbUpdateOptions->setEnabled(fileExists);
1114 if (!fileExists) {
1115 // file doesn't exist -> delete the content preview that is still potentially
1116 // available from the previously selected file
1117 ui.tePreview->clear();
1118 m_twPreview->clear();
1119 initOptionsWidget();
1120
1121 Q_EMIT fileNameChanged();
1122 return;
1123 }
1124
1125 // warn about opening project files
1126 bool isProjectFile = false;
1127 if (name.toLower().endsWith(QLatin1String(".opj"))) {
1128 Q_EMIT error(i18n("Origin Project files need to be opened with \"Import -> Origin Project\"!"));
1129 isProjectFile = true;
1130 } else if (name.toLower().endsWith(QLatin1String(".lml"))) {
1131 Q_EMIT error(i18n("LabPlot Project files need to be opened with \"Import -> LabPlot Project\"!"));
1132 isProjectFile = true;
1133 }
1134 if (isProjectFile) {
1135 ui.tePreview->clear();
1136 m_twPreview->clear();
1137 Q_EMIT fileNameChanged();
1138 return;
1139 }
1140
1141 if (currentSourceType() == LiveDataSource::SourceType::FileOrPipe) {
1142 const auto fileType = AbstractFileFilter::fileType(fileName);
1143 const auto* model = qobject_cast<const QStandardItemModel*>(ui.cbFileType->model());
1144 for (int i = 0; i < ui.cbFileType->count(); ++i) {
1145 const auto type = static_cast<AbstractFileFilter::FileType>(ui.cbFileType->itemData(i).toInt());
1146 // disable item if exclusive
1147 if (AbstractFileFilter::exclusiveFileType(type)) {
1148 auto* item = model->item(i);
1149 if (item)
1150 item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled));
1151 }
1152 }
1153 for (int i = 0; i < ui.cbFileType->count(); ++i) {
1154 if (static_cast<AbstractFileFilter::FileType>(ui.cbFileType->itemData(i).toInt()) == fileType) {
1155 // enable item if exlusive
1156 if (AbstractFileFilter::exclusiveFileType(fileType)) {
1157 auto* item = model->item(i);
1158 if (item)
1159 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1160 }

Callers 1

Calls 9

QStringClass · 0.50
setEnabledMethod · 0.45
clearMethod · 0.45
modelMethod · 0.45
countMethod · 0.45
flagsMethod · 0.45
currentIndexMethod · 0.45
setCurrentIndexMethod · 0.45

Tested by

no test coverage detected