Skip to content

Commit

Permalink
Implement detailed function arguments dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
atrosinenko authored and adeas31 committed Aug 14, 2018
1 parent 7606bd6 commit 717eccd
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 5 deletions.
88 changes: 88 additions & 0 deletions OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "FunctionArgumentDialog.h"

#include "LibraryTreeWidget.h"
#include "Component/Component.h"

#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>

FunctionArgumentDialog::FunctionArgumentDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *parent):
QDialog(parent), mpLibraryTreeItem(pLibraryTreeItem)
{
setWindowTitle(pLibraryTreeItem->getNameStructure());
QGridLayout *pGrid = new QGridLayout();

OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
mComponents = pOMCProxy->getComponents(pLibraryTreeItem->getNameStructure());
QString comment = pOMCProxy->getClassComment(pLibraryTreeItem->getNameStructure());

int row = 0;
pGrid->addWidget(new QLabel(comment), row++, 0, 1, 4);

for (int i = 0; i < mComponents.size(); ++i) {
ComponentInfo *pComponent = mComponents[i];
if (!isInput(pComponent))
continue;

pGrid->addWidget(new QLabel(pComponent->getName()), row, 0);

QLabel *typeLabel = new QLabel(pComponent->getClassName());
QFont typeFont;
typeFont.setBold(true);
typeLabel->setFont(typeFont);
pGrid->addWidget(typeLabel, row, 1);

QLabel *commentLabel = new QLabel(pComponent->getComment());
QFont commentFont;
commentFont.setItalic(true);
commentLabel->setFont(commentFont);
pGrid->addWidget(commentLabel, row, 2);

QLineEdit *pEditor = new QLineEdit();
mEditors.append(pEditor);
pGrid->addWidget(pEditor, row, 3);
++row;
}

QDialogButtonBox *pButtons = new QDialogButtonBox(
QDialogButtonBox::StandardButton::Ok |
QDialogButtonBox::StandardButton::Cancel);
pGrid->addWidget(pButtons, row, 0, 1, 4);
connect(pButtons, SIGNAL(accepted()), SLOT(accept()));
connect(pButtons, SIGNAL(rejected()), SLOT(reject()));

setLayout(pGrid);
}

QString FunctionArgumentDialog::getFunctionCallCommand()
{
QString result = mpLibraryTreeItem->getNameStructure() + "(";
int inputArgIndex = 0;
for (int i = 0; i < mComponents.size(); ++i) {
ComponentInfo *pComponent = mComponents[i];
if (!isInput(pComponent))
continue;

QString value = mEditors[inputArgIndex]->text();

if (inputArgIndex != 0) {
result += ", ";
}

if (pComponent->getClassName() == "String") {
result += "\"" + value + "\"";
} else {
result += value;
}

++inputArgIndex;
}
result += ")";
return result;
}

bool FunctionArgumentDialog::isInput(ComponentInfo *pComponentInfo)
{
return pComponentInfo->getCausality() == "input";
}
23 changes: 23 additions & 0 deletions OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef FUNCTIONPARAMETERDIALOG_H
#define FUNCTIONPARAMETERDIALOG_H

#include <QDialog>

class LibraryTreeItem;
class ComponentInfo;
class QLineEdit;

class FunctionArgumentDialog : public QDialog
{
public:
explicit FunctionArgumentDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *parent = 0);
QString getFunctionCallCommand();
private:
bool isInput(ComponentInfo *pComponentInfo);

LibraryTreeItem *mpLibraryTreeItem;
QList<ComponentInfo*> mComponents;
QList<QLineEdit*> mEditors;
};

#endif // FUNCTIONPARAMETERDIALOG_H
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ItemDelegate.h"
#include "MainWindow.h"
#include "ModelWidgetContainer.h"
#include "FunctionArgumentDialog.h"
#include "Options/OptionsDialog.h"
#include "MessagesWidget.h"
#include "DocumentationWidget.h"
Expand Down Expand Up @@ -749,11 +750,10 @@ void LibraryTreeItem::handleCoOrdinateSystemUpdated(GraphicsView *pGraphicsView)

void LibraryTreeItem::callFunction()
{
QInputDialog dlg(MainWindow::instance());
dlg.setLabelText(getNameStructure() + "(...):");
FunctionArgumentDialog dlg(this, MainWindow::instance());

if (dlg.exec() == QDialog::Accepted) {
QString cmd = getNameStructure() + "(" + dlg.textValue() + ")";
QString cmd = dlg.getFunctionCallCommand();

MainWindow::instance()->getOMCProxy()->openOMCLoggerWidget();
MainWindow::instance()->getOMCProxy()->sendCommand(cmd);
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ SOURCES += main.cpp \
OMS/OMSProxy.cpp \
Component/FMUProperties.cpp \
OMS/OMSSimulationDialog.cpp \
OMS/OMSSimulationOutputWidget.cpp
OMS/OMSSimulationOutputWidget.cpp \
Modeling/FunctionArgumentDialog.cpp

HEADERS += Util/Helper.h \
Util/Utilities.h \
Expand Down Expand Up @@ -277,7 +278,8 @@ HEADERS += Util/Helper.h \
Component/FMUProperties.h \
OMS/OMSSimulationOptions.h \
OMS/OMSSimulationDialog.h \
OMS/OMSSimulationOutputWidget.h
OMS/OMSSimulationOutputWidget.h \
Modeling/FunctionArgumentDialog.h

CONFIG(osg) {

Expand Down

0 comments on commit 717eccd

Please sign in to comment.