From 259a1aa71524a15235b17e5f70d4b0f8e238dd26 Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Thu, 11 Mar 2021 16:19:23 +0100 Subject: [PATCH] add convenience functions, docu, working tags, rm outdated code --- GUI/coregui/Models/JobModelFunctions.cpp | 2 +- GUI/coregui/Models/RealDataModel.cpp | 10 +++++++ GUI/coregui/Models/RealDataModel.h | 3 +++ .../Views/CommonWidgets/ItemSelectorWidget.h | 2 +- .../SpecularDataImportWidget.cpp | 7 ----- .../SpecularDataImportWidget.h | 1 - GUI/coregui/mainwindow/projectmanager.cpp | 27 +++++++++++++++++++ GUI/coregui/mainwindow/projectmanager.h | 10 +++++++ GUI/coregui/utils/GUIHelpers.cpp | 11 ++++++++ GUI/coregui/utils/GUIHelpers.h | 7 +++++ 10 files changed, 70 insertions(+), 10 deletions(-) diff --git a/GUI/coregui/Models/JobModelFunctions.cpp b/GUI/coregui/Models/JobModelFunctions.cpp index 6dd954fd9dc..7d0954fb4bd 100644 --- a/GUI/coregui/Models/JobModelFunctions.cpp +++ b/GUI/coregui/Models/JobModelFunctions.cpp @@ -202,7 +202,7 @@ void JobModelFunctions::copyRealDataItem(JobItem* jobItem, const RealDataItem* r // adapting the name to job name realDataItemCopy->dataItem()->setFileName(ItemFileNameUtils::jobReferenceFileName(*jobItem)); - // #baimport ++ copy members of realDataItem + // #baimport ++ copy members of realDataItem? if (!realDataItem->hasNativeData()) return; diff --git a/GUI/coregui/Models/RealDataModel.cpp b/GUI/coregui/Models/RealDataModel.cpp index a4295b6586d..f56212b70ac 100644 --- a/GUI/coregui/Models/RealDataModel.cpp +++ b/GUI/coregui/Models/RealDataModel.cpp @@ -117,6 +117,16 @@ QVector<RealDataItem*> RealDataModel::realDataItems() const return topItems<RealDataItem>(); } +QVector<RealDataItem*> RealDataModel::realDataItems1D() const +{ + return topItems<RealDataItem>([](const RealDataItem& item) { return item.isSpecularData(); }); +} + +QVector<RealDataItem*> RealDataModel::realDataItems2D() const +{ + return topItems<RealDataItem>([](const RealDataItem& item) { return !item.isSpecularData(); }); +} + InstrumentModel* RealDataModel::instrumentModel() const { return m_instrumentModel; diff --git a/GUI/coregui/Models/RealDataModel.h b/GUI/coregui/Models/RealDataModel.h index d7e9661dc19..1055d785f6f 100644 --- a/GUI/coregui/Models/RealDataModel.h +++ b/GUI/coregui/Models/RealDataModel.h @@ -40,6 +40,9 @@ public: RealDataItem* insertIntensityDataItem(); QVector<RealDataItem*> realDataItems() const; + QVector<RealDataItem*> realDataItems1D() const; + QVector<RealDataItem*> realDataItems2D() const; + InstrumentModel* instrumentModel() const; signals: diff --git a/GUI/coregui/Views/CommonWidgets/ItemSelectorWidget.h b/GUI/coregui/Views/CommonWidgets/ItemSelectorWidget.h index cd77490a576..6f3c2c8b047 100644 --- a/GUI/coregui/Views/CommonWidgets/ItemSelectorWidget.h +++ b/GUI/coregui/Views/CommonWidgets/ItemSelectorWidget.h @@ -28,7 +28,7 @@ class QListView; class SessionDecorationModel; //! The ItemSelectorWidget class holds QListView to show top level items of SessionModel. -//! Used in InstrumentView, ImportDataView, JobSelectorView to switch between items. +//! Used in InstrumentView and JobSelectorView to switch between items. class ItemSelectorWidget : public QWidget { Q_OBJECT diff --git a/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.cpp b/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.cpp index 02c03f452c5..5d7d5917490 100644 --- a/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.cpp +++ b/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.cpp @@ -210,7 +210,6 @@ void SpecularDataImportWidget::onFormatSelectionChanged() realDataItem()->setDataLoader(m_loader); updatePropertiesEdits(); updatePreview(); - applyProperties(); connect(m_loader, &AbstractDataLoader::propertiesChanged, this, &SpecularDataImportWidget::updatePreview); } @@ -248,7 +247,6 @@ void SpecularDataImportWidget::onCreateNewFormatButton() void SpecularDataImportWidget::onPropertiesChanged() { m_loader->applyProperties(); // #baTODO: may be duplicate - applyProperties(); QStringList errors, warnings; m_loader->importFile(realDataItem()->nativeFileName(), realDataItem(), &errors, &warnings); @@ -266,8 +264,3 @@ QString SpecularDataImportWidget::currentFileName() const { return realDataItem()->nativeFileName(); } - -void SpecularDataImportWidget::applyProperties() -{ - // #baimport seems obsolete -} diff --git a/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.h b/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.h index 0dbf4f26d79..f299163f096 100644 --- a/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.h +++ b/GUI/coregui/Views/SpecularDataWidgets/SpecularDataImportWidget.h @@ -60,7 +60,6 @@ private: void onCreateNewFormatButton(); void onPropertiesChanged(); QString currentFileName() const; - void applyProperties(); Ui::SpecularDataImportWidget* m_ui; AbstractDataLoader1D* m_loader; // only borrowed from realDataItem. Do not delete! diff --git a/GUI/coregui/mainwindow/projectmanager.cpp b/GUI/coregui/mainwindow/projectmanager.cpp index b85c54d536b..387f487ce2c 100644 --- a/GUI/coregui/mainwindow/projectmanager.cpp +++ b/GUI/coregui/mainwindow/projectmanager.cpp @@ -38,6 +38,8 @@ const QString S_AUTOSAVE = "EnableAutosave"; const QString S_DEFAULTPROJECTPATH = "DefaultProjectPath"; const QString S_RECENTPROJECTS = "RecentProjects"; const QString S_LASTUSEDIMPORTDIR = "LastUsedImportDir"; +const QString S_LASTUSEDIMPORFILTER1D = "LastUsedImportFilter1D"; +const QString S_LASTUSEDIMPORFILTER2D = "LastUsedImportFilter2D"; } // namespace ProjectManager::ProjectManager(MainWindow* parent) @@ -76,6 +78,9 @@ void ProjectManager::readSettings() if (settings.contains(S_LASTUSEDIMPORTDIR)) m_importDirectory = settings.value(S_LASTUSEDIMPORTDIR, QString()).toString(); + m_importFilter1D = settings.value(S_LASTUSEDIMPORFILTER1D, m_importFilter1D).toString(); + m_importFilter2D = settings.value(S_LASTUSEDIMPORFILTER2D, m_importFilter2D).toString(); + setAutosaveEnabled(settings.value(S_AUTOSAVE).toBool()); settings.endGroup(); @@ -93,6 +98,8 @@ void ProjectManager::writeSettings() if (!m_importDirectory.isEmpty()) settings.setValue(S_LASTUSEDIMPORTDIR, m_importDirectory); + settings.setValue(S_LASTUSEDIMPORFILTER1D, m_importFilter1D); + settings.setValue(S_LASTUSEDIMPORFILTER2D, m_importFilter2D); settings.endGroup(); } @@ -144,6 +151,16 @@ QString ProjectManager::userImportDir() const return m_importDirectory.isEmpty() ? userExportDir() : m_importDirectory; } +QString ProjectManager::recentlyUsedImportFilter1D() const +{ + return m_importFilter1D; +} + +QString ProjectManager::recentlyUsedImportFilter2D() const +{ + return m_importFilter2D; +} + //! Sets user import directory in system settings. void ProjectManager::setImportDir(const QString& dirname) @@ -158,6 +175,16 @@ void ProjectManager::setImportDirFromFilePath(const QString& filePath) m_importDirectory = QFileInfo(filePath).absolutePath(); } +void ProjectManager::setRecentlyUsedImportFilter1D(const QString& filter) +{ + m_importFilter1D = filter; +} + +void ProjectManager::setRecentlyUsedImportFilter2D(const QString& filter) +{ + m_importFilter2D = filter; +} + bool ProjectManager::isAutosaveEnabled() const { return m_saveService->isAutosaveEnabled(); diff --git a/GUI/coregui/mainwindow/projectmanager.h b/GUI/coregui/mainwindow/projectmanager.h index 7b861d2b447..a44b5e5330f 100644 --- a/GUI/coregui/mainwindow/projectmanager.h +++ b/GUI/coregui/mainwindow/projectmanager.h @@ -40,8 +40,12 @@ public: QString projectDir() const; QString userExportDir() const; QString userImportDir() const; + QString recentlyUsedImportFilter1D() const; + QString recentlyUsedImportFilter2D() const; void setImportDir(const QString& dirname); void setImportDirFromFilePath(const QString& filePath); + void setRecentlyUsedImportFilter1D(const QString& filter); + void setRecentlyUsedImportFilter2D(const QString& filter); bool isAutosaveEnabled() const; @@ -81,6 +85,12 @@ private: //!< Name of directory from there user prefer to import files QString m_importDirectory; + //! Recently used import filter for 1D files + QString m_importFilter1D; + + //! Recently used import filter for 2D files + QString m_importFilter2D; + QStringList m_recentProjects; MessageService* m_messageService; SaveService* m_saveService; diff --git a/GUI/coregui/utils/GUIHelpers.cpp b/GUI/coregui/utils/GUIHelpers.cpp index 0594e8f32b1..31d0236529e 100644 --- a/GUI/coregui/utils/GUIHelpers.cpp +++ b/GUI/coregui/utils/GUIHelpers.cpp @@ -16,6 +16,7 @@ #include "BAVersion.h" #include "GUI/coregui/Models/JobItem.h" #include "GUI/coregui/Models/RealDataItem.h" +#include "GUI/coregui/mainwindow/mainwindow.h" #include <QApplication> #include <QDateTime> #include <QDir> @@ -65,6 +66,11 @@ void information(QWidget* parent, const QString& title, const QString& text, messageBox->exec(); } +void information(const QString& title, const QString& text, const QString& detailedText) +{ + information(MainWindow::instance(), title, text, detailedText); +} + void warning(QWidget* parent, const QString& title, const QString& text, const QString& detailedText) { @@ -80,6 +86,11 @@ void warning(QWidget* parent, const QString& title, const QString& text, messageBox->exec(); } +void warning(const QString& title, const QString& text, const QString& detailedText) +{ + warning(MainWindow::instance(), title, text, detailedText); +} + bool question(QWidget* parent, const QString& title, const QString& text, const QString& detailedText, const QString& yesText, const QString& noText) { diff --git a/GUI/coregui/utils/GUIHelpers.h b/GUI/coregui/utils/GUIHelpers.h index 2118e76c822..dc8ea76d48a 100644 --- a/GUI/coregui/utils/GUIHelpers.h +++ b/GUI/coregui/utils/GUIHelpers.h @@ -42,11 +42,18 @@ private: void information(QWidget* parent, const QString& title, const QString& text, const QString& detailedText = ""); + +void information(const QString& title, const QString& text, const QString& detailedText = ""); + void warning(QWidget* parent, const QString& title, const QString& text, const QString& detailedText = ""); + +void warning(const QString& title, const QString& text, const QString& detailedText = ""); + bool question(QWidget* parent, const QString& title, const QString& text, const QString& detailedText = "", const QString& yesText = "&Yes", const QString& noText = "&No"); + bool okToDelete(QWidget* parent, const QString& title, const QString& text, const QString& detailedText = ""); -- GitLab