diff --git a/App/AppOptions.cpp b/App/AppOptions.cpp index 4665a8297ce3b4acdb99589318697f731d9a356a..4c8d05cb51566f9d9683c6444bb1f38f57e73ab9 100644 --- a/App/AppOptions.cpp +++ b/App/AppOptions.cpp @@ -130,7 +130,7 @@ void ApplicationOptions::processOptions() } else if (m_variables_map.count("version")) { - std::cout << "BornAgain-" << GUI::Base::Path::getBornAgainVersionString().toStdString() + std::cout << "BornAgain-" << GUI::Path::getBornAgainVersionString().toStdString() << std::endl; exit(0); } diff --git a/App/main.cpp b/App/main.cpp index ecd980c14f9b0b1f446f715a3ca931dfddc6190c..fa937be782381ef4bab78e364677a6d75a10804b 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) int ret = -1; QApplication app(argc, argv); app.setApplicationName("BornAgain"); - app.setApplicationVersion(GUI::Base::Path::getBornAgainVersionString()); + app.setApplicationVersion(GUI::Path::getBornAgainVersionString()); app.setOrganizationName("BornAgain"); #ifndef Q_OS_MAC app.setWindowIcon(QIcon(":/images/BornAgain.ico")); @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) auto style = applicationSettings.styleToUse(); applicationSettings.loadStyle(style); - QString dir = GUI::Base::Path::appDataFolder(); + QString dir = GUI::Path::appDataFolder(); if (!QDir().exists(dir)) QDir().mkpath(dir); diff --git a/GUI/Model/Device/InstrumentLibrary.cpp b/GUI/Model/Device/InstrumentLibrary.cpp index 34baa2966b0eb81181f926b57ca128bde21e4842..e0f6d709ea1a2a602068733f1703d7881f2b71a7 100644 --- a/GUI/Model/Device/InstrumentLibrary.cpp +++ b/GUI/Model/Device/InstrumentLibrary.cpp @@ -27,7 +27,7 @@ const QString XML_INSTRUMENT_COLLECTION_TAG = "InstrumentCollection"; QString instrumentLibraryFilePath() { - return GUI::Base::Path::appDataFolder() + "/BornAgainInstrumentLibrary.balib"; + return GUI::Path::appDataFolder() + "/BornAgainInstrumentLibrary.balib"; } } // namespace diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index 018f80bc9e8d9929167dc511b9f2441357c37852..6d8dce2cbd2bc7d444dab92afbabb14855d8b664 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -226,7 +226,7 @@ QString ProjectDocument::documentVersion() const { QString result(m_currentVersion); if (result.isEmpty()) - result = GUI::Base::Path::getBornAgainVersionString(); + result = GUI::Path::getBornAgainVersionString(); return result; } @@ -243,7 +243,7 @@ void ProjectDocument::writeProject(QIODevice* device) w.setAutoFormatting(true); w.writeStartDocument(); w.writeStartElement(Tag::BornAgain); - QString version_string = GUI::Base::Path::getBornAgainVersionString(); + QString version_string = GUI::Path::getBornAgainVersionString(); w.writeAttribute(XML::Attrib::BA_Version, version_string); XML::writeAttribute(&w, XML::Attrib::version, uint(2)); @@ -300,8 +300,8 @@ ProjectDocument::ReadResult ProjectDocument::readProject(QIODevice* device, Q_UNUSED(version) m_currentVersion = r.attributes().value(XML::Attrib::BA_Version).toString(); - if (!GUI::Base::Path::isVersionMatchMinimal(m_currentVersion, - minimal_supported_version)) { + if (!GUI::Path::isVersionMatchMinimal(m_currentVersion, + minimal_supported_version)) { QString message = QString("Cannot open document version '%1', " "minimal supported version '%2'") .arg(m_currentVersion) diff --git a/GUI/Support/Util/ItemFileNameUtil.cpp b/GUI/Support/Util/ItemFileNameUtil.cpp index 01ca48ca6a8894ed61072d605302a9c4bd97cd9e..b0c4de1926491b2e8f05e7e763148082aa9b17a0 100644 --- a/GUI/Support/Util/ItemFileNameUtil.cpp +++ b/GUI/Support/Util/ItemFileNameUtil.cpp @@ -26,7 +26,7 @@ const QString nativedata_file_prefix = "nativedata"; //! Constructs the name of the file for intensity data. QString intensityDataFileName(const QString& itemName, const QString& prefix) { - QString bodyName = GUI::Base::Path::getValidFileName(itemName); + QString bodyName = GUI::Path::getValidFileName(itemName); return QString("%1_%2.int").arg(prefix).arg(bodyName); } diff --git a/GUI/Support/Util/Path.cpp b/GUI/Support/Util/Path.cpp index 8dbe733747723fa854a6889b9758fe10c0b47376..862c22bf9aae3cae25ea4648cb32e0bf25d79674 100644 --- a/GUI/Support/Util/Path.cpp +++ b/GUI/Support/Util/Path.cpp @@ -42,7 +42,7 @@ const QMap<QString, QString> invalidCharacterMap = initializeCharacterMap(); } // namespace -QString GUI::Base::Path::withTildeHomePath(const QString& path) +QString GUI::Path::withTildeHomePath(const QString& path) { #ifdef Q_OS_WIN return path; @@ -57,7 +57,7 @@ QString GUI::Base::Path::withTildeHomePath(const QString& path) return path; } -QString GUI::Base::Path::getBornAgainVersionString() +QString GUI::Path::getBornAgainVersionString() { return QString::fromStdString(BornAgain::GetVersionNumber()); } @@ -71,7 +71,7 @@ QString GUI::Base::Path::getBornAgainVersionString() //! > greaterthan //! | pipe //! ? questionmark -QString GUI::Base::Path::getValidFileName(const QString& proposed_name) +QString GUI::Path::getValidFileName(const QString& proposed_name) { QString result = proposed_name; for (auto it = invalidCharacterMap.begin(); it != invalidCharacterMap.end(); ++it) @@ -80,7 +80,7 @@ QString GUI::Base::Path::getValidFileName(const QString& proposed_name) } //! parses version string into 2 numbers, returns true in the case of success -bool GUI::Base::Path::parseVersion(const QString& version, int& major_num, int& minor_num) +bool GUI::Path::parseVersion(const QString& version, int& major_num, int& minor_num) { major_num = 0; minor_num = 0; @@ -98,7 +98,7 @@ bool GUI::Base::Path::parseVersion(const QString& version, int& major_num, int& return success; } -int GUI::Base::Path::versionCode(const QString& version) +int GUI::Path::versionCode(const QString& version) { int ba_major; int ba_minor; @@ -109,13 +109,13 @@ int GUI::Base::Path::versionCode(const QString& version) } //! Returns true if current BornAgain version match minimal required version -bool GUI::Base::Path::isVersionMatchMinimal(const QString& version, const QString& minimal_version) +bool GUI::Path::isVersionMatchMinimal(const QString& version, const QString& minimal_version) { return versionCode(version) >= versionCode(minimal_version); } //! Returns file directory from the full file path -QString GUI::Base::Path::fileDir(const QString& fname) +QString GUI::Path::fileDir(const QString& fname) { QFileInfo info(fname); if (info.exists()) @@ -125,18 +125,18 @@ QString GUI::Base::Path::fileDir(const QString& fname) //! Returns base name of file. -QString GUI::Base::Path::baseName(const QString& fname) +QString GUI::Path::baseName(const QString& fname) { QFileInfo info(fname); return info.baseName(); } -QString GUI::Base::Path::appDataFolder() +QString GUI::Path::appDataFolder() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); } -QString GUI::Base::Path::getPathFromIndex(const QModelIndex& index) +QString GUI::Path::getPathFromIndex(const QModelIndex& index) { if (!index.isValid()) return ""; diff --git a/GUI/Support/Util/Path.h b/GUI/Support/Util/Path.h index 42bcf8883ca3744115ee609acbf6bcf1fa84de63..81cc0df646be8e3e0cea04854ff198684ac56c05 100644 --- a/GUI/Support/Util/Path.h +++ b/GUI/Support/Util/Path.h @@ -19,7 +19,7 @@ class QModelIndex; -namespace GUI::Base::Path { +namespace GUI::Path { QString withTildeHomePath(const QString& path); @@ -43,6 +43,6 @@ QString appDataFolder(); QString getPathFromIndex(const QModelIndex& index); -} // namespace GUI::Base::Path +} // namespace GUI::Path #endif // BORNAGAIN_GUI_SUPPORT_UTIL_PATH_H diff --git a/GUI/View/Frame/#Plot2DFrame.cpp# b/GUI/View/Frame/#Plot2DFrame.cpp# new file mode 100644 index 0000000000000000000000000000000000000000..4defb3cbcf534cf8179bc243ed38d93ad1cf68a1 --- /dev/null +++ b/GUI/View/Frame/#Plot2DFrame.cpp# @@ -0,0 +1,65 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/View/Frame/Plot2DFrame.cpp +//! @brief Implements class Plot2DFrame. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#include "GUI/View/Frame/Plot2DFrame.h" +#include "GUI/Model/Data/Data2DItem.h" +#include "GUI/View/Canvas/IntensityDataCanvas.h" +#include "GUI/View/Setup/Scale2DEditor.h" +#include "GUI/View/Tool/ActionFactory.h" +#include <QBoxLayout> +#include <QMenu> + +Plot2DFrame::Plot2DFrame(QWidget* parent) + : DataAccessWidget(parent) + , m_intensityCanvas(new IntensityDataCanvas) + , m_propertyWidget(new Scale2DEditor) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + m_propertyWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + + auto* hlayout = new QHBoxLayout(this); + hlayout->setContentsMargins(0, 0, 0, 0); + hlayout->setSpacing(0); + hlayout->addWidget(m_intensityCanvas); + hlayout->addWidget(m_propertyWidget); + + connect(m_intensityCanvas, &IntensityDataCanvas::customContextMenuRequested, this, + &Plot2DFrame::onContextMenuRequest); + + m_togglePropertiesAction = + ActionFactory::createTogglePropertiesPanelAction(this, m_propertyWidget); + + m_propertyWidget->setVisible(false); +} + +void Plot2DFrame::setDatafileItem(QObject* job_or_real_item) +{ + setBaseItem(job_or_real_item); + m_intensityCanvas->setDatafileItem(job_or_real_item); + m_propertyWidget->setJobOrDatafileItem(job_or_real_item); +} + +QList<QAction*> Plot2DFrame::actionList() +{ + return m_intensityCanvas->actionList() + QList<QAction*>{m_togglePropertiesAction}; +} + +void Plot2DFrame::onContextMenuRequest(const QPoint& point) +{ + QMenu menu; + for (auto* action : actionList()) + menu.addAction(action); + menu.exec(point); +} diff --git a/GUI/View/Main/AboutDialog.cpp b/GUI/View/Main/AboutDialog.cpp index 476e2691cff87aaedd6203745880531568dc3879..7f8b87f0d9a0cc8be10ca6dcf1b633e6dd39ba91 100644 --- a/GUI/View/Main/AboutDialog.cpp +++ b/GUI/View/Main/AboutDialog.cpp @@ -70,7 +70,7 @@ QBoxLayout* createTextLayout() // title auto* aboutTitleLabel = - new QLabel("BornAgain version " + GUI::Base::Path::getBornAgainVersionString()); + new QLabel("BornAgain version " + GUI::Path::getBornAgainVersionString()); aboutTitleLabel->setFont(titleFont); // description diff --git a/GUI/View/Main/ActionManager.cpp b/GUI/View/Main/ActionManager.cpp index bcb1f59662d6ca7f944c651c0494294fb07acdfb..3e5ce8e85ff6243d8bbbe40cb23bae8de3017f6a 100644 --- a/GUI/View/Main/ActionManager.cpp +++ b/GUI/View/Main/ActionManager.cpp @@ -191,7 +191,7 @@ void ActionManager::onAboutToShowFileMenu() int orderNr = 1; for (const QString& file : m_mainWindow->projectManager()->recentProjects()) { hasRecentProjects = true; - QString actionText = GUI::Base::Path::withTildeHomePath(QDir::toNativeSeparators(file)); + QString actionText = GUI::Path::withTildeHomePath(QDir::toNativeSeparators(file)); if (orderNr < 10) actionText = QString("&%1 ").arg(orderNr) + actionText; QAction* action = m_recentProjectsMenu->addAction(actionText); diff --git a/GUI/View/Main/MainWindow.cpp b/GUI/View/Main/MainWindow.cpp index ee0854de6b3bc414be98582c1dfede609f51186c..af66ce8b5593570f08adb32400fa33b2f913801e 100644 --- a/GUI/View/Main/MainWindow.cpp +++ b/GUI/View/Main/MainWindow.cpp @@ -145,8 +145,8 @@ void MainWindow::updateTitle() const auto& doc = gProjectDocument; QString location = "not saved yet"; if (doc.has_value() && doc.value()->hasValidNameAndPath()) - location = GUI::Base::Path::withTildeHomePath( - QDir::toNativeSeparators(doc.value()->projectFullPath())); + location = + GUI::Path::withTildeHomePath(QDir::toNativeSeparators(doc.value()->projectFullPath())); if (!doc.has_value()) setWindowTitle("BornAgain"); else if (doc.value()->isModified()) diff --git a/GUI/View/Manager/ProjectLoadProblemDialog.cpp b/GUI/View/Manager/ProjectLoadProblemDialog.cpp index 41fce0ffa7acba332ab3dc16f3a7b7c4ab2c98e0..c7ef8407856c368b41cd9b298791b550753e0bf3 100644 --- a/GUI/View/Manager/ProjectLoadProblemDialog.cpp +++ b/GUI/View/Manager/ProjectLoadProblemDialog.cpp @@ -119,13 +119,13 @@ QLayout* ProjectLoadProblemDialog::buttonLayout() //! Returns explanations what went wrong. QString ProjectLoadProblemDialog::explanationText() const { - if (m_projectDocumentVersion != GUI::Base::Path::getBornAgainVersionString()) { + if (m_projectDocumentVersion != GUI::Path::getBornAgainVersionString()) { return QString( "Given project was created using BornAgain version %1 " " which is different from version %2 you are currently using. " "At the moment we provide only limited support for import from older versions.") .arg(m_projectDocumentVersion) - .arg(GUI::Base::Path::getBornAgainVersionString()); + .arg(GUI::Path::getBornAgainVersionString()); } return QString("Given project was created using BornAgain version %1 " diff --git a/GUI/View/Manager/PyImportAssistant.cpp b/GUI/View/Manager/PyImportAssistant.cpp index b0584f433cc2e2e8f5eb0ed79a9bfaa7f08249dc..dde220b56817f7c7f0079ff48c7304afb1dd50a6 100644 --- a/GUI/View/Manager/PyImportAssistant.cpp +++ b/GUI/View/Manager/PyImportAssistant.cpp @@ -77,7 +77,7 @@ QString fnameToOpen() : QFileDialog::DontUseNativeDialog); if (!result.isEmpty()) - ProjectManager::instance()->setImportDir(GUI::Base::Path::fileDir(result)); + ProjectManager::instance()->setImportDir(GUI::Path::fileDir(result)); return result; } @@ -182,7 +182,7 @@ std::unique_ptr<MultiLayer> PyImportAssistant::importMultiLayer() throw std::runtime_error("Import did not yield MultiLayer object"); if (sample->sampleName() == "Unnamed") - sample->setSampleName(GUI::Base::Path::baseName(fname).toStdString()); + sample->setSampleName(GUI::Path::baseName(fname).toStdString()); return sample; } catch (const std::exception& ex) { diff --git a/GUI/View/Project/ProjectsView.cpp b/GUI/View/Project/ProjectsView.cpp index 2792059d7bb08cdea28ca88274df6111575739ca..5a5742219db8878c746d549fea1cc67ef4ac82f0 100644 --- a/GUI/View/Project/ProjectsView.cpp +++ b/GUI/View/Project/ProjectsView.cpp @@ -60,8 +60,7 @@ ProjectsView::ProjectsView(QWidget* parent) for (const auto& file : pm->recentProjects()) { auto* button = new QCommandLinkButton; button->setText(QFileInfo(file).baseName()); - button->setDescription( - GUI::Base::Path::withTildeHomePath(QDir::toNativeSeparators(file))); + button->setDescription(GUI::Path::withTildeHomePath(QDir::toNativeSeparators(file))); button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); connect(button, &QCommandLinkButton::clicked, [pm, file] { pm->openProject(file); }); diff --git a/Tests/Unit/GUI/TestHelpers.cpp b/Tests/Unit/GUI/TestHelpers.cpp index 5c497b6a0f5dd702d3dacac8ae5c7f8bce7453a6..8cb267b3791a466e60163d8bce7c0797ed00827b 100644 --- a/Tests/Unit/GUI/TestHelpers.cpp +++ b/Tests/Unit/GUI/TestHelpers.cpp @@ -5,20 +5,20 @@ TEST(TestHelpers, VersionString) { int vmajor(0), vminor(0); - EXPECT_EQ(true, GUI::Base::Path::parseVersion("199.19", vmajor, vminor)); + EXPECT_EQ(true, GUI::Path::parseVersion("199.19", vmajor, vminor)); EXPECT_EQ(199, vmajor); EXPECT_EQ(19, vminor); - EXPECT_FALSE(GUI::Base::Path::parseVersion("1.0.0", vmajor, vminor)); + EXPECT_FALSE(GUI::Path::parseVersion("1.0.0", vmajor, vminor)); QString min_version("20.3"); - EXPECT_TRUE(GUI::Base::Path::isVersionMatchMinimal("20.3", min_version)); - EXPECT_TRUE(GUI::Base::Path::isVersionMatchMinimal("20.4", min_version)); - EXPECT_TRUE(GUI::Base::Path::isVersionMatchMinimal("21.0", min_version)); - EXPECT_TRUE(GUI::Base::Path::isVersionMatchMinimal("123.45", min_version)); + EXPECT_TRUE(GUI::Path::isVersionMatchMinimal("20.3", min_version)); + EXPECT_TRUE(GUI::Path::isVersionMatchMinimal("20.4", min_version)); + EXPECT_TRUE(GUI::Path::isVersionMatchMinimal("21.0", min_version)); + EXPECT_TRUE(GUI::Path::isVersionMatchMinimal("123.45", min_version)); - EXPECT_FALSE(GUI::Base::Path::isVersionMatchMinimal("20.2", min_version)); - EXPECT_FALSE(GUI::Base::Path::isVersionMatchMinimal("19.19", min_version)); - EXPECT_FALSE(GUI::Base::Path::isVersionMatchMinimal("18.0", min_version)); - EXPECT_FALSE(GUI::Base::Path::isVersionMatchMinimal("0.9", min_version)); + EXPECT_FALSE(GUI::Path::isVersionMatchMinimal("20.2", min_version)); + EXPECT_FALSE(GUI::Path::isVersionMatchMinimal("19.19", min_version)); + EXPECT_FALSE(GUI::Path::isVersionMatchMinimal("18.0", min_version)); + EXPECT_FALSE(GUI::Path::isVersionMatchMinimal("0.9", min_version)); }