Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Added a new copyClass API.
- Added GUI for new copyClass API in OMEdit.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23234 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 6, 2014
1 parent 25bc12b commit 16ad28b
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1950,7 +1950,7 @@ void MainWindow::createActions()
mpCutAction = new QAction(QIcon(":/Resources/icons/cut.svg"), tr("Cut"), this);
mpCutAction->setShortcut(QKeySequence("Ctrl+x"));
// copy action
mpCopyAction = new QAction(QIcon(":/Resources/icons/copy.svg"), tr("Copy"), this);
mpCopyAction = new QAction(QIcon(":/Resources/icons/copy.svg"), Helper::copy, this);
//! @todo opening this will stop copying data from messages window.
//copyAction->setShortcut(QKeySequence("Ctrl+c"));
// paste action
Expand Down
17 changes: 17 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -568,6 +568,10 @@ void LibraryTreeWidget::createActions()
mpSimulationSetupAction = new QAction(QIcon(":/Resources/icons/simulation-center.svg"), Helper::simulationSetup, this);
mpSimulationSetupAction->setStatusTip(Helper::simulationSetupTip);
connect(mpSimulationSetupAction, SIGNAL(triggered()), SLOT(simulationSetup()));
// copy action
mpCopyClassAction = new QAction(QIcon(":/Resources/icons/duplicate.svg"), Helper::copy, this);
mpCopyClassAction->setStatusTip(tr("Creates a copy of the class"));
connect(mpCopyClassAction, SIGNAL(triggered()), SLOT(copyClass()));
// unload Action
mpUnloadClassAction = new QAction(QIcon(":/Resources/icons/delete.svg"), Helper::unloadClass, this);
mpUnloadClassAction->setStatusTip(Helper::unloadClassTip);
Expand Down Expand Up @@ -1514,6 +1518,7 @@ void LibraryTreeWidget::showContextMenu(QPoint point)
if (!((StringHandler::getFirstWordBeforeDot(pLibraryTreeNode->getNameStructure()).compare("OpenModelica") == 0) || isSearchedTree()))
{
menu.addSeparator();
menu.addAction(mpCopyClassAction);
menu.addAction(mpUnloadClassAction);
/* Only used for development testing. */
/*menu.addAction(mpRefreshAction);*/
Expand Down Expand Up @@ -1632,6 +1637,18 @@ void LibraryTreeWidget::checkAllModels()
mpMainWindow->checkAllModels(pLibraryTreeNode);
}

void LibraryTreeWidget::copyClass()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
if (selectedItemsList.isEmpty())
return;
LibraryTreeNode *pLibraryTreeNode = dynamic_cast<LibraryTreeNode*>(selectedItemsList.at(0));
if (pLibraryTreeNode) {
CopyClassDialog *pCopyClassDialog = new CopyClassDialog(pLibraryTreeNode, mpMainWindow);
pCopyClassDialog->exec();
}
}

void LibraryTreeWidget::unloadClass()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -195,6 +195,7 @@ class LibraryTreeWidget : public QTreeWidget
QAction *mpSimulateWithTransformationalDebuggerAction;
QAction *mpSimulateWithAlgorithmicDebuggerAction;
QAction *mpSimulationSetupAction;
QAction *mpCopyClassAction;
QAction *mpUnloadClassAction;
QAction *mpUnloadTextFileAction;
QAction *mpUnloadXMLFileAction;
Expand Down Expand Up @@ -225,6 +226,7 @@ public slots:
void instantiateModel();
void checkModel();
void checkAllModels();
void copyClass();
void unloadClass();
void unloadTextFile();
void unloadXMLFile();
Expand Down
90 changes: 90 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -769,6 +769,96 @@ void SaveAsClassDialog::showHideSaveContentsInOneFileCheckBox(QString text)
mpSaveContentsInOneFileCheckBox->setVisible(false);
}

/*!
\class CopyClassDialog
\brief Creates a dialog to allow users to copy the Modelica class.
*/

/*!
\param name - name of Modelica class
\param nameStructure - qualified name of Modelica class
\param pParent - pointer to MainWindow
*/
CopyClassDialog::CopyClassDialog(LibraryTreeNode *pLibraryTreeNode, MainWindow *pMainWindow)
: QDialog(pMainWindow, Qt::WindowTitleHint), mpLibraryTreeNode(pLibraryTreeNode), mpMainWindow(pMainWindow)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString(Helper::applicationName).append(" - Copy ").append(mpLibraryTreeNode->getNameStructure()));
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit;
mpPathLabel = new Label(Helper::path);
mpPathTextBox = new QLineEdit;
mpPathBrowseButton = new QPushButton(Helper::browse);
mpPathBrowseButton->setAutoDefault(false);
connect(mpPathBrowseButton, SIGNAL(clicked()), SLOT(browsePath()));
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), SLOT(copyClass()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), SLOT(reject()));
// create buttons box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpNameLabel, 0, 0);
pMainLayout->addWidget(mpNameTextBox, 0, 1, 1, 2);
pMainLayout->addWidget(mpPathLabel, 1, 0);
pMainLayout->addWidget(mpPathTextBox, 1, 1);
pMainLayout->addWidget(mpPathBrowseButton, 1, 2);
pMainLayout->addWidget(mpButtonBox, 2, 0, 1, 3, Qt::AlignRight);
setLayout(pMainLayout);
}

void CopyClassDialog::browsePath()
{
LibraryBrowseDialog *pLibraryBrowseDialog = new LibraryBrowseDialog(tr("Select Path"), mpPathTextBox, mpMainWindow->getLibraryTreeWidget());
pLibraryBrowseDialog->exec();
}

void CopyClassDialog::copyClass()
{
if (mpNameTextBox->text().isEmpty())
{
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg("class"), Helper::ok);
return;
}
/* if path class doesn't exist. */
if (!mpPathTextBox->text().isEmpty())
{
if (!mpMainWindow->getOMCProxy()->existClass(mpPathTextBox->text()))
{
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), GUIMessages::getMessage(
GUIMessages::INSERT_IN_CLASS_NOT_FOUND).arg(mpPathTextBox->text()), Helper::ok);
return;
}
}
// check if new class already exists
QString newClassPath = mpNameTextBox->text() + (mpPathTextBox->text().isEmpty() ? "" : "." + mpPathTextBox->text());
if (mpMainWindow->getOMCProxy()->existClass(newClassPath)) {
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::MODEL_ALREADY_EXISTS).arg("class").arg(mpNameTextBox->text())
.arg((mpPathTextBox->text().isEmpty() ? "Top Level" : mpPathTextBox->text())), Helper::ok);
return;
}
// if everything is fine then copy the class.
if (mpMainWindow->getOMCProxy()->copyClass(mpLibraryTreeNode->getNameStructure(), mpNameTextBox->text(), mpPathTextBox->text())) {
LibraryTreeWidget *pLibraryTreeWidget = mpMainWindow->getLibraryTreeWidget();
LibraryTreeNode *pLibraryTreeNode;
QString className = mpNameTextBox->text().trimmed();
pLibraryTreeNode = pLibraryTreeWidget->addLibraryTreeNode(className, mpMainWindow->getOMCProxy()->getClassRestriction(className),
mpPathTextBox->text().trimmed(), false);
pLibraryTreeNode->setSaveContentsType(mpLibraryTreeNode->getSaveContentsType());
pLibraryTreeWidget->addToExpandedLibraryTreeNodesList(pLibraryTreeNode);
}
accept();
}

/*!
\class RenameClassDialog
\brief Creates a dialog to allow users to rename the Modelica class.
Expand Down
22 changes: 22 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.h
Expand Up @@ -145,6 +145,28 @@ private slots:
void showHideSaveContentsInOneFileCheckBox(QString text);
};

class LibraryTreeNode;
class CopyClassDialog : public QDialog
{
Q_OBJECT
public:
CopyClassDialog(LibraryTreeNode *pLibraryTreeNode, MainWindow *pMainWindow);
private:
LibraryTreeNode *mpLibraryTreeNode;
MainWindow *mpMainWindow;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpPathLabel;
QLineEdit *mpPathTextBox;
QPushButton *mpPathBrowseButton;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
public slots:
void browsePath();
void copyClass();
};

class RenameClassDialog : public QDialog
{
Q_OBJECT
Expand Down
20 changes: 20 additions & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2494,6 +2494,26 @@ bool OMCProxy::exportToFigaro(QString className, QString database, QString mode,
return result;
}

/*!
Copies the class with new name to within path.
\param className - the class that should be copied
\param newClassName - the name for new class
\param withIn - the with in path for new class
*/
bool OMCProxy::copyClass(QString className, QString newClassName, QString withIn)
{
QString expression;
if (withIn.isEmpty()) {
expression = "copyClass(" + className + ",\"" + newClassName + "\")";
} else {
expression = "copyClass(" + className + ",\"" + newClassName + "\"," + withIn + ")";
}
sendCommand(expression);
bool result = StringHandler::unparseBool(getResult());
if (!result) printMessagesStringInternal();
return result;
}

/*!
\class CustomExpressionBox
\brief A text box for executing OMC commands.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -222,6 +222,7 @@ class OMCProxy : public QObject
QStringList getConfigFlagValidOptions(QString topic, QString *mainDescription = 0, QStringList *descriptions = 0);
bool setDebugFlags(QString flags);
bool exportToFigaro(QString className, QString database, QString mode, QString options, QString processor);
bool copyClass(QString className, QString newClassName, QString withIn);
signals:
void commandFinished();
public slots:
Expand Down

0 comments on commit 16ad28b

Please sign in to comment.