From 924ecced98c93e4c7cfe1c81fc533ccf8254fa1d Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Tue, 11 Apr 2017 22:53:07 -0400 Subject: [PATCH] [Companion] Fix issue with category edit and dbl-click not working after category name edit; Add translator warnings on default model names; Remove redundant variable and consolidate filename change routines. --- companion/src/mdichild.cpp | 20 ++++++++------------ companion/src/mdichild.h | 3 +-- companion/src/modelslist.cpp | 12 ++++++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 0561e6d42..e9545888a 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -45,7 +45,6 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f): firmware(getCurrentFirmware()), lastSelectedModel(-1), isUntitled(true), - fileChanged(false), showCatToolbar(true), stateDataVersion(1) { @@ -566,6 +565,7 @@ void MdiChild::onItemActivated(const QModelIndex index) openModelEditWindow(mIdx); } else if (modelsListModel->isCategoryType(index)) { + ui->modelsList->setCurrentIndex(index); ui->modelsList->edit(index); } } @@ -591,6 +591,7 @@ void MdiChild::onDataChanged(const QModelIndex & index) } strcpy(radioData.categories[categoryIndex].name, modelsListModel->data(index, 0).toString().left(sizeof(CategoryData::name)-1).toStdString().c_str()); + ui->modelsList->setCurrentIndex(QModelIndex()); // must do this otherwise leaves QTreeView in limbo after TreeModel::refresh() (Qt undoc/bug?) setModified(); } @@ -692,7 +693,6 @@ void MdiChild::updateTitle() void MdiChild::setModified() { - fileChanged = true; refresh(); setWindowModified(true); emit modified(); @@ -875,6 +875,7 @@ int MdiChild::newModel(int modelIndex, int categoryIndex) if (isNewModel && firmware->getCapability(Capability::HasModelCategories) && categoryIndex > -1) { radioData.models[modelIndex].category = categoryIndex; strcpy(radioData.models[modelIndex].filename, radioData.getNextModelFilename().toStdString().c_str()); + /*: Translators: do NOT use accents here, this is a default model name. */ strcpy(radioData.models[modelIndex].name, qPrintable(tr("New model"))); // TODO: Why not just use existing default model name? } // Only set the default model if we just added the first one. @@ -1350,8 +1351,7 @@ bool MdiChild::save() bool MdiChild::saveAs(bool isNew) { - QString fileName; - curFile.replace(QRegExp("\\.(eepe|bin|hex)$"), ".otx"); + forceNewFilename(); QFileInfo fi(curFile); #ifdef __APPLE__ QString filter; @@ -1359,7 +1359,7 @@ bool MdiChild::saveAs(bool isNew) QString filter(OTX_FILES_FILTER); #endif - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), filter); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), filter); if (fileName.isEmpty()) return false; g.eepromDir( QFileInfo(fileName).dir().absolutePath() ); @@ -1387,7 +1387,7 @@ bool MdiChild::saveFile(const QString & filename, bool setCurrent) bool MdiChild::maybeSave() { - if (fileChanged) { + if (isWindowModified()) { int ret = askQuestion(tr("%1 has been modified.\nDo you want to save your changes?").arg(userFriendlyCurrentFile()), QMessageBox::Save, QMessageBox::Discard, QMessageBox::Cancel | QMessageBox::Default); @@ -1413,7 +1413,6 @@ void MdiChild::setCurrentFile(const QString & fileName) { curFile = QFileInfo(fileName).canonicalFilePath(); isUntitled = false; - fileChanged = false; setWindowModified(false); updateTitle(); int MaxRecentFiles = g.historySize(); @@ -1427,18 +1426,15 @@ void MdiChild::setCurrentFile(const QString & fileName) void MdiChild::forceNewFilename(const QString & suffix, const QString & ext) { - QFileInfo info(curFile); - curFile = info.path() + "/" + info.baseName() + suffix + ext; + curFile.replace(QRegExp("\\.(eepe|bin|hex|otx)$"), suffix + "." + ext); } - void MdiChild::convertStorage(Board::Type from, Board::Type to) { showWarning(tr("Models and settings will be automatically converted.\nIf that is not what you intended, please close the file\nand choose the correct radio type/profile before reopening it.")); radioData.convert(from, to); - forceNewFilename("_converted", ".otx"); + forceNewFilename("_converted"); initModelsList(); - fileChanged = true; isUntitled = true; } diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 80c389897..f9f062553 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -178,7 +178,7 @@ class MdiChild : public QWidget bool maybeSave(); void setCurrentFile(const QString & fileName); - void forceNewFilename(const QString & suffix, const QString & ext); + void forceNewFilename(const QString & suffix = "", const QString & ext = "otx"); void convertStorage(Board::Type from, Board::Type to); void showWarning(const QString & msg); int askQuestion(const QString & msg, int button0 = QMessageBox::Yes, int button1 = QMessageBox::No | QMessageBox::Default, int button2 = 0); @@ -199,7 +199,6 @@ class MdiChild : public QWidget int lastSelectedModel; bool isUntitled; - bool fileChanged; bool showCatToolbar; const quint16 stateDataVersion; }; diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index be5957878..32079bc22 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -192,7 +192,7 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const { - Qt::ItemFlags f = QAbstractItemModel::flags(index); + Qt::ItemFlags f = Qt::ItemIsSelectable | Qt::ItemIsEnabled; if (index.isValid()) { if (getItem(index)->isCategory()) @@ -202,6 +202,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const } f |= Qt::ItemIsDropEnabled; + //qDebug() << f; return f; } @@ -691,10 +692,13 @@ void TreeModel::refresh() if (!model.isEmpty() && current) { QString modelName; - if (strlen(model.name) > 0) + if (strlen(model.name) > 0) { modelName = model.name; - else - modelName = QString().sprintf("Model%02d", i+1); + } + else { + /*: Translators: do NOT use accents here, this is a default model name. */ + modelName = tr("Model %1").arg(uint(i+1), 2, 10, QChar('0')); + } current->setData(currentColumn++, modelName); if (hasEepromSizeData) { int size = eepromInterface->getSize(model);