feat(cpn): Add two more new model actions: template and prompt (#1963)
* Add new model actions to application settings * Add new model prompt action * Tweak wording * Add new model action template * Open individual model yml files * Tidy up after importing template * Add create default and edit to prompt options * Fix edit mode to display the edit dialog after model creation when selected in settings
This commit is contained in:
@@ -80,7 +80,7 @@ void AppPreferencesDialog::accept()
|
||||
g.promptProfile(ui->chkPromptProfile->isChecked());
|
||||
g.simuSW(ui->simuSW->isChecked());
|
||||
g.removeModelSlots(ui->opt_removeBlankSlots->isChecked());
|
||||
g.newModelAction(ui->opt_newMdl_useWizard->isChecked() ? AppData::MODEL_ACT_WIZARD : ui->opt_newMdl_useEditor->isChecked() ? AppData::MODEL_ACT_EDITOR : AppData::MODEL_ACT_NONE);
|
||||
g.newModelAction((AppData::NewModelAction)ui->cboNewModelAction->currentIndex());
|
||||
g.historySize(ui->historySize->value());
|
||||
g.backLight(ui->backLightColor->currentIndex());
|
||||
profile.volumeGain(round(ui->volumeGain->value() * 10.0));
|
||||
@@ -207,9 +207,8 @@ void AppPreferencesDialog::initSettings()
|
||||
|
||||
ui->simuSW->setChecked(g.simuSW());
|
||||
ui->opt_removeBlankSlots->setChecked(g.removeModelSlots());
|
||||
ui->opt_newMdl_useNone->setChecked(g.newModelAction() == AppData::MODEL_ACT_NONE);
|
||||
ui->opt_newMdl_useWizard->setChecked(g.newModelAction() == AppData::MODEL_ACT_WIZARD);
|
||||
ui->opt_newMdl_useEditor->setChecked(g.newModelAction() == AppData::MODEL_ACT_EDITOR);
|
||||
ui->cboNewModelAction->addItems(AppData::newModelActionsList());
|
||||
ui->cboNewModelAction->setCurrentIndex(g.newModelAction());
|
||||
ui->libraryPath->setText(g.libDir());
|
||||
ui->ge_lineedit->setText(g.gePath());
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="profileTab">
|
||||
<attribute name="title">
|
||||
@@ -887,40 +887,6 @@ Mode 4:
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="opt_newMdl_useWizard">
|
||||
<property name="text">
|
||||
<string>Use model wizard</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">btnGrp_newModelActions</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="opt_newMdl_useEditor">
|
||||
<property name="text">
|
||||
<string>Open model editor</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">btnGrp_newModelActions</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="opt_newMdl_useNone">
|
||||
<property name="text">
|
||||
<string>Just create the model</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">btnGrp_newModelActions</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="14" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
@@ -1190,6 +1156,9 @@ Mode 4:
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<widget class="QComboBox" name="cboNewModelAction"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -903,8 +903,16 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
|
||||
setSelectedModel(modelIndex);
|
||||
//qDebug() << modelIndex << categoryIndex << isNewModel;
|
||||
|
||||
if (isNewModel && g.newModelAction() == AppData::MODEL_ACT_WIZARD)
|
||||
openModelWizard(modelIndex);
|
||||
if (isNewModel) {
|
||||
if (g.newModelAction() == AppData::MODEL_ACT_WIZARD)
|
||||
openModelWizard(modelIndex);
|
||||
else if (g.newModelAction() == AppData::MODEL_ACT_TEMPLATE)
|
||||
openModelTemplate(modelIndex);
|
||||
else if (g.newModelAction() == AppData::MODEL_ACT_PROMPT)
|
||||
openModelPrompt(modelIndex);
|
||||
else if (g.newModelAction() == AppData::MODEL_ACT_EDITOR)
|
||||
openModelEditWindow(modelIndex);
|
||||
}
|
||||
else if (g.newModelAction() == AppData::MODEL_ACT_EDITOR)
|
||||
openModelEditWindow(modelIndex);
|
||||
|
||||
@@ -1706,3 +1714,81 @@ void MdiChild::onInternalModuleChanged()
|
||||
|
||||
delete fim;
|
||||
}
|
||||
|
||||
void MdiChild::openModelTemplate(int row)
|
||||
{
|
||||
if (row < 0 && (row = getCurrentModel()) < 0)
|
||||
return;
|
||||
|
||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select a model template file"), QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/TEMPLATES"), YML_FILES_FILTER);
|
||||
|
||||
if (filename.isEmpty())
|
||||
return;
|
||||
|
||||
// validate like read single model
|
||||
// if okay copy into current model slot
|
||||
|
||||
RadioData data;
|
||||
|
||||
Storage storage(filename);
|
||||
if (!storage.load(data)) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, storage.error());
|
||||
return;
|
||||
}
|
||||
|
||||
QString warning = storage.warning();
|
||||
if (!warning.isEmpty()) {
|
||||
QMessageBox::warning(this, CPN_STR_TTL_WARNING, warning);
|
||||
}
|
||||
|
||||
radioData.models[row] = data.models[0];
|
||||
|
||||
// reset module bindings
|
||||
for (int i = 0; i < CPN_MAX_MODULES; i++) {
|
||||
radioData.models[row].moduleData[i].modelId = row + 1;
|
||||
}
|
||||
|
||||
setModified();
|
||||
setSelectedModel(row);
|
||||
|
||||
openModelEditWindow(row);
|
||||
}
|
||||
|
||||
void MdiChild::openModelPrompt(int row)
|
||||
{
|
||||
if (row < 0 && (row = getCurrentModel()) < 0)
|
||||
return;
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle(CPN_STR_APP_NAME);
|
||||
msgBox.setIcon(QMessageBox::Question);
|
||||
msgBox.setText(tr("Add a new model using"));
|
||||
QPushButton *defaultsButton = msgBox.addButton(tr("Defaults"),QMessageBox::ActionRole);
|
||||
QPushButton *editButton = msgBox.addButton(tr("Edit"),QMessageBox::ActionRole);
|
||||
QPushButton *wizardButton = msgBox.addButton(tr("Wizard"),QMessageBox::ActionRole);
|
||||
QPushButton *templateButton = msgBox.addButton(tr("Template"),QMessageBox::ActionRole);
|
||||
QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel);
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
if (msgBox.clickedButton() == cancelButton) {
|
||||
if (!deleteModel(row))
|
||||
QMessageBox::critical(this, CPN_STR_APP_NAME, tr("Failed to remove temporary model!"));
|
||||
return;
|
||||
}
|
||||
else if (msgBox.clickedButton() == defaultsButton) {
|
||||
// nothing to do here
|
||||
return;
|
||||
}
|
||||
else if (msgBox.clickedButton() == editButton) {
|
||||
openModelEditWindow(row);
|
||||
}
|
||||
else if (msgBox.clickedButton() == wizardButton) {
|
||||
openModelWizard(row);
|
||||
}
|
||||
else if (msgBox.clickedButton() == templateButton) {
|
||||
openModelTemplate(row);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,8 @@ class MdiChild : public QWidget
|
||||
|
||||
void openModelWizard(int row = -1);
|
||||
void openModelEditWindow(int row = -1);
|
||||
void openModelTemplate(int row = -1);
|
||||
void openModelPrompt(int row = -1);
|
||||
|
||||
void setDefault();
|
||||
void modelSimulate();
|
||||
|
||||
@@ -451,10 +451,14 @@ class AppData: public CompStoreObj
|
||||
enum NewModelAction {
|
||||
MODEL_ACT_NONE,
|
||||
MODEL_ACT_WIZARD,
|
||||
MODEL_ACT_EDITOR
|
||||
MODEL_ACT_EDITOR,
|
||||
MODEL_ACT_TEMPLATE,
|
||||
MODEL_ACT_PROMPT
|
||||
};
|
||||
Q_ENUM(NewModelAction)
|
||||
|
||||
static QStringList newModelActionsList() { return { tr("None"), tr("Wizard"), tr("Editor"), tr("Template"), tr("Prompt") } ; }
|
||||
|
||||
explicit AppData();
|
||||
void init() override;
|
||||
void initAll();
|
||||
|
||||
Reference in New Issue
Block a user