diff --git a/src/3rdparty/traceability/reviews/reviewswidget.cpp b/src/3rdparty/traceability/reviews/reviewswidget.cpp index d206cbc9158f6ac2443d92e923c9fb9808ace2d2..534c56392855f982704134619687590bfe480222 100644 --- a/src/3rdparty/traceability/reviews/reviewswidget.cpp +++ b/src/3rdparty/traceability/reviews/reviewswidget.cpp @@ -41,6 +41,14 @@ QUrl ReviewsWidget::url() const return ui->credentialWidget->url(); } +/*! + * Sets the url to fetch the requirements from + */ +void ReviewsWidget::setUrl(const QUrl &url) +{ + ui->credentialWidget->setUrl(url.toString()); +} + /*! * Returns the token to authenticate for fetching the reviews */ @@ -49,4 +57,12 @@ QString ReviewsWidget::token() const return ui->credentialWidget->token(); } +/*! + * Sets the Token to authenticate for fetching the requirements + */ +void ReviewsWidget::setToken(const QString &token) +{ + ui->credentialWidget->setToken(token); +} + } // namespace reviews diff --git a/src/3rdparty/traceability/reviews/reviewswidget.h b/src/3rdparty/traceability/reviews/reviewswidget.h index b48a8b38a319b1ed2f41826d0a0bd5ee3eb6515a..9d6c86ce36109bd7706ca0811d3b8d9a08960e4b 100644 --- a/src/3rdparty/traceability/reviews/reviewswidget.h +++ b/src/3rdparty/traceability/reviews/reviewswidget.h @@ -37,7 +37,9 @@ public: ~ReviewsWidget(); QUrl url() const; + void setUrl(const QUrl &url); QString token() const; + void setToken(const QString &token); private: Ui::ReviewsWidget *ui; diff --git a/src/3rdparty/traceability/reviews/reviewswidget.ui b/src/3rdparty/traceability/reviews/reviewswidget.ui index 0a00744b590789363838a3fb483ab2cf8ca031f6..124c0aab05ab0ea99c9184313e55b9e3fe7541af 100644 --- a/src/3rdparty/traceability/reviews/reviewswidget.ui +++ b/src/3rdparty/traceability/reviews/reviewswidget.ui @@ -13,16 +13,96 @@ <property name="windowTitle"> <string>Form</string> </property> - <widget class="tracecommon::CredentialWidget" name="credentialWidget" native="true"> - <property name="geometry"> - <rect> - <x>20</x> - <y>10</y> - <width>371</width> - <height>41</height> - </rect> - </property> - </widget> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="tracecommon::CredentialWidget" name="credentialWidget" native="true"/> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="refreshButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>123</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Refresh</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="serverStatusLabel"> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0"> + <widget class="QTableView" name="allReviews"> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + </widget> + </item> + </layout> </widget> <customwidgets> <customwidget> diff --git a/src/3rdparty/traceability/tracecommon/credentialwidget.ui b/src/3rdparty/traceability/tracecommon/credentialwidget.ui index f625e933c1255312f99bf7c3d9a8e5f10f489dc7..1f164acf787a149a8eed88750cf8096b3d607889 100644 --- a/src/3rdparty/traceability/tracecommon/credentialwidget.ui +++ b/src/3rdparty/traceability/tracecommon/credentialwidget.ui @@ -69,6 +69,11 @@ </item> </layout> </widget> + <tabstops> + <tabstop>urlLineEdit</tabstop> + <tabstop>tokenLineEdit</tabstop> + <tabstop>createTokenButton</tabstop> + </tabstops> <resources/> <connections/> </ui> diff --git a/src/libs/ivcore/templating/xml_templates/interfaceview.tmplt b/src/libs/ivcore/templating/xml_templates/interfaceview.tmplt index d424422caf57625a3809075b8a21230a52e093bf..9aeed4e4521b3e186fc4e3db5c6d69b4a76442a6 100644 --- a/src/libs/ivcore/templating/xml_templates/interfaceview.tmplt +++ b/src/libs/ivcore/templating/xml_templates/interfaceview.tmplt @@ -14,7 +14,7 @@ layer : |_ Instance of layer ArchetypeLibraryReferences : List of all available NON-nested archetypeLibraryReferences (provided by application) archetypeLibraryReference : |_ Instance of archetypeLibraryReference {% endcomment %} -<InterfaceView version="1.3"{% if ProjectName %} projectName="{{ ProjectName }}"{% endif %}{% if Asn1FileName %} asn1file="{{ Asn1FileName }}"{% endif %}{% if MscFileName %} mscfile="{{ MscFileName }}"{% endif %}{% if UiFile %} UiFile="{{ UiFile }}"{% endif %}{% if creatorHash %} creatorHash="{{ creatorHash }}"{% endif %}{% if modifierHash %} modifierHash="{{ modifierHash }}"{% endif %}{% if requirementsURL %} requirementsURL="{{ requirementsURL }}"{% endif %}> +<InterfaceView version="1.3"{% if ProjectName %} projectName="{{ ProjectName }}"{% endif %}{% if Asn1FileName %} asn1file="{{ Asn1FileName }}"{% endif %}{% if MscFileName %} mscfile="{{ MscFileName }}"{% endif %}{% if UiFile %} UiFile="{{ UiFile }}"{% endif %}{% if creatorHash %} creatorHash="{{ creatorHash }}"{% endif %}{% if modifierHash %} modifierHash="{{ modifierHash }}"{% endif %}{% if requirementsURL %} requirementsURL="{{ requirementsURL }}"{% endif %}{% if reviewsURL %} reviewsURL="{{ reviewsURL }}"{% endif %}> {% for func in Functions %} {% include "function.tmplt" %} {% endfor %} diff --git a/src/libs/libiveditor/interfacedocument.cpp b/src/libs/libiveditor/interfacedocument.cpp index 65e3f4061db21ffed5ade302daee547628e2629e..c6a22a29a648fbae2cb8169ff7efaa93ccf0319f 100644 --- a/src/libs/libiveditor/interfacedocument.cpp +++ b/src/libs/libiveditor/interfacedocument.cpp @@ -1171,11 +1171,15 @@ bool InterfaceDocument::loadImpl(const QString &path) setAsn1FileName(metadata["asn1file"].toString()); } setMscFileName(metadata["mscfile"].toString()); - if (metadata.contains(parser.uiFileNameTag())) + if (metadata.contains(parser.uiFileNameTag())) { setUIFileName(metadata[parser.uiFileNameTag()].toString()); + } if (metadata.contains("requirementsURL")) { objectsModel()->setRequirementsURL(metadata["requirementsURL"].toString()); } + if (metadata.contains("reviewsURL")) { + objectsModel()->setReviewsURL(metadata["reviewsURL"].toString()); + } setCreatorGitHash(metadata["creatorHash"].toString()); shared::ErrorHub::clearCurrentFile(); diff --git a/src/libs/libiveditor/ivexporter.cpp b/src/libs/libiveditor/ivexporter.cpp index 9f51085f06a0e9404be7c75a849c80fbb813d441..f5c1f8e6cd719ad377408557248240028be70275 100644 --- a/src/libs/libiveditor/ivexporter.cpp +++ b/src/libs/libiveditor/ivexporter.cpp @@ -145,6 +145,10 @@ QHash<QString, QVariant> IVExporter::collectInterfaceObjects(InterfaceDocument * if (requirementsURL.isValid()) { grouppedObjects[QLatin1String("requirementsURL")] = QVariant::fromValue(requirementsURL.toString()); } + const QUrl &reviewsURL = doc->objectsModel()->reviewsURL(); + if (reviewsURL.isValid()) { + grouppedObjects[QLatin1String("reviewsURL")] = QVariant::fromValue(reviewsURL.toString()); + } const QString creatorGitHash = doc->creatorGitHash(); grouppedObjects[QLatin1String("creatorHash")] = QVariant::fromValue(creatorGitHash); diff --git a/src/libs/libiveditor/properties/ivpropertiesdialog.cpp b/src/libs/libiveditor/properties/ivpropertiesdialog.cpp index 2c27b5274815f1abcc046c38e0ff2e1c4d52562d..3c5c379aab86256cf21a6bc35fb90c9182342925 100644 --- a/src/libs/libiveditor/properties/ivpropertiesdialog.cpp +++ b/src/libs/libiveditor/properties/ivpropertiesdialog.cpp @@ -54,7 +54,6 @@ #include <QHeaderView> #include <QListView> #include <QPlainTextEdit> -#include <QSettings> #include <QTableView> #include <QTimer> #include <QUndoCommand> diff --git a/src/libs/shared/CMakeLists.txt b/src/libs/shared/CMakeLists.txt index a666ab5d8a2f890c4dbfdce3cc401f09ccfc579f..23bce6744f18cef4283199acda2508a4849fdc5a 100644 --- a/src/libs/shared/CMakeLists.txt +++ b/src/libs/shared/CMakeLists.txt @@ -47,6 +47,8 @@ target_sources(${LIB_NAME} PRIVATE commands/cmdentitypropertyrename.h commands/cmdsetrequirementsurl.cpp commands/cmdsetrequirementsurl.h + commands/cmdsetreviewsurl.cpp + commands/cmdsetreviewsurl.h commandsstackbase.cpp commandsstackbase.h common.cpp diff --git a/src/libs/shared/commands/cmdsetreviewsurl.cpp b/src/libs/shared/commands/cmdsetreviewsurl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73d64d94baa73b3e530bb6131d8a73a5832a8745 --- /dev/null +++ b/src/libs/shared/commands/cmdsetreviewsurl.cpp @@ -0,0 +1,64 @@ +/* + Copyright (C) 2023 European Space Agency - <maxime.perrotin@esa.int> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#include "cmdsetreviewsurl.h" + +#include "commandids.h" + +namespace shared { +namespace cmd { + +/*! + * \param model The model to store the URL information in + * \param url The new URL for the reviews (gitlab project) + */ +CmdSetReviewsUrl::CmdSetReviewsUrl(shared::DataModel *model, const QUrl &url, QObject *parent) + : shared::UndoCommand(parent) + , m_model(model) + , m_oldUrl(m_model->reviewsURL()) + , m_newUrl(url) +{ +} + +void CmdSetReviewsUrl::redo() +{ + m_model->setReviewsURL(m_newUrl); +} + +void CmdSetReviewsUrl::undo() +{ + m_model->setReviewsURL(m_oldUrl); +} + +bool CmdSetReviewsUrl::mergeWith(const QUndoCommand *command) +{ + if (id() == command->id()) { + auto other = static_cast<const CmdSetReviewsUrl *>(command); + m_oldUrl = other->m_oldUrl; + return true; + } + + return false; +} + +int CmdSetReviewsUrl::id() const +{ + return Id::SetReviewsUrl; +} + +} // namespace cmd +} // namespace shared diff --git a/src/libs/shared/commands/cmdsetreviewsurl.h b/src/libs/shared/commands/cmdsetreviewsurl.h new file mode 100644 index 0000000000000000000000000000000000000000..f310f167ad8e8001f1258c9598d1a3e02577d90b --- /dev/null +++ b/src/libs/shared/commands/cmdsetreviewsurl.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2023 European Space Agency - <maxime.perrotin@esa.int> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#pragma once + +#include "datamodel.h" +#include "undocommand.h" + +#include <QPointer> +#include <QUrl> + +namespace shared { +namespace cmd { + +/*! + * \brief The CmdSetReviewsUrl class handles setting the URL for the reviews of a model + */ +class CmdSetReviewsUrl : public shared::UndoCommand +{ +public: + CmdSetReviewsUrl(shared::DataModel *model, const QUrl &url, QObject *parent = nullptr); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *command) override; + int id() const override; + +private: + QPointer<shared::DataModel> m_model; + QUrl m_oldUrl; + const QUrl m_newUrl; +}; + +} // namespace cmd +} // namespace shared diff --git a/src/libs/shared/commands/commandids.h b/src/libs/shared/commands/commandids.h index 095386d8667d691bdc25421c6b8ab2ec9fc987e3..f1a782ea1babba317792fb3584897c24599cf71b 100644 --- a/src/libs/shared/commands/commandids.h +++ b/src/libs/shared/commands/commandids.h @@ -30,6 +30,7 @@ enum Id RenameEntityProperty, ChangeEntityAttributes, SetRequirementsUrl, + SetReviewsUrl, LastId }; diff --git a/src/libs/shared/datamodel.cpp b/src/libs/shared/datamodel.cpp index f91773beed50a0645d2d27c0adae76b0956fa36f..51b4391dc204397a67fac24ebbe1a221ee639c4f 100644 --- a/src/libs/shared/datamodel.cpp +++ b/src/libs/shared/datamodel.cpp @@ -45,6 +45,21 @@ const QUrl &DataModel::requirementsURL() const return m_requirementsURL; } +void DataModel::setReviewsURL(const QUrl &url) +{ + if (!url.isValid() || url == m_reviewsURL) { + return; + } + + m_reviewsURL = url; + Q_EMIT reviewsURLChanged(m_reviewsURL); +} + +const QUrl &DataModel::reviewsURL() const +{ + return m_reviewsURL; +} + /*! * Returns the git has for this SpaceCreator build */ diff --git a/src/libs/shared/datamodel.h b/src/libs/shared/datamodel.h index 0426d5f6659fe417463db0ad3d485b9134bcc9a0..7f04df4d08a7c2a96e3f8c7a9a919027322c4ad5 100644 --- a/src/libs/shared/datamodel.h +++ b/src/libs/shared/datamodel.h @@ -28,6 +28,7 @@ class DataModel : public QObject { Q_OBJECT Q_PROPERTY(QUrl requirementsURL READ requirementsURL WRITE setRequirementsURL NOTIFY requirementsURLChanged) + Q_PROPERTY(QUrl reviewsURL READ reviewsURL WRITE setReviewsURL NOTIFY reviewsURLChanged) Q_PROPERTY(QString creatorGitHash READ creatorGitHash WRITE setCreatorGitHash NOTIFY creatorGitHashChanged) public: @@ -38,15 +39,20 @@ public: void setRequirementsURL(const QUrl &url); const QUrl &requirementsURL() const; + void setReviewsURL(const QUrl &url); + const QUrl &reviewsURL() const; + void setCreatorGitHash(const QString &hashStr); QString creatorGitHash() const; Q_SIGNALS: void requirementsURLChanged(const QUrl &); + void reviewsURLChanged(const QUrl &); void creatorGitHashChanged(const QString &); protected: QUrl m_requirementsURL; + QUrl m_reviewsURL; QString m_creatorGitHash; }; diff --git a/src/libs/shared/settingsmanager.cpp b/src/libs/shared/settingsmanager.cpp index 0194ac117604446c0c5eefa0c992051bde92c6a5..75f721edb6af5c3b11032685537e06639020c2c8 100644 --- a/src/libs/shared/settingsmanager.cpp +++ b/src/libs/shared/settingsmanager.cpp @@ -20,6 +20,7 @@ #include "standardpaths.h" #include <QDebug> +#include <QUrl> static QString path() { @@ -45,6 +46,29 @@ SettingsManager *SettingsManager::instance() return instance; } +QString SettingsManager::spaceCreatorGroup() +{ + return "SpaceCreator"; +} + +/*! + * Returns the settings key for storing a token of a host + * \param hostname The hostname the token is belonging to + */ +QString SettingsManager::tokenKey(const QString &hostname) +{ + return QString("%1__token").arg(hostname); +} + +/*! + * Returns the settings key for storing a token of an url + * \param hostname The hostname the token is belonging to + */ +QString SettingsManager::tokenKey(const QUrl &url) +{ + return tokenKey(url.host()); +} + QSettings *SettingsManager::storage() { return m_settings; diff --git a/src/libs/shared/settingsmanager.h b/src/libs/shared/settingsmanager.h index da87e55b87c759b777be05065a7c46ff3784d690..5eaa5107311d68e8534043f7a79f945abb05954a 100644 --- a/src/libs/shared/settingsmanager.h +++ b/src/libs/shared/settingsmanager.h @@ -21,6 +21,8 @@ #include <QObject> #include <QSettings> +class QUrl; + namespace shared { class SettingsManager : public QObject @@ -123,6 +125,10 @@ public: return value.isValid() ? value.value<V>() : defaultValue; } + static QString spaceCreatorGroup(); + static QString tokenKey(const QString &hostname); + static QString tokenKey(const QUrl &url); + Q_SIGNALS: void settingChanged(const QString &key, const QVariant &value); diff --git a/src/libs/shared/ui/spacecreatorrequirements.cpp b/src/libs/shared/ui/spacecreatorrequirements.cpp index 74b98038fb8d3a1c0e7d4ab163e09d6311239392..eac1430c74b3432c7daf4486514cf41f78ec34f9 100644 --- a/src/libs/shared/ui/spacecreatorrequirements.cpp +++ b/src/libs/shared/ui/spacecreatorrequirements.cpp @@ -18,8 +18,11 @@ along with this program. If not, see #include "spacecreatorrequirements.h" +#include "settingsmanager.h" + #include <QSettings> #include <QUrl> + namespace shared { namespace ui { SpaceCreatorRequirements::SpaceCreatorRequirements(const QString &requirementsUrl, @@ -42,9 +45,9 @@ void SpaceCreatorRequirements::onCredentialsChange(const QUrl &newUrl, const QSt return; } - const QString &newUrlHostKey = tokenKey(newUrl.host()); + const QString &newUrlHostKey = SettingsManager::tokenKey(newUrl.host()); QSettings settings; - settings.beginGroup("SpaceCreator"); + settings.beginGroup(SettingsManager::spaceCreatorGroup()); const QString &storedToken = settings.value(newUrlHostKey).toString(); // If anything changed @@ -64,8 +67,8 @@ void SpaceCreatorRequirements::onCredentialsChange(const QUrl &newUrl, const QSt bool SpaceCreatorRequirements::loadSavedCredentials() { QSettings settings; - settings.beginGroup("SpaceCreator"); - const auto &storedToken = settings.value(tokenKey(QUrl(m_requirementsUrl).host())).toString(); + settings.beginGroup(SettingsManager::spaceCreatorGroup()); + const auto &storedToken = settings.value(SettingsManager::tokenKey(QUrl(m_requirementsUrl).host())).toString(); settings.endGroup(); if (m_requirementsUrl.isEmpty() || storedToken.isEmpty()) { diff --git a/src/libs/shared/ui/spacecreatorrequirements.h b/src/libs/shared/ui/spacecreatorrequirements.h index 9a032f71939468f7b5c19cbace7931146752792e..cca9ab3cc18e2ddbe535bf1a424524238c55f905 100644 --- a/src/libs/shared/ui/spacecreatorrequirements.h +++ b/src/libs/shared/ui/spacecreatorrequirements.h @@ -37,7 +37,6 @@ public Q_SLOTS: void onCredentialsChange(const QUrl &url, const QString& newToken); private: - QString tokenKey(const QString &base) const { return QString("%1__token").arg(base); } bool loadSavedCredentials(); }; } diff --git a/src/qtcreator/spacecreatorplugin/CMakeLists.txt b/src/qtcreator/spacecreatorplugin/CMakeLists.txt index ae0a72ee4c11d086d4f84f1b6f2ac08d8f332399..aac12387d3eef025dd505ba7524a613090915e26 100644 --- a/src/qtcreator/spacecreatorplugin/CMakeLists.txt +++ b/src/qtcreator/spacecreatorplugin/CMakeLists.txt @@ -71,6 +71,7 @@ set(SC_PLUGIN_SOURCES refactor/pythonrefactor.h refactor/replacerefactorbase.cpp refactor/replacerefactorbase.h + reviewsdialog.h reviewsdialog.cpp reviewsdialog.ui spacecreatorplugin.cpp spacecreatorplugin.h spacecreatorplugin_global.h @@ -98,7 +99,7 @@ set(SC_QTC_PLUGINS add_qtc_plugin(${PLUGIN_NAME} DEFINES SCPLUGIN_LIBRARY - DEPENDS spacecreatorsystem libmsceditor libiveditor libdveditor ${QT_CORE} ${QT_GUI} ${QT_WIDGETS} ${SC_QTC_LIBRARIES} ${SC_QTC_PLUGINS} + DEPENDS spacecreatorsystem libmsceditor libiveditor libdveditor reviews ${QT_CORE} ${QT_GUI} ${QT_WIDGETS} ${SC_QTC_LIBRARIES} ${SC_QTC_PLUGINS} PLUGIN_DEPENDS ${SC_QTC_PLUGINS} SOURCES ${SC_PLUGIN_SOURCES} ) diff --git a/src/qtcreator/spacecreatorplugin/common/actionhandler.cpp b/src/qtcreator/spacecreatorplugin/common/actionhandler.cpp index 6bac9dc5d0fb025ca58afe4760612d7686be625e..11cba72ed53a791931f2a5ab33808ac96ee72d20 100644 --- a/src/qtcreator/spacecreatorplugin/common/actionhandler.cpp +++ b/src/qtcreator/spacecreatorplugin/common/actionhandler.cpp @@ -20,6 +20,7 @@ #include "editorcore.h" #include "qtceditor.h" #include "spacecreatorpluginconstants.h" +#include "spacecreatorprojectmanager.h" #include <QAction> #include <QUndoGroup> @@ -37,8 +38,9 @@ namespace spctr { /** * @param id the ID of the editor type */ -ActionHandler::ActionHandler(const Utils::Id &id, QObject *parent) +ActionHandler::ActionHandler(const Utils::Id &id, SpaceCreatorProjectManager *projectManager, QObject *parent) : QObject(parent) + , m_projectManager(projectManager) , m_contextId(id) , m_undoGroup(new QUndoGroup(this)) { diff --git a/src/qtcreator/spacecreatorplugin/common/actionhandler.h b/src/qtcreator/spacecreatorplugin/common/actionhandler.h index 77695dc4a47b99bd15d426e058fbbe19db926372..f4d4c28fb0a34c1ac984042403424efeabb3efcb 100644 --- a/src/qtcreator/spacecreatorplugin/common/actionhandler.h +++ b/src/qtcreator/spacecreatorplugin/common/actionhandler.h @@ -18,7 +18,9 @@ #pragma once #include <QObject> +#include <QPointer> #include <id.h> +#include <spacecreatorprojectmanager.h> class QAction; class QUndoGroup; @@ -28,6 +30,7 @@ class IEditor; } namespace spctr { +class SpaceCreatorProjectManager; /** * Class do handle undo/redo and similar actions for the different editors/documents inside QtCreator @@ -36,7 +39,10 @@ class ActionHandler : public QObject { Q_OBJECT public: - explicit ActionHandler(const Utils::Id &id, QObject *parent = nullptr); + explicit ActionHandler(const Utils::Id &id, SpaceCreatorProjectManager *projectManager, QObject *parent = nullptr); + +protected: + QPointer<SpaceCreatorProjectManager> m_projectManager; private Q_SLOTS: void onCurrentEditorChanged(Core::IEditor *editor); @@ -48,5 +54,4 @@ private: QUndoGroup *m_undoGroup = nullptr; QAction *m_deleteAction = nullptr; }; - } diff --git a/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.cpp b/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.cpp index a42ebf0835e116454e40545847603b8b5302964c..21886db84df511ec0c9b099e6b853c8eb9068431 100644 --- a/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.cpp +++ b/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.cpp @@ -31,8 +31,8 @@ namespace spctr { -DVActionHandler::DVActionHandler(QObject *parent) - : ActionHandler(spctr::Constants::K_DV_EDITOR_ID, parent) +DVActionHandler::DVActionHandler(SpaceCreatorProjectManager *projectManager, QObject *parent) + : ActionHandler(spctr::Constants::K_DV_EDITOR_ID, projectManager, parent) { Core::Context contexts; contexts.add(spctr::Constants::K_DV_EDITOR_ID); diff --git a/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.h b/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.h index e0a032425553a1aff67ec1073c67c1667c9cff58..45f9a443e2b14272c8c8b95ff6d15e6b094627d5 100644 --- a/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.h +++ b/src/qtcreator/spacecreatorplugin/dv/dvactionhandler.h @@ -25,7 +25,7 @@ class DVActionHandler : public ActionHandler { Q_OBJECT public: - explicit DVActionHandler(QObject *parent = nullptr); + explicit DVActionHandler(SpaceCreatorProjectManager *projectManager, QObject *parent = nullptr); }; } diff --git a/src/qtcreator/spacecreatorplugin/dv/dveditorfactory.cpp b/src/qtcreator/spacecreatorplugin/dv/dveditorfactory.cpp index 3591d5f3f4c575294a63a55da19d23a99df05994..a56bf30c34bdbadfcdf7d478435cd4038d7a490e 100644 --- a/src/qtcreator/spacecreatorplugin/dv/dveditorfactory.cpp +++ b/src/qtcreator/spacecreatorplugin/dv/dveditorfactory.cpp @@ -29,7 +29,7 @@ namespace spctr { DVEditorFactory::DVEditorFactory(SpaceCreatorProjectManager *projectManager, QObject *parent) : IEditorFactory() - , m_actionHandler(new DVActionHandler(this)) + , m_actionHandler(new DVActionHandler(projectManager, this)) , m_projectManager(projectManager) { setId(spctr::Constants::K_DV_EDITOR_ID); diff --git a/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.cpp b/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.cpp index bc0b37eb6025268d7c6a064791c1226e815b5282..35bf8e544fd6413545961af5b12bf51af37b447d 100644 --- a/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.cpp +++ b/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.cpp @@ -17,8 +17,14 @@ #include "ivactionhandler.h" +#include "commands/cmdsetreviewsurl.h" +#include "commandsstack.h" #include "editorcore.h" +#include "interfacedocument.h" +#include "ivmodel.h" +#include "reviewsdialog.h" #include "spacecreatorpluginconstants.h" +#include "spacecreatorprojectimpl.h" #include <QMenu> #include <coreplugin/actionmanager/actioncontainer.h> @@ -26,13 +32,14 @@ #include <coreplugin/coreconstants.h> #include <coreplugin/icontext.h> #include <coreplugin/icore.h> +#include <projectexplorer/projectmanager.h> #include <utils/icon.h> #include <utils/utilsicons.h> namespace spctr { -IVActionHandler::IVActionHandler(QObject *parent) - : ActionHandler(spctr::Constants::K_IV_EDITOR_ID, parent) +IVActionHandler::IVActionHandler(SpaceCreatorProjectManager *projectManager, QObject *parent) + : ActionHandler(spctr::Constants::K_IV_EDITOR_ID, projectManager, parent) { Core::Context contexts; contexts.add(spctr::Constants::K_IV_EDITOR_ID); @@ -50,6 +57,13 @@ IVActionHandler::IVActionHandler(QObject *parent) auto gridSnapCommand = Core::ActionManager::registerAction(gridSnapAction, Constants::IV_SNAP_TO_GRID_ID, contexts); interfaceViewMenu->addAction(gridSnapCommand); + interfaceViewMenu->addSeparator(); + + auto reviewsAction = new QAction(tr("Show reviews ...")); + connect(reviewsAction, &QAction::triggered, this, &IVActionHandler::showReviewsDialog); + auto reviewsCommand = Core::ActionManager::registerAction(reviewsAction, Constants::IV_SHOW_REVIEWS_ID, contexts); + interfaceViewMenu->addAction(reviewsCommand); + auto toolsMenu = Core::ActionManager::actionContainer(Core::Constants::M_TOOLS); QMenu *menu = interfaceViewMenu->menu(); menu->setTitle(tr("Interface view")); @@ -57,4 +71,23 @@ IVActionHandler::IVActionHandler(QObject *parent) toolsMenu->addMenu(interfaceViewMenu); } +void IVActionHandler::showReviewsDialog() +{ + SpaceCreatorProjectImpl *project = m_projectManager->currentSpaceCreatorProject(); + if (!project || !project->ivCore()) { + return; + } + + ivm::IVModel *model = project->ivCore()->document()->objectsModel(); + const QUrl reviewUrl = model->reviewsURL(); + ReviewsDialog dialog; + dialog.setUrl(reviewUrl); + const int ret = dialog.exec(); + if (ret == QDialog::Accepted) { + ive::cmd::CommandsStack *commandsStack = project->ivCore()->commandsStack(); + if (dialog.url() != model->reviewsURL()) { + commandsStack->push(new shared::cmd::CmdSetReviewsUrl(model, dialog.url())); + } + } +} } diff --git a/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.h b/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.h index 370a406c3d30a2a4f3977910c7a91bc36b1d61bd..f7e775b4cb9b0ab7b8bffad1a0f0455673a69395 100644 --- a/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.h +++ b/src/qtcreator/spacecreatorplugin/iv/ivactionhandler.h @@ -25,7 +25,9 @@ class IVActionHandler : public ActionHandler { Q_OBJECT public: - explicit IVActionHandler(QObject *parent = nullptr); -}; + explicit IVActionHandler(SpaceCreatorProjectManager *projectManager, QObject *parent = nullptr); +protected Q_SLOTS: + void showReviewsDialog(); +}; } diff --git a/src/qtcreator/spacecreatorplugin/iv/iveditorfactory.cpp b/src/qtcreator/spacecreatorplugin/iv/iveditorfactory.cpp index 206853686a9f0a40624016dafbe558b221a0687b..22c6c57b83c740d9d5eabd557ff9c1e750ebf315 100644 --- a/src/qtcreator/spacecreatorplugin/iv/iveditorfactory.cpp +++ b/src/qtcreator/spacecreatorplugin/iv/iveditorfactory.cpp @@ -29,7 +29,7 @@ namespace spctr { IVEditorFactory::IVEditorFactory(SpaceCreatorProjectManager *projectManager, QObject *parent) : IEditorFactory() - , m_actionHandler(new IVActionHandler(this)) + , m_actionHandler(new IVActionHandler(projectManager, this)) , m_projectManager(projectManager) { setId(spctr::Constants::K_IV_EDITOR_ID); diff --git a/src/qtcreator/spacecreatorplugin/msc/msceditorfactory.cpp b/src/qtcreator/spacecreatorplugin/msc/msceditorfactory.cpp index d54ab6ad9c7d4f55d453325cb1ca3e12884700a6..b8649ed9ac6845f479577bc762c31fa54888cf24 100644 --- a/src/qtcreator/spacecreatorplugin/msc/msceditorfactory.cpp +++ b/src/qtcreator/spacecreatorplugin/msc/msceditorfactory.cpp @@ -29,7 +29,7 @@ namespace spctr { MscEditorFactory::MscEditorFactory(SpaceCreatorProjectManager *projectManager, QObject *parent) : IEditorFactory() - , m_actionHandler(new ActionHandler(spctr::Constants::K_MSC_EDITOR_ID, this)) + , m_actionHandler(new ActionHandler(spctr::Constants::K_MSC_EDITOR_ID, projectManager, this)) , m_projectManager(projectManager) { setId(Constants::K_MSC_EDITOR_ID); diff --git a/src/qtcreator/spacecreatorplugin/reviewsdialog.cpp b/src/qtcreator/spacecreatorplugin/reviewsdialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ce941b927daddeff85abc298e8875665139604c --- /dev/null +++ b/src/qtcreator/spacecreatorplugin/reviewsdialog.cpp @@ -0,0 +1,70 @@ +/* + Copyright (C) 2024 European Space Agency - <maxime.perrotin@esa.int> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#include "reviewsdialog.h" + +#include "settingsmanager.h" +#include "ui_reviewsdialog.h" + +#include <QSettings> +#include <QUrl> + +namespace spctr { + +ReviewsDialog::ReviewsDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::ReviewsDialog) +{ + ui->setupUi(this); + connect(this, &QDialog::accepted, this, &ReviewsDialog::saveToken); +} + +ReviewsDialog::~ReviewsDialog() +{ + delete ui; +} + +void ReviewsDialog::setUrl(const QUrl &reviewsUrl) +{ + QSettings settings; + settings.beginGroup(shared::SettingsManager::spaceCreatorGroup()); + ui->reviewsWidget->setUrl(reviewsUrl); + const QString &tokenKey = shared::SettingsManager::tokenKey(reviewsUrl); + const QString token = settings.value(tokenKey, ui->reviewsWidget->token()).toString(); + ui->reviewsWidget->setToken(token); + settings.endGroup(); +} + +QUrl ReviewsDialog::url() const +{ + return ui->reviewsWidget->url(); +} + +/*! + * Saves the authentification token in the settings. + * \note The URL has to be stored outside separately (in the model to save it in the file) + */ +void ReviewsDialog::saveToken() +{ + QSettings settings; + settings.beginGroup(shared::SettingsManager::spaceCreatorGroup()); + const QString &tokenKey = shared::SettingsManager::tokenKey(ui->reviewsWidget->url()); + settings.setValue(tokenKey, ui->reviewsWidget->token()); + settings.endGroup(); +} + +} // namespace spctr diff --git a/src/qtcreator/spacecreatorplugin/reviewsdialog.h b/src/qtcreator/spacecreatorplugin/reviewsdialog.h new file mode 100644 index 0000000000000000000000000000000000000000..d7fa9d06bf25ba4de330e1a8f35e0fd34580d17c --- /dev/null +++ b/src/qtcreator/spacecreatorplugin/reviewsdialog.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2024 European Space Agency - <maxime.perrotin@esa.int> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#pragma once + +#include <QDialog> +#include <QUrl> + +namespace spctr { + +namespace Ui { +class ReviewsDialog; +} + +class ReviewsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ReviewsDialog(QWidget *parent = nullptr); + ~ReviewsDialog(); + + void setUrl(const QUrl &reviewsUrl); + QUrl url() const; + +private Q_SLOTS: + void saveToken(); + +private: + Ui::ReviewsDialog *ui; +}; + +} // namespace spctr diff --git a/src/qtcreator/spacecreatorplugin/reviewsdialog.ui b/src/qtcreator/spacecreatorplugin/reviewsdialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..b78a7d086b404acddbf44847057186deec134734 --- /dev/null +++ b/src/qtcreator/spacecreatorplugin/reviewsdialog.ui @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>spctr::ReviewsDialog</class> + <widget class="QDialog" name="spctr::ReviewsDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="reviews::ReviewsWidget" name="reviewsWidget" native="true"/> + </item> + <item row="1" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>reviews::ReviewsWidget</class> + <extends>QWidget</extends> + <header>reviewswidget.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>spctr::ReviewsDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>spctr::ReviewsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/qtcreator/spacecreatorplugin/spacecreatorpluginconstants.h b/src/qtcreator/spacecreatorplugin/spacecreatorpluginconstants.h index e1e1c358a3c78d6f73b5d73016fec7947325edf7..56ac0f495dae48681cf203e1455fa000ddc29824 100644 --- a/src/qtcreator/spacecreatorplugin/spacecreatorpluginconstants.h +++ b/src/qtcreator/spacecreatorplugin/spacecreatorpluginconstants.h @@ -65,6 +65,7 @@ const char IV_MENU_ID[] = "InterfaceView.Tools.Menu"; const char IV_MANAGE_ARCHETYPES_ID[] = "InterfaceView.ManageArchetypes"; const char IV_SHOW_HELP_LINES_ID[] = "InterfaceView.ShowHelpLines"; const char IV_SNAP_TO_GRID_ID[] = "InterfaceView.SnapToGrid"; +const char IV_SHOW_REVIEWS_ID[] = "InterfaceView.ShowReviews"; const char DV_MENU_ID[] = "DeploymentView.Tools.Menu"; const char DV_SHOW_HELP_LINES_ID[] = "DeploymentView.ShowHelpLines"; const char DV_SNAP_TO_GRID_ID[] = "DeploymentView.SnapToGrid"; diff --git a/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.cpp b/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.cpp index 5d96bf124dcd054fc353017cdcf018aad7e06a6f..029522cfc187153bd7ddb9e59b1dd00ba6a5cfd2 100644 --- a/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.cpp +++ b/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.cpp @@ -19,6 +19,7 @@ #include "spacecreatorprojectimpl.h" +#include <editormanager/editormanager.h> #include <projectexplorer/project.h> #if QTC_VERSION >= 1100 #include <projectexplorer/projectmanager.h> @@ -134,6 +135,38 @@ scs::SpaceCreatorProject *SpaceCreatorProjectManager::orphanStorage() const return m_orphanStorage.get(); } +/*! + * Returns the SpaceCreator project that is used by the given QtCreator project + */ +SpaceCreatorProjectImpl *SpaceCreatorProjectManager::spaceCreatorProject(ProjectExplorer::Project *qtcProject) const +{ + auto found = std::find_if(m_projects.cbegin(), m_projects.cend(), + [qtcProject](auto *pro) { return pro->project() == qtcProject; }); + return found != m_projects.cend() ? *found : nullptr; +} + +/*! + * Returns the spacecreator of the current active editor/document. + */ +SpaceCreatorProjectImpl *SpaceCreatorProjectManager::currentSpaceCreatorProject() const +{ + SpaceCreatorProjectImpl *spaceProject = nullptr; + Core::IDocument *doc = Core::EditorManager::currentDocument(); + if (doc) { + const QString filename = doc->filePath().toFileInfo().absoluteFilePath(); + spaceProject = project(filename); + } + + if (!spaceProject) { + ProjectExplorer::Project *qtcProject = ProjectExplorer::ProjectManager::instance()->startupProject(); + if (qtcProject) { + spaceProject = spaceCreatorProject(qtcProject); + } + } + + return spaceProject; +} + /*! Adds a new SpaceCreatorProject that represents the given QtCreator \p project */ diff --git a/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.h b/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.h index 18304aeea17653c1516c2f14760533bc6bb206b3..d82871f04ff30b02378d8d3f8fd16b75222cf9e6 100644 --- a/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.h +++ b/src/qtcreator/spacecreatorplugin/spacecreatorprojectmanager.h @@ -60,6 +60,9 @@ public: scs::SpaceCreatorProject *orphanStorage() const; + SpaceCreatorProjectImpl *spaceCreatorProject(ProjectExplorer::Project *qtcProject) const; + SpaceCreatorProjectImpl *currentSpaceCreatorProject() const; + private Q_SLOTS: void addProject(ProjectExplorer::Project *project); void removeProject(ProjectExplorer::Project *project);