Menu updates handling cat/models for Horus (#4452)

* Alt+S is properly set

* Copy menu fixed

* Cosmetics

* Better handling of model and categories signaling

* Cosmetics

* Cosmetics and handling of special case after model or cat creation

* Remove unused viableModelSelected

* Take 2

* Start work on connect to new standards
This commit is contained in:
3djc
2017-02-15 16:28:39 +01:00
committed by Bertrand Songis
parent 7762bac360
commit b5798e219d
3 changed files with 41 additions and 20 deletions
+5 -5
View File
@@ -871,14 +871,14 @@ void MainWindow::about()
void MainWindow::updateMenus() void MainWindow::updateMenus()
{ {
bool hasMdiChild = (activeMdiChild() != 0); bool hasMdiChild = (activeMdiChild() != 0);
bool hasSelection = (activeMdiChild() && activeMdiChild()->hasSelection()); bool hasModelSelected = (activeMdiChild() && activeMdiChild()->hasModelSelected());
newAct->setEnabled(true); newAct->setEnabled(true);
openAct->setEnabled(true); openAct->setEnabled(true);
saveAct->setEnabled(hasMdiChild); saveAct->setEnabled(hasMdiChild);
saveAsAct->setEnabled(hasMdiChild); saveAsAct->setEnabled(hasMdiChild);
cutAct->setEnabled(hasSelection); cutAct->setEnabled(hasModelSelected);
copyAct->setEnabled(hasSelection); copyAct->setEnabled(hasModelSelected);
pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false); pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false);
writeEepromAct->setEnabled(hasMdiChild); writeEepromAct->setEnabled(hasMdiChild);
readEepromAct->setEnabled(true); readEepromAct->setEnabled(true);
@@ -888,8 +888,8 @@ void MainWindow::updateMenus()
recentFileActs[i]->setEnabled(true); recentFileActs[i]->setEnabled(true);
} }
separatorAct->setVisible(hasMdiChild); separatorAct->setVisible(hasMdiChild);
simulateAct->setEnabled(hasSelection); simulateAct->setEnabled(hasMdiChild);
printAct->setEnabled(hasSelection); printAct->setEnabled(hasModelSelected);
loadbackupAct->setEnabled(hasMdiChild); loadbackupAct->setEnabled(hasMdiChild);
compareAct->setEnabled(activeMdiChild()); compareAct->setEnabled(activeMdiChild());
updateRecentFileActions(); updateRecentFileActions();
+32 -13
View File
@@ -54,9 +54,11 @@ MdiChild::MdiChild(MainWindow * parent):
ui->simulateButton->setIcon(CompanionIcon("simulate.png")); ui->simulateButton->setIcon(CompanionIcon("simulate.png"));
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
initModelsList(); initModelsList();
connect(parent, SIGNAL(FirmwareChanged()), this, SLOT(onFirmwareChanged())); connect(parent, &MainWindow::FirmwareChanged, this, &MdiChild::onFirmwareChanged);
connect(ui->modelsList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openModelEditWindow())); connect(ui->modelsList, &QTreeView::doubleClicked, this, &MdiChild::openModelEditWindow);
connect(ui->modelsList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showModelsListContextMenu(const QPoint &))); 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 *))); // connect(ui->modelsList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(onCurrentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
ui->modelsList->setContextMenuPolicy(Qt::CustomContextMenu); ui->modelsList->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -87,6 +89,26 @@ void MdiChild::refresh(bool expand)
updateTitle(); 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() void MdiChild::confirmDelete()
{ {
if (QMessageBox::warning(this, "Companion", tr("Delete selected models?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { if (QMessageBox::warning(this, "Companion", tr("Delete selected models?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
@@ -188,7 +210,7 @@ void MdiChild::initModelsList()
delete modelsListModel; delete modelsListModel;
modelsListModel = new TreeModel(&radioData, this); 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->setModel(modelsListModel);
ui->modelsList->header()->setVisible(!IS_HORUS(board)); ui->modelsList->header()->setVisible(!IS_HORUS(board));
if (IS_HORUS(board)) { if (IS_HORUS(board)) {
@@ -320,9 +342,9 @@ bool MdiChild::hasPasteData() const
return mimeData->hasFormat("application/x-companion"); 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() void MdiChild::updateTitle()
@@ -381,7 +403,7 @@ void MdiChild::checkAndInitModel(int row)
void MdiChild::generalEdit() void MdiChild::generalEdit()
{ {
GeneralEdit * t = new GeneralEdit(this, radioData, firmware); GeneralEdit * t = new GeneralEdit(this, radioData, firmware);
connect(t, SIGNAL(modified()), this, SLOT(setModified())); connect(t, &GeneralEdit::modified, this, &MdiChild::setModified);
t->show(); t->show();
} }
@@ -390,6 +412,7 @@ void MdiChild::categoryAdd()
CategoryData category("New category"); CategoryData category("New category");
radioData.categories.push_back(category); radioData.categories.push_back(category);
setModified(); setModified();
emit copyAvailable(false); // workaround : nothing is selected after model creation
} }
void MdiChild::categoryRename() void MdiChild::categoryRename()
@@ -468,6 +491,7 @@ void MdiChild::modelAdd()
radioData.setCurrentModel(newModelIndex); radioData.setCurrentModel(newModelIndex);
} }
setModified(); setModified();
emit copyAvailable(false); // workaround : nothing is selected after model creation
} }
void MdiChild::modelEdit() void MdiChild::modelEdit()
@@ -481,7 +505,7 @@ void MdiChild::modelEdit()
ModelEdit * t = new ModelEdit(this, radioData, (row), firmware); ModelEdit * t = new ModelEdit(this, radioData, (row), firmware);
gStopwatch.report("ModelEdit created"); gStopwatch.report("ModelEdit created");
t->setWindowTitle(tr("Editing model %1: ").arg(row+1) + model.name); 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"); gStopwatch.report("STARTING MODEL EDIT");
t->show(); t->show();
QApplication::restoreOverrideCursor(); 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 int MdiChild::getCurrentModel() const
{ {
return modelsListModel->getModelIndex(ui->modelsList->currentIndex()); return modelsListModel->getModelIndex(ui->modelsList->currentIndex());
+4 -2
View File
@@ -46,11 +46,10 @@ class MdiChild : public QWidget
bool save(); bool save();
bool saveAs(bool isNew=false); bool saveAs(bool isNew=false);
bool saveFile(const QString & fileName, bool setCurrent=true); bool saveFile(const QString & fileName, bool setCurrent=true);
bool hasSelection() const; bool hasModelSelected();
bool hasPasteData() const; bool hasPasteData() const;
QString userFriendlyCurrentFile() const; QString userFriendlyCurrentFile() const;
QString currentFile() const { return curFile; } QString currentFile() const { return curFile; }
void viableModelSelected(bool viable);
int getCurrentModel() const; int getCurrentModel() const;
int getCurrentCategory() const; int getCurrentCategory() const;
void refresh(bool expand=false); void refresh(bool expand=false);
@@ -97,6 +96,9 @@ class MdiChild : public QWidget
void print(int model=-1, const QString & filename=""); void print(int model=-1, const QString & filename="");
void setModified(); void setModified();
void updateTitle(); void updateTitle();
void onItemSelected(QModelIndex);
bool isModel(QModelIndex);
bool isCategory(QModelIndex);
private: private:
bool maybeSave(); bool maybeSave();