[Companion] Delete category function added

This commit is contained in:
Bertrand Songis
2017-01-18 16:37:38 +01:00
parent a412992783
commit c707715f3d
2 changed files with 30 additions and 0 deletions
+29
View File
@@ -137,6 +137,7 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
else if (IS_HORUS(firmware->getBoard())) {
if (modelsListModel->getCategoryIndex(modelIndex) >= 0) {
contextMenu.addAction(CompanionIcon("add.png"), tr("&Add model"), this, SLOT(modelAdd()));
contextMenu.addAction(CompanionIcon("delete.png"), tr("&Delete category"), this, SLOT(categoryDelete()));
}
else {
contextMenu.addAction(CompanionIcon("add.png"), tr("&Add category"), this, SLOT(categoryAdd()));
@@ -342,6 +343,34 @@ void MdiChild::categoryAdd()
setModified();
}
void MdiChild::categoryDelete()
{
int categoryIndex = modelsListModel->getCategoryIndex(ui->modelsList->currentIndex());
if (categoryIndex < 0 || categoryIndex >= (int)radioData.categories.size()) {
return;
}
for (unsigned i=0; i<radioData.models.size(); i++) {
ModelData & model = radioData.models[i];
if (model.used && model.category == categoryIndex) {
QMessageBox::warning(this, tr("Companion"),
tr("This category is not empty!"),
QMessageBox::Cancel);
return;
}
}
radioData.categories.erase(radioData.categories.begin() + categoryIndex);
for (unsigned i=0; i<radioData.models.size(); i++) {
ModelData & model = radioData.models[i];
if (model.used && model.category > categoryIndex) {
model.category--;
}
}
setModified();
}
void MdiChild::modelAdd()
{
int categoryIndex = modelsListModel->getCategoryIndex(ui->modelsList->currentIndex());
+1
View File
@@ -73,6 +73,7 @@ class MdiChild : public QWidget
void checkAndInitModel(int row);
void generalEdit();
void categoryAdd();
void categoryDelete();
void modelAdd();
void modelEdit();
void wizardEdit();