[Companion] Do not run model wizard on a duplicated/copied model (fixes #4773); Replace existing file extension with .otx when first saving a converted bin/hex/eepe file (fixes #4772); Make sure no other models exist before setting first model as default (fix index 0 always being auto-selected).
This commit is contained in:
+33
-33
@@ -742,24 +742,21 @@ bool MdiChild::deleteCategory(int categoryIndex, QString * error)
|
|||||||
*error = tr("Cannot delete the last category.");
|
*error = tr("Cannot delete the last category.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (countUsedModels(categoryIndex)) {
|
||||||
QVector<int> modelsToMove;
|
if (error)
|
||||||
for (unsigned i=0; i < radioData.models.size(); i++) {
|
*error = tr("This category is not empty!");
|
||||||
ModelData & model = radioData.models[i];
|
return false;
|
||||||
if (model.used && model.category == categoryIndex) {
|
|
||||||
if (error)
|
|
||||||
*error = tr("This category is not empty!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (model.used && model.category > categoryIndex) {
|
|
||||||
modelsToMove.append(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
radioData.categories.erase(radioData.categories.begin() + categoryIndex);
|
radioData.categories.erase(radioData.categories.begin() + categoryIndex);
|
||||||
foreach (const int i, modelsToMove) {
|
|
||||||
--radioData.models[i].category;
|
for (unsigned i=0; i < radioData.models.size(); ++i) {
|
||||||
|
ModelData & model = radioData.models.at(i);
|
||||||
|
if (model.used && model.category > categoryIndex) {
|
||||||
|
--radioData.models[i].category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,14 +862,13 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
|
|||||||
if (modelIndex < 0)
|
if (modelIndex < 0)
|
||||||
modelIndex = modelAppend(ModelData());
|
modelIndex = modelAppend(ModelData());
|
||||||
|
|
||||||
if (modelIndex < 0) {
|
if (modelIndex < 0 || modelIndex >= (int)radioData.models.size()) {
|
||||||
showWarning(tr("Cannot add model, could not find an available model slot."));
|
showWarning(tr("Cannot add model, could not find an available model slot."));
|
||||||
return modelIndex;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (categoryIndex < 0)
|
if (categoryIndex < 0)
|
||||||
categoryIndex = modelsListModel->getCategoryIndex(getCurrentIndex());
|
categoryIndex = modelsListModel->getCategoryIndex(getCurrentIndex());
|
||||||
//qDebug() << modelIndex << categoryIndex;
|
|
||||||
|
|
||||||
bool isNewModel = radioData.models[modelIndex].isEmpty();
|
bool isNewModel = radioData.models[modelIndex].isEmpty();
|
||||||
checkAndInitModel(modelIndex);
|
checkAndInitModel(modelIndex);
|
||||||
@@ -882,13 +878,14 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
|
|||||||
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.
|
||||||
if (modelIndex == 0) {
|
if (countUsedModels() == 1) {
|
||||||
radioData.setCurrentModel(modelIndex);
|
radioData.setCurrentModel(modelIndex);
|
||||||
}
|
}
|
||||||
setModified();
|
setModified();
|
||||||
setSelectedModel(modelIndex);
|
setSelectedModel(modelIndex);
|
||||||
|
//qDebug() << modelIndex << categoryIndex << isNewModel;
|
||||||
|
|
||||||
if (g.newModelAction() == 1)
|
if (isNewModel && g.newModelAction() == 1)
|
||||||
openModelWizard(modelIndex);
|
openModelWizard(modelIndex);
|
||||||
else if (g.newModelAction() == 2)
|
else if (g.newModelAction() == 2)
|
||||||
openModelEditWindow(modelIndex);
|
openModelEditWindow(modelIndex);
|
||||||
@@ -971,6 +968,17 @@ void MdiChild::moveSelectedModelsToCat(const int toCategoryId)
|
|||||||
moveModelsToCategory(getSelectedModels(), toCategoryId);
|
moveModelsToCategory(getSelectedModels(), toCategoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned MdiChild::countUsedModels(const int categoryId)
|
||||||
|
{
|
||||||
|
unsigned count = 0;
|
||||||
|
for (unsigned i=0; i < radioData.models.size(); ++i) {
|
||||||
|
ModelData & model = radioData.models.at(i);
|
||||||
|
if (!model.isEmpty() && (categoryId < 0 || model.category == categoryId))
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, bool insert, bool move)
|
void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, bool insert, bool move)
|
||||||
{
|
{
|
||||||
QVector<ModelData> modelsList;
|
QVector<ModelData> modelsList;
|
||||||
@@ -1343,23 +1351,15 @@ bool MdiChild::save()
|
|||||||
bool MdiChild::saveAs(bool isNew)
|
bool MdiChild::saveAs(bool isNew)
|
||||||
{
|
{
|
||||||
QString fileName;
|
QString fileName;
|
||||||
if (IS_SKY9X(getCurrentBoard())) {
|
curFile.replace(QRegExp("\\.(eepe|bin|hex)$"), ".otx");
|
||||||
curFile.replace(".eepe", ".bin");
|
QFileInfo fi(curFile);
|
||||||
QFileInfo fi(curFile);
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
|
QString filter;
|
||||||
#else
|
#else
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER));
|
QString filter(OTX_FILES_FILTER);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
else {
|
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), filter);
|
||||||
QFileInfo fi(curFile);
|
|
||||||
#ifdef __APPLE__
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
|
|
||||||
#else
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(OTX_FILES_FILTER));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
g.eepromDir( QFileInfo(fileName).dir().absolutePath() );
|
g.eepromDir( QFileInfo(fileName).dir().absolutePath() );
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class MdiChild : public QWidget
|
|||||||
void deleteSelectedModels();
|
void deleteSelectedModels();
|
||||||
void moveModelsToCategory(const QVector<int> models, const int toCategoryId);
|
void moveModelsToCategory(const QVector<int> models, const int toCategoryId);
|
||||||
void moveSelectedModelsToCat(const int toCategoryId);
|
void moveSelectedModelsToCat(const int toCategoryId);
|
||||||
|
unsigned countUsedModels(const int categoryId = -1);
|
||||||
|
|
||||||
void clearCutList();
|
void clearCutList();
|
||||||
void removeModelFromCutList(const int modelIndex);
|
void removeModelFromCutList(const int modelIndex);
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
|
|||||||
return item->data(index.column());
|
return item->data(index.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == Qt::FontRole && item->getModelIndex() == (int)radioData->generalSettings.currModelIndex) {
|
if (role == Qt::FontRole && item->isModel() && item->getModelIndex() == (int)radioData->generalSettings.currModelIndex) {
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
return font;
|
return font;
|
||||||
|
|||||||
Reference in New Issue
Block a user