From 3f94928cf06d8ce4d46a2b088a12c673fe7c95f1 Mon Sep 17 00:00:00 2001 From: Thomas Kroes Date: Tue, 17 Dec 2024 16:16:31 +0100 Subject: [PATCH] Add download URLs API to page action --- ManiVault/src/PluginFactory.h | 6 ++-- ManiVault/src/private/FileMenu.cpp | 1 - ManiVault/src/private/PageAction.cpp | 1 + ManiVault/src/private/PageAction.h | 6 +++- .../PageActionDelegateEditorWidget.cpp | 28 ++++++++++++++++++- .../private/PageActionDelegateEditorWidget.h | 3 +- ManiVault/src/private/PageActionsModel.cpp | 3 ++ ManiVault/src/private/PageActionsModel.h | 9 +++--- ManiVault/src/private/PageActionsWidget.cpp | 1 + ManiVault/src/private/PageTutorialsWidget.cpp | 1 + 10 files changed, 48 insertions(+), 11 deletions(-) diff --git a/ManiVault/src/PluginFactory.h b/ManiVault/src/PluginFactory.h index dc3c24edb..638917a0c 100644 --- a/ManiVault/src/PluginFactory.h +++ b/ManiVault/src/PluginFactory.h @@ -89,7 +89,7 @@ class CORE_EXPORT PluginFactory : public QObject * Set plugin global settings group action to \p pluginGlobalSettingsGroupAction * @param pluginGlobalSettingsGroupAction Pointer to plugin global settings group action (maybe a nullptr) */ - virtual void setGlobalSettingsGroupAction(gui::PluginGlobalSettingsGroupAction* pluginGlobalSettingsGroupAction) final; + void setGlobalSettingsGroupAction(gui::PluginGlobalSettingsGroupAction* pluginGlobalSettingsGroupAction); public: // Status bar @@ -97,13 +97,13 @@ class CORE_EXPORT PluginFactory : public QObject * Get plugin status bar action * @return Pointer to plugin status bar action (maybe nullptr) */ - virtual gui::PluginStatusBarAction* getStatusBarAction() const final; + gui::PluginStatusBarAction* getStatusBarAction() const; /** * Set plugin status bar action to \p statusBarAction * @param statusBarAction Pointer to plugin status bar action (maybe a nullptr) */ - virtual void setStatusBarAction(gui::PluginStatusBarAction* statusBarAction) final; + void setStatusBarAction(gui::PluginStatusBarAction* statusBarAction); public: // Help diff --git a/ManiVault/src/private/FileMenu.cpp b/ManiVault/src/private/FileMenu.cpp index 9959a1e5b..422eeaa0c 100644 --- a/ManiVault/src/private/FileMenu.cpp +++ b/ManiVault/src/private/FileMenu.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #define TEST_STYLESHEET diff --git a/ManiVault/src/private/PageAction.cpp b/ManiVault/src/private/PageAction.cpp index 84c7b99ec..d7586fddd 100644 --- a/ManiVault/src/private/PageAction.cpp +++ b/ManiVault/src/private/PageAction.cpp @@ -32,6 +32,7 @@ void PageAction::setEditorData(const QModelIndex& index) setSubtitle(index.siblingAtColumn(static_cast(PageActionsModel::Column::Subtitle)).data(Qt::EditRole).toString()); setMetaData(index.siblingAtColumn(static_cast(PageActionsModel::Column::MetaData)).data(Qt::EditRole).toString()); setPreviewImage(index.siblingAtColumn(static_cast(PageActionsModel::Column::PreviewImage)).data(Qt::UserRole + 1).value()); + setDownloadUrls(index.siblingAtColumn(static_cast(PageActionsModel::Column::DownloadUrls)).data(Qt::EditRole).toStringList()); setContributors(index.siblingAtColumn(static_cast(PageActionsModel::Column::Contributors)).data(Qt::UserRole + 1).toStringList()); } diff --git a/ManiVault/src/private/PageAction.h b/ManiVault/src/private/PageAction.h index 4e19f0a5e..832894395 100644 --- a/ManiVault/src/private/PageAction.h +++ b/ManiVault/src/private/PageAction.h @@ -75,6 +75,9 @@ class PageAction final QStringList getContributors() const { return _contributors; } void setContributors(const QStringList& contributors) { _contributors = contributors; } + QStringList getDownloadUrls() const { return _downloadUrls; } + void setDownloadUrls(const QStringList& downloadUrls) { _downloadUrls = downloadUrls; } + ClickedCallback getClickedCallback() const { return _clickedCallback; } void setClickedCallback(const ClickedCallback& clickedCallback) { _clickedCallback = clickedCallback; } @@ -107,10 +110,11 @@ class PageAction final QString _comments; /** Comments are show on the top right */ QStringList _tags; /** Tags (might be empty) */ QString _subtitle; /** Subtitle */ - QString _metaData; /** Meta data (might be empty) */ + QString _metaData; /** Metadata (might be empty) */ QImage _previewImage; /** Preview image (might be empty) */ QString _tooltip; /** Tooltip (might be empty) */ QStringList _contributors; /** List of contributors */ + QStringList _downloadUrls; /** Action download URLs */ ClickedCallback _clickedCallback; /** Callback function that is called when the action row is clicked */ static bool compactView; diff --git a/ManiVault/src/private/PageActionDelegateEditorWidget.cpp b/ManiVault/src/private/PageActionDelegateEditorWidget.cpp index d12027ab9..99bf4b2d1 100644 --- a/ManiVault/src/private/PageActionDelegateEditorWidget.cpp +++ b/ManiVault/src/private/PageActionDelegateEditorWidget.cpp @@ -20,6 +20,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent / _previewIconLabel(Application::getIconFont("FontAwesome").getIcon("image")), _metaDataIconLabel(Application::getIconFont("FontAwesome").getIcon("file-alt")), _tagsIconLabel(Application::getIconFont("FontAwesome").getIcon("tags")), + _downloadUrls(Application::getIconFont("FontAwesome").getIcon("download")), _contributorsIconLabel(Application::getIconFont("FontAwesome").getIcon("user")) { setObjectName("PageActionDelegateEditorWidget"); @@ -60,6 +61,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent / _infoLayout.addWidget(&_previewIconLabel); _infoLayout.addWidget(&_metaDataIconLabel); _infoLayout.addWidget(&_tagsIconLabel); + _infoLayout.addWidget(&_downloadUrls); _infoLayout.addWidget(&_contributorsIconLabel); _infoLayout.addStretch(1); @@ -79,6 +81,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent / _infoLayout.addWidget(&_previewIconLabel); _infoLayout.addWidget(&_metaDataIconLabel); _infoLayout.addWidget(&_tagsIconLabel); + _infoLayout.addWidget(&_downloadUrls); _infoLayout.addWidget(&_contributorsIconLabel); _infoLayout.addStretch(1); @@ -103,7 +106,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent / _previewIconLabel.setTooltipCallback([this, getTooltipHtml]() -> QString { if (!_index.isValid()) - return QString(); + return {}; PageAction pageAction(_index); @@ -163,6 +166,28 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent / return getTooltipHtml(tagsHtml); }); + _downloadUrls.setTooltipCallback([this, getTooltipHtml]() -> QString { + if (!_index.isValid()) + return {}; + + PageAction pageAction(_index); + + const auto downloadUrls = pageAction.getDownloadUrls(); + + QStringList downloads; + + for (const auto& downloadUrl : downloadUrls) + downloads << QString("

%1

").arg(downloadUrl); + + if (downloadUrls.size() == 1) + return getTooltipHtml(QString("

One download from:

%1").arg(downloads.first())); + + if (downloadUrls.size() > 1) + return getTooltipHtml(QString("

%1 downloads from:

%2").arg(QString::number(downloadUrls.size()), downloadUrls.join("
"))); + + return {}; + }); + _contributorsIconLabel.setTooltipCallback([this, getTooltipHtml]() -> QString { if (!_index.isValid()) return {}; @@ -195,6 +220,7 @@ void PageActionDelegateEditorWidget::setEditorData(const QModelIndex& index) _previewIconLabel.setVisible(!pageAction.getPreviewImage().isNull()); _tagsIconLabel.setVisible(!pageAction.getTags().isEmpty()); + _downloadUrls.setVisible(!pageAction.getDownloadUrls().isEmpty()); _contributorsIconLabel.setVisible(!pageAction.getContributors().isEmpty()); } diff --git a/ManiVault/src/private/PageActionDelegateEditorWidget.h b/ManiVault/src/private/PageActionDelegateEditorWidget.h index 2e0df20c1..22dd92558 100644 --- a/ManiVault/src/private/PageActionDelegateEditorWidget.h +++ b/ManiVault/src/private/PageActionDelegateEditorWidget.h @@ -75,7 +75,7 @@ class PageActionDelegateEditorWidget : public QWidget QVBoxLayout _textLayout; /** Right text layout */ QHBoxLayout _primaryTextLayout; /** Primary layout with title and comments labels */ QLabel _titleLabel; /** Title label */ - QLabel _metaDataLabel; /** Label with meta data (may be empty) */ + QLabel _metaDataLabel; /** Label with metadata (maybe empty) */ QHBoxLayout _secondaryTextLayout; /** Secondary layout with subtitle and info labels */ QLabel _subtitleLabel; /** Subtitle label */ QWidget _infoWidget; /** Widget for info labels */ @@ -83,5 +83,6 @@ class PageActionDelegateEditorWidget : public QWidget mv::gui::IconLabel _previewIconLabel; /** Icon label for preview image */ mv::gui::IconLabel _metaDataIconLabel; /** Icon label for meta data */ mv::gui::IconLabel _tagsIconLabel; /** Icon label for tags */ + mv::gui::IconLabel _downloadUrls; /** Icon label for requires download */ mv::gui::IconLabel _contributorsIconLabel; /** Icon label for contributors */ }; diff --git a/ManiVault/src/private/PageActionsModel.cpp b/ManiVault/src/private/PageActionsModel.cpp index c01807827..8be80c98d 100644 --- a/ManiVault/src/private/PageActionsModel.cpp +++ b/ManiVault/src/private/PageActionsModel.cpp @@ -22,6 +22,7 @@ QMap> PageActionsModel::column { Column::MetaData, { "Meta Data", "Meta Data" }}, { Column::PreviewImage, { "Preview", "Preview image" }}, { Column::Tooltip, { "Tooltip", "Tooltip" }}, + { Column::DownloadUrls, { "Download URLs", "Download URLs" }}, { Column::Contributors, { "Contributors", "Contributors" }}, { Column::ClickedCallback, { "Clicked Callback", "Callback which is called when the action is clicked" }}, { Column::SummaryDelegate, { "Summary", "Delegate item with title and subtitle" }} @@ -55,6 +56,7 @@ void PageActionsModel::add(const PageAction& pageAction) new QStandardItem(pageAction.getMetaData()), new QStandardItem(), new QStandardItem(pageAction.getTooltip()), + new QStandardItem(pageAction.getDownloadUrls().join(", ")), new QStandardItem(), new QStandardItem(), new QStandardItem() @@ -64,6 +66,7 @@ void PageActionsModel::add(const PageAction& pageAction) pageActionRow[static_cast(Column::Tags)]->setData(QVariant::fromValue(pageAction.getTags()), Qt::EditRole); pageActionRow[static_cast(Column::PreviewImage)]->setData(QVariant::fromValue(pageAction.getPreviewImage())); pageActionRow[static_cast(Column::Contributors)]->setData(QVariant::fromValue(pageAction.getContributors())); + pageActionRow[static_cast(Column::DownloadUrls)]->setData(QVariant::fromValue(pageAction.getDownloadUrls()), Qt::EditRole); pageActionRow[static_cast(Column::ClickedCallback)]->setData(QVariant::fromValue(pageAction.getClickedCallback())); for (auto item : pageActionRow) diff --git a/ManiVault/src/private/PageActionsModel.h b/ManiVault/src/private/PageActionsModel.h index a8dc4ec0a..9bbb5fcbb 100644 --- a/ManiVault/src/private/PageActionsModel.h +++ b/ManiVault/src/private/PageActionsModel.h @@ -25,14 +25,15 @@ class PageActionsModel final : public QStandardItemModel enum class Column { Icon, /** Icon */ Title, /** Title */ - Description, /** Description (may be empty) */ - Comments, /** Comments (may be empty) */ - Tags, /** Tags (may be empty) */ - Subtitle, /** Sub title */ + Description, /** Description (maybe empty) */ + Comments, /** Comments (maybe empty) */ + Tags, /** Tags (maybe empty) */ + Subtitle, /** Subtitle */ MetaData, /** Meta information */ PreviewImage, /** Action preview image */ Tooltip, /** Action tooltip */ Contributors, /** Action contributors */ + DownloadUrls, /** Download URLs */ ClickedCallback, /** Callback which is called when the action is clicked */ SummaryDelegate /** Delegate item with title and subtitle */ }; diff --git a/ManiVault/src/private/PageActionsWidget.cpp b/ManiVault/src/private/PageActionsWidget.cpp index b920ab280..642b9526b 100644 --- a/ManiVault/src/private/PageActionsWidget.cpp +++ b/ManiVault/src/private/PageActionsWidget.cpp @@ -65,6 +65,7 @@ PageActionsWidget::PageActionsWidget(QWidget* parent, const QString& title, bool treeView.setColumnHidden(static_cast(PageActionsModel::Column::MetaData), true); treeView.setColumnHidden(static_cast(PageActionsModel::Column::PreviewImage), true); treeView.setColumnHidden(static_cast(PageActionsModel::Column::Tooltip), true); + treeView.setColumnHidden(static_cast(PageActionsModel::Column::DownloadUrls), true); treeView.setColumnHidden(static_cast(PageActionsModel::Column::Contributors), true); treeView.setColumnHidden(static_cast(PageActionsModel::Column::ClickedCallback), true); diff --git a/ManiVault/src/private/PageTutorialsWidget.cpp b/ManiVault/src/private/PageTutorialsWidget.cpp index 202339a01..f33712648 100644 --- a/ManiVault/src/private/PageTutorialsWidget.cpp +++ b/ManiVault/src/private/PageTutorialsWidget.cpp @@ -104,6 +104,7 @@ void PageTutorialsWidget::updateActions() tutorialAction.setComments(tutorial->hasProject() ? QString("A tutorial project will be downloaded from: %1.").arg(tutorial->getProject()) : "Creates a project with a tutorial plugin."); tutorialAction.setTags(tutorial->getTags()); + tutorialAction.setDownloadUrls({ tutorial->getProject() }); getModel().add(tutorialAction); }