From c1da4b9b4f12ece6206931d2818b5da8cb02c33a Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sun, 5 Mar 2017 02:47:10 -0500 Subject: [PATCH] [Companion][MdiChild] Add model context-menu actions for moving a model between categories (only if > 1 category exists). (#4555) (ref. #4224 : Horus models cannot be moved from one category to another) --- companion/src/mdichild.cpp | 37 +++++++++++++++++++++++++++++++++++++ companion/src/mdichild.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 634e506b3..dd681bbf1 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -144,6 +144,19 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos) contextMenu.addAction(CompanionIcon("cut.png"), tr("&Cut"), this, SLOT(cut()), tr("Ctrl+X")); contextMenu.addAction(CompanionIcon("paste.png"), tr("&Paste"), this, SLOT(paste()), tr("Ctrl+V"))->setEnabled(hasData); contextMenu.addAction(CompanionIcon("duplicate.png"), tr("D&uplicate"), this, SLOT(modelDuplicate()), tr("Ctrl+U")); + if (radioData.categories.size() > 1) { + QMenu * catsMenu = contextMenu.addMenu(CompanionIcon("arrow-right.png"), tr("Move to Category")); + for (unsigned i=0; i < radioData.categories.size(); ++i) { + QAction * act = catsMenu->addAction(QString(radioData.categories[i].name), this, SLOT(onModelMoveToCategory())); + act->setProperty("categoryId", i); + if ((int)i < modelsListModel->getCategoryIndex(modelIndex)) + act->setIcon(CompanionIcon("moveup.png")); + else if ((int)i > modelsListModel->getCategoryIndex(modelIndex)) + act->setIcon(CompanionIcon("movedown.png")); + else + act->setEnabled(false); + } + } contextMenu.addSeparator(); contextMenu.addAction(CompanionIcon("currentmodel.png"), tr("&Use as default"), this, SLOT(setDefault())); contextMenu.addSeparator(); @@ -518,6 +531,30 @@ void MdiChild::modelDuplicate() setModified(); } +void MdiChild::modelChangeCategory(int toCategoryId) +{ + int row = getCurrentModel(); + if (row < 0 || row >= (int)radioData.models.size() || toCategoryId < 0) { + return; + } + if (radioData.models[row].category != toCategoryId) { + radioData.models[row].category = toCategoryId; + setModified(); + } +} + +void MdiChild::onModelMoveToCategory() +{ + if (!sender()) { + return; + } + bool ok = false; + int toCatId = sender()->property("categoryId").toInt(&ok); + if (ok && toCatId >= 0) { + modelChangeCategory(toCatId); + } +} + void MdiChild::setDefault() { int row = getCurrentModel(); diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index e83fc2683..7ab23c6a2 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -66,6 +66,7 @@ class MdiChild : public QWidget protected slots: void documentWasModified(); void on_simulateButton_clicked(); + void onModelMoveToCategory(); void on_radioSettings_clicked(); void setDefault(); void onFirmwareChanged(); @@ -80,6 +81,7 @@ class MdiChild : public QWidget void modelAdd(); void modelEdit(); void modelDuplicate(); + void modelChangeCategory(int toCategoryId); void wizardEdit(); void openModelEditWindow(); bool loadBackup();