Skip to content

Commit

Permalink
Created a separate dialog for saveTotalModel api options (#8110)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 11, 2021
1 parent 68aabef commit 14d01f4
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 26 deletions.
24 changes: 6 additions & 18 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -4690,14 +4690,13 @@ void LibraryWidget::saveAsLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
* \param pLibraryTreeItem
* \return
*/
bool LibraryWidget::saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
void LibraryWidget::saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
{
MainWindow::instance()->getStatusBar()->showMessage(tr("Saving %1").arg(pLibraryTreeItem->getNameStructure()));
MainWindow::instance()->showProgressBar();
bool result = saveTotalLibraryTreeItemHelper(pLibraryTreeItem);
saveTotalLibraryTreeItemHelper(pLibraryTreeItem);
MainWindow::instance()->getStatusBar()->clearMessage();
MainWindow::instance()->hideProgressBar();
return result;
}

/*!
Expand Down Expand Up @@ -5211,24 +5210,13 @@ bool LibraryWidget::saveCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryT
* \param pLibraryTreeItem
* \return
*/
bool LibraryWidget::saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
void LibraryWidget::saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
{
bool result = false;
/* if user has done some changes in the Modelica text view then save & validate it in the AST before saving it to file. */
if (pLibraryTreeItem->getModelWidget() && !pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return false;
if (pLibraryTreeItem->getModelWidget() && pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
SaveTotalFileDialog *pSaveTotalFileDialog = new SaveTotalFileDialog(pLibraryTreeItem);
pSaveTotalFileDialog->exec();
}
QString fileName;
QString name = QString("%1Total").arg(pLibraryTreeItem->getName());
fileName = StringHandler::getSaveFileName(this, tr("%1 - Save %2 %3 as Total File").arg(Helper::applicationName)
.arg(pLibraryTreeItem->mClassInformation.restriction).arg(pLibraryTreeItem->getName()), NULL,
Helper::omFileTypes, NULL, "mo", &name);
if (fileName.isEmpty()) { // if user press ESC
return false;
}
// save the model through OMC
result = MainWindow::instance()->getOMCProxy()->saveTotalModel(fileName, pLibraryTreeItem->getNameStructure());
return result;
}

/*!
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h
Expand Up @@ -491,7 +491,7 @@ class LibraryWidget : public QWidget
bool saveFile(QString fileName, QString contents);
bool saveLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
void saveAsLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
bool saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
void saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
void openLibraryTreeItem(QString nameStructure);
private:
TreeSearchFilters *mpTreeSearchFilters;
Expand All @@ -512,7 +512,7 @@ class LibraryWidget : public QWidget
bool saveAsCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
bool saveAsOMSLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
bool saveCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem, QString fileName);
bool saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem);
void saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem);
public slots:
void scrollToActiveLibraryTreeItem();
void searchClasses();
Expand Down
58 changes: 58 additions & 0 deletions OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -1253,6 +1253,64 @@ void RenameClassDialog::renameClass()
}
}

/*!
* \class SaveTotalFileDialog
* \brief Creates a dialog that shows the options for saveTotalModel.
*/
/*!
* \brief SaveTotalFileDialog::SaveTotalFileDialog
* \param pLibraryTreeItem
* \param pParent
*/
SaveTotalFileDialog::SaveTotalFileDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *pParent)
: QDialog(pParent)
{
mpLibraryTreeItem = pLibraryTreeItem;
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString("%1 - Save %2 %3 as Total File").arg(Helper::applicationName, mpLibraryTreeItem->mClassInformation.restriction, mpLibraryTreeItem->getName()));
setMinimumWidth(400);
// checkboxes
mpObfuscateOutputCheckBox = new QCheckBox(tr("Obfuscate output"));
mpStripAnnotationsCheckBox = new QCheckBox(tr("Strip annotations"));
mpStripCommentsCheckBox = new QCheckBox(tr("Strip comments"));
// buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(saveTotalModel()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
QGridLayout *pMainGridLayout = new QGridLayout;
pMainGridLayout->addWidget(mpObfuscateOutputCheckBox, 0, 0);
pMainGridLayout->addWidget(mpStripAnnotationsCheckBox, 1, 0);
pMainGridLayout->addWidget(mpStripCommentsCheckBox, 2, 0);
pMainGridLayout->addWidget(mpButtonBox, 3, 0, 1, 1, Qt::AlignRight);
setLayout(pMainGridLayout);
}

/*!
* \brief SaveTotalFileDialog::saveTotalModel
* Saves the model as total file.
*/
void SaveTotalFileDialog::saveTotalModel()
{
QString fileName;
QString name = QString("%1Total").arg(mpLibraryTreeItem->getName());
fileName = StringHandler::getSaveFileName(this, tr("%1 - Save %2 %3 as Total File").arg(Helper::applicationName, mpLibraryTreeItem->mClassInformation.restriction,
mpLibraryTreeItem->getName()), NULL, Helper::omFileTypes, NULL, "mo", &name);
if (fileName.isEmpty()) { // if user press ESC
reject();
} else {
// save the model through OMC
MainWindow::instance()->getOMCProxy()->saveTotalModel(fileName, mpLibraryTreeItem->getNameStructure(), mpStripAnnotationsCheckBox->isChecked(),
mpStripCommentsCheckBox->isChecked(), mpObfuscateOutputCheckBox->isChecked());
accept();
}
}

/*!
* \class InformationDialog
* \brief Creates a dialog that shows the users the result of OMCProxy::instantiateModel and OMCProxy::checkModel.
Expand Down
17 changes: 17 additions & 0 deletions OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h
Expand Up @@ -206,6 +206,23 @@ public slots:
void renameClass();
};

class SaveTotalFileDialog : public QDialog
{
Q_OBJECT
public:
SaveTotalFileDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *pParent = 0);
private:
LibraryTreeItem *mpLibraryTreeItem;
QCheckBox *mpObfuscateOutputCheckBox;
QCheckBox *mpStripAnnotationsCheckBox;
QCheckBox *mpStripCommentsCheckBox;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void saveTotalModel();
};

class InformationDialog : public QWidget
{
public:
Expand Down
11 changes: 6 additions & 5 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -1838,14 +1838,15 @@ bool OMCProxy::saveModifiedModel(QString modelText)
* Save class with all used classes to a file.
* \param fileName - the file to save in.
* \param className - the name of the class.
* \param stripAnnotations
* \param stripComments
* \param obfuscate
* \return true on success.
*/
bool OMCProxy::saveTotalModel(QString fileName, QString className)
bool OMCProxy::saveTotalModel(QString fileName, QString className, bool stripAnnotations, bool stripComments, bool obfuscate)
{
bool result = mpOMCInterface->saveTotalModel(fileName, className, false, false, false);
if (!result) {
printMessagesStringInternal();
}
bool result = mpOMCInterface->saveTotalModel(fileName, className, stripAnnotations, stripComments, obfuscate);
printMessagesStringInternal();
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -171,7 +171,7 @@ class OMCProxy : public QObject
bool setSourceFile(QString className, QString path);
bool save(QString className);
bool saveModifiedModel(QString modelText);
bool saveTotalModel(QString fileName, QString className);
bool saveTotalModel(QString fileName, QString className, bool stripAnnotations, bool stripComments, bool obfuscate);
QString list(QString className);
QString listFile(QString className, bool nestedClasses = true);
QString diffModelicaFileListings(const QString &before, const QString &after);
Expand Down

0 comments on commit 14d01f4

Please sign in to comment.