1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 17:55:12 +03:00

[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.

This commit is contained in:
Max Paperno 2017-04-11 22:53:07 -04:00
parent 077a651dc3
commit 924ecced98
3 changed files with 17 additions and 18 deletions

View file

@ -45,7 +45,6 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
firmware(getCurrentFirmware()), firmware(getCurrentFirmware()),
lastSelectedModel(-1), lastSelectedModel(-1),
isUntitled(true), isUntitled(true),
fileChanged(false),
showCatToolbar(true), showCatToolbar(true),
stateDataVersion(1) stateDataVersion(1)
{ {
@ -566,6 +565,7 @@ void MdiChild::onItemActivated(const QModelIndex index)
openModelEditWindow(mIdx); openModelEditWindow(mIdx);
} }
else if (modelsListModel->isCategoryType(index)) { else if (modelsListModel->isCategoryType(index)) {
ui->modelsList->setCurrentIndex(index);
ui->modelsList->edit(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()); 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(); setModified();
} }
@ -692,7 +693,6 @@ void MdiChild::updateTitle()
void MdiChild::setModified() void MdiChild::setModified()
{ {
fileChanged = true;
refresh(); refresh();
setWindowModified(true); setWindowModified(true);
emit modified(); emit modified();
@ -875,6 +875,7 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
if (isNewModel && firmware->getCapability(Capability::HasModelCategories) && categoryIndex > -1) { if (isNewModel && firmware->getCapability(Capability::HasModelCategories) && categoryIndex > -1) {
radioData.models[modelIndex].category = categoryIndex; radioData.models[modelIndex].category = categoryIndex;
strcpy(radioData.models[modelIndex].filename, radioData.getNextModelFilename().toStdString().c_str()); 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? 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. // Only set the default model if we just added the first one.
@ -1350,8 +1351,7 @@ bool MdiChild::save()
bool MdiChild::saveAs(bool isNew) bool MdiChild::saveAs(bool isNew)
{ {
QString fileName; forceNewFilename();
curFile.replace(QRegExp("\\.(eepe|bin|hex)$"), ".otx");
QFileInfo fi(curFile); QFileInfo fi(curFile);
#ifdef __APPLE__ #ifdef __APPLE__
QString filter; QString filter;
@ -1359,7 +1359,7 @@ bool MdiChild::saveAs(bool isNew)
QString filter(OTX_FILES_FILTER); QString filter(OTX_FILES_FILTER);
#endif #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()) if (fileName.isEmpty())
return false; return false;
g.eepromDir( QFileInfo(fileName).dir().absolutePath() ); g.eepromDir( QFileInfo(fileName).dir().absolutePath() );
@ -1387,7 +1387,7 @@ bool MdiChild::saveFile(const QString & filename, bool setCurrent)
bool MdiChild::maybeSave() bool MdiChild::maybeSave()
{ {
if (fileChanged) { if (isWindowModified()) {
int ret = askQuestion(tr("%1 has been modified.\nDo you want to save your changes?").arg(userFriendlyCurrentFile()), 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); QMessageBox::Save, QMessageBox::Discard, QMessageBox::Cancel | QMessageBox::Default);
@ -1413,7 +1413,6 @@ void MdiChild::setCurrentFile(const QString & fileName)
{ {
curFile = QFileInfo(fileName).canonicalFilePath(); curFile = QFileInfo(fileName).canonicalFilePath();
isUntitled = false; isUntitled = false;
fileChanged = false;
setWindowModified(false); setWindowModified(false);
updateTitle(); updateTitle();
int MaxRecentFiles = g.historySize(); int MaxRecentFiles = g.historySize();
@ -1427,18 +1426,15 @@ void MdiChild::setCurrentFile(const QString & fileName)
void MdiChild::forceNewFilename(const QString & suffix, const QString & ext) void MdiChild::forceNewFilename(const QString & suffix, const QString & ext)
{ {
QFileInfo info(curFile); curFile.replace(QRegExp("\\.(eepe|bin|hex|otx)$"), suffix + "." + ext);
curFile = info.path() + "/" + info.baseName() + suffix + ext;
} }
void MdiChild::convertStorage(Board::Type from, Board::Type to) 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.")); 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); radioData.convert(from, to);
forceNewFilename("_converted", ".otx"); forceNewFilename("_converted");
initModelsList(); initModelsList();
fileChanged = true;
isUntitled = true; isUntitled = true;
} }

View file

@ -178,7 +178,7 @@ class MdiChild : public QWidget
bool maybeSave(); bool maybeSave();
void setCurrentFile(const QString & fileName); 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 convertStorage(Board::Type from, Board::Type to);
void showWarning(const QString & msg); void showWarning(const QString & msg);
int askQuestion(const QString & msg, int button0 = QMessageBox::Yes, int button1 = QMessageBox::No | QMessageBox::Default, int button2 = 0); 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; int lastSelectedModel;
bool isUntitled; bool isUntitled;
bool fileChanged;
bool showCatToolbar; bool showCatToolbar;
const quint16 stateDataVersion; const quint16 stateDataVersion;
}; };

View file

@ -192,7 +192,7 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) 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 (index.isValid()) {
if (getItem(index)->isCategory()) if (getItem(index)->isCategory())
@ -202,6 +202,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
} }
f |= Qt::ItemIsDropEnabled; f |= Qt::ItemIsDropEnabled;
//qDebug() << f;
return f; return f;
} }
@ -691,10 +692,13 @@ void TreeModel::refresh()
if (!model.isEmpty() && current) { if (!model.isEmpty() && current) {
QString modelName; QString modelName;
if (strlen(model.name) > 0) if (strlen(model.name) > 0) {
modelName = model.name; 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); current->setData(currentColumn++, modelName);
if (hasEepromSizeData) { if (hasEepromSizeData) {
int size = eepromInterface->getSize(model); int size = eepromInterface->getSize(model);