[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)
This commit is contained in:
Max Paperno
2017-03-05 08:47:10 +01:00
committed by Bertrand Songis
parent 2540e166b0
commit c1da4b9b4f
2 changed files with 39 additions and 0 deletions
+37
View File
@@ -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();
+2
View File
@@ -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();