diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 54ca04143..c7694494a 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -871,14 +871,14 @@ void MainWindow::about() void MainWindow::updateMenus() { bool hasMdiChild = (activeMdiChild() != 0); - bool hasSelection = (activeMdiChild() && activeMdiChild()->hasSelection()); + bool hasModelSelected = (activeMdiChild() && activeMdiChild()->hasModelSelected()); newAct->setEnabled(true); openAct->setEnabled(true); saveAct->setEnabled(hasMdiChild); saveAsAct->setEnabled(hasMdiChild); - cutAct->setEnabled(hasSelection); - copyAct->setEnabled(hasSelection); + cutAct->setEnabled(hasModelSelected); + copyAct->setEnabled(hasModelSelected); pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false); writeEepromAct->setEnabled(hasMdiChild); readEepromAct->setEnabled(true); @@ -888,8 +888,8 @@ void MainWindow::updateMenus() recentFileActs[i]->setEnabled(true); } separatorAct->setVisible(hasMdiChild); - simulateAct->setEnabled(hasSelection); - printAct->setEnabled(hasSelection); + simulateAct->setEnabled(hasMdiChild); + printAct->setEnabled(hasModelSelected); loadbackupAct->setEnabled(hasMdiChild); compareAct->setEnabled(activeMdiChild()); updateRecentFileActions(); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index c9f96dc06..12cef6262 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -54,9 +54,11 @@ MdiChild::MdiChild(MainWindow * parent): ui->simulateButton->setIcon(CompanionIcon("simulate.png")); setAttribute(Qt::WA_DeleteOnClose); initModelsList(); - connect(parent, SIGNAL(FirmwareChanged()), this, SLOT(onFirmwareChanged())); - connect(ui->modelsList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openModelEditWindow())); - connect(ui->modelsList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showModelsListContextMenu(const QPoint &))); + connect(parent, &MainWindow::FirmwareChanged, this, &MdiChild::onFirmwareChanged); + connect(ui->modelsList, &QTreeView::doubleClicked, this, &MdiChild::openModelEditWindow); + connect(ui->modelsList, &QTreeView::activated, this, &MdiChild::openModelEditWindow); + connect(ui->modelsList, &QTreeView::pressed, this, &MdiChild::onItemSelected); + connect(ui->modelsList, &QTreeView::customContextMenuRequested, this, &MdiChild::showModelsListContextMenu); // connect(ui->modelsList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(onCurrentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); ui->modelsList->setContextMenuPolicy(Qt::CustomContextMenu); @@ -87,6 +89,26 @@ void MdiChild::refresh(bool expand) updateTitle(); } +void MdiChild::onItemSelected(QModelIndex idx) +{ + emit copyAvailable(isModel(idx) ? true : false); +} + +bool MdiChild::isModel(QModelIndex idx) +{ + return (modelsListModel->getModelIndex(idx) >= 0 ? true : false); +} + +bool MdiChild::isCategory(QModelIndex idx) +{ + if (isModel(idx)) { + return false; + } + else { + return (modelsListModel->getCategoryIndex(idx) >= 0); + } +} + void MdiChild::confirmDelete() { if (QMessageBox::warning(this, "Companion", tr("Delete selected models?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { @@ -188,7 +210,7 @@ void MdiChild::initModelsList() delete modelsListModel; modelsListModel = new TreeModel(&radioData, this); - connect(modelsListModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(onDataChanged(const QModelIndex &))); + connect(modelsListModel, &QAbstractItemModel::dataChanged, this, &MdiChild::onDataChanged); ui->modelsList->setModel(modelsListModel); ui->modelsList->header()->setVisible(!IS_HORUS(board)); if (IS_HORUS(board)) { @@ -320,9 +342,9 @@ bool MdiChild::hasPasteData() const return mimeData->hasFormat("application/x-companion"); } -bool MdiChild::hasSelection() const +bool MdiChild::hasModelSelected() { - return ui->modelsList->selectionModel()->hasSelection(); + return isModel(ui->modelsList->currentIndex()); } void MdiChild::updateTitle() @@ -381,7 +403,7 @@ void MdiChild::checkAndInitModel(int row) void MdiChild::generalEdit() { GeneralEdit * t = new GeneralEdit(this, radioData, firmware); - connect(t, SIGNAL(modified()), this, SLOT(setModified())); + connect(t, &GeneralEdit::modified, this, &MdiChild::setModified); t->show(); } @@ -390,6 +412,7 @@ void MdiChild::categoryAdd() CategoryData category("New category"); radioData.categories.push_back(category); setModified(); + emit copyAvailable(false); // workaround : nothing is selected after model creation } void MdiChild::categoryRename() @@ -468,6 +491,7 @@ void MdiChild::modelAdd() radioData.setCurrentModel(newModelIndex); } setModified(); + emit copyAvailable(false); // workaround : nothing is selected after model creation } void MdiChild::modelEdit() @@ -481,7 +505,7 @@ void MdiChild::modelEdit() ModelEdit * t = new ModelEdit(this, radioData, (row), firmware); gStopwatch.report("ModelEdit created"); t->setWindowTitle(tr("Editing model %1: ").arg(row+1) + model.name); - connect(t, SIGNAL(modified()), this, SLOT(setModified())); + connect(t, &ModelEdit::modified, this, &MdiChild::setModified); gStopwatch.report("STARTING MODEL EDIT"); t->show(); QApplication::restoreOverrideCursor(); @@ -741,11 +765,6 @@ void MdiChild::print(int model, const QString & filename) } } -void MdiChild::viableModelSelected(bool viable) -{ - emit copyAvailable(viable); -} - int MdiChild::getCurrentModel() const { return modelsListModel->getModelIndex(ui->modelsList->currentIndex()); diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 511c086ec..e83fc2683 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -46,11 +46,10 @@ class MdiChild : public QWidget bool save(); bool saveAs(bool isNew=false); bool saveFile(const QString & fileName, bool setCurrent=true); - bool hasSelection() const; + bool hasModelSelected(); bool hasPasteData() const; QString userFriendlyCurrentFile() const; QString currentFile() const { return curFile; } - void viableModelSelected(bool viable); int getCurrentModel() const; int getCurrentCategory() const; void refresh(bool expand=false); @@ -97,6 +96,9 @@ class MdiChild : public QWidget void print(int model=-1, const QString & filename=""); void setModified(); void updateTitle(); + void onItemSelected(QModelIndex); + bool isModel(QModelIndex); + bool isCategory(QModelIndex); private: bool maybeSave();