Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Drop down menus for Enumeration and Boolean types.
- Added a new API getBuiltinType.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23278 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 8, 2014
1 parent 090dde8 commit 17b9de4
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 17 deletions.
141 changes: 128 additions & 13 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -60,8 +60,19 @@ Parameter::Parameter(ComponentInfo *pComponentInfo, OMCProxy *pOMCProxy, QString
mpFixedCheckBox->setCheckState(Qt::PartiallyChecked);
connect(mpFixedCheckBox, SIGNAL(clicked()), SLOT(showFixedMenu()));
mshowStartAttribute = showStartAttribute;
mpValueTextBox = new QLineEdit;
mpValueTextBox->setMinimumWidth(100); /* Set the minimum width for so atleast it can show the value when scroll bars are on */
// set the value type based on component type.
if ((pOMCProxy->isBuiltinType(pComponentInfo->getClassName())) && (pComponentInfo->getClassName().compare("Boolean") == 0)) {
mValueType = Parameter::Boolean;
} else if (pOMCProxy->isBuiltinType(pComponentInfo->getClassName())) {
mValueType = Parameter::Normal;
} else if (pOMCProxy->isWhat(StringHandler::Enumeration, pComponentInfo->getClassName())) {
mValueType = Parameter::Enumeration;
} else if (pOMCProxy->getBuiltinType(pComponentInfo->getClassName()).compare("Boolean") == 0) {
mValueType = Parameter::Boolean;
} else {
mValueType = Parameter::Normal;
}
createValueWidget(pOMCProxy, pComponentInfo->getClassName());

QString value;
bool defaultValue = true;
Expand Down Expand Up @@ -121,12 +132,7 @@ Parameter::Parameter(ComponentInfo *pComponentInfo, OMCProxy *pOMCProxy, QString
defaultValue = true;
}
}
if (defaultValue) {
mpValueTextBox->setPlaceholderText(value);
} else {
mpValueTextBox->setText(value);
}
mpValueTextBox->setCursorPosition(0); /* move the cursor to start so that parameter value will show up from start instead of end. */
setValueWidget(value, defaultValue);
mpUnitLabel = new Label;
mpCommentLabel = new Label;
/*
Expand All @@ -145,6 +151,42 @@ Parameter::Parameter(ComponentInfo *pComponentInfo, OMCProxy *pOMCProxy, QString
mpCommentLabel = new Label(pComponentInfo->getComment());
}

QWidget* Parameter::getValueWidget()
{
switch (mValueType) {
case Parameter::Boolean:
case Parameter::Enumeration:
return mpValueComboBox;
case Parameter::Normal:
default:
return mpValueTextBox;
}
}

bool Parameter::isValueModified()
{
switch (mValueType) {
case Parameter::Boolean:
case Parameter::Enumeration:
return mpValueComboBox->lineEdit()->isModified();
case Parameter::Normal:
default:
return mpValueTextBox->isModified();
}
}

QString Parameter::getValue()
{
switch (mValueType) {
case Parameter::Boolean:
case Parameter::Enumeration:
return mpValueComboBox->lineEdit()->text().trimmed();
case Parameter::Normal:
default:
return mpValueTextBox->text().trimmed();
}
}

void Parameter::setFixedState(QString fixed)
{
if (fixed.compare("true") == 0) {
Expand Down Expand Up @@ -200,7 +242,81 @@ QString Parameter::getUnitFromDerivedClass(OMCProxy *pOMCProxy, QString classNam
*/
void Parameter::setEnabled(bool enable)
{
mpValueTextBox->setEnabled(enable);
switch (mValueType) {
case Parameter::Boolean:
case Parameter::Enumeration:
mpValueComboBox->setEnabled(enable);
break;
case Parameter::Normal:
default:
mpValueTextBox->setEnabled(enable);
break;
}
}

void Parameter::createValueWidget(OMCProxy *pOMCProxy, QString className)
{
int i;
QStringList enumerationLiterals;
switch (mValueType) {
case Parameter::Boolean:
mpValueComboBox = new QComboBox;
mpValueComboBox->setEditable(true);
mpValueComboBox->addItem("", "");
mpValueComboBox->addItem("true", "true");
mpValueComboBox->addItem("false", "false");
/* Set the minimum width so atleast it can show the value when scroll bars are on */
mpValueComboBox->setMinimumWidth(100);
connect(mpValueComboBox, SIGNAL(currentIndexChanged(int)), SLOT(valueComboBoxChanged(int)));
break;
case Parameter::Enumeration:
mpValueComboBox = new QComboBox;
mpValueComboBox->setEditable(true);
mpValueComboBox->addItem("", "");
enumerationLiterals = pOMCProxy->getEnumerationLiterals(className);
for (i = 0 ; i < enumerationLiterals.size(); i++) {
mpValueComboBox->addItem(enumerationLiterals[i], className + "." + enumerationLiterals[i]);
}
/* Set the minimum width so atleast it can show the value when scroll bars are on */
mpValueComboBox->setMinimumWidth(100);
connect(mpValueComboBox, SIGNAL(currentIndexChanged(int)), SLOT(valueComboBoxChanged(int)));
break;
case Parameter::Normal:
default:
mpValueTextBox = new QLineEdit;
/* Set the minimum width so atleast it can show the value when scroll bars are on */
mpValueTextBox->setMinimumWidth(100);
break;
}
}

void Parameter::setValueWidget(QString value, bool defaultValue)
{
switch (mValueType) {
case Parameter::Boolean:
case Parameter::Enumeration:
if (defaultValue) {
mpValueComboBox->lineEdit()->setPlaceholderText(value);
} else {
mpValueComboBox->lineEdit()->setText(value);
}
break;
case Parameter::Normal:
default:
if (defaultValue) {
mpValueTextBox->setPlaceholderText(value);
} else {
mpValueTextBox->setText(value);
}
mpValueTextBox->setCursorPosition(0); /* move the cursor to start so that parameter value will show up from start instead of end. */
break;
}
}

void Parameter::valueComboBoxChanged(int index)
{
mpValueComboBox->lineEdit()->setText(mpValueComboBox->itemData(index).toString());
mpValueComboBox->lineEdit()->setModified(true);
}

void Parameter::showFixedMenu()
Expand Down Expand Up @@ -636,7 +752,7 @@ void ComponentParameters::createParameters(OMCProxy *pOMCProxy, QString classNam
if (showStartAttribute) {
pGroupBoxGridLayout->addWidget(pParameter->getFixedCheckBox(), layoutIndex, columnIndex++);
}
pGroupBoxGridLayout->addWidget(pParameter->getValueTextBox(), layoutIndex, columnIndex++);
pGroupBoxGridLayout->addWidget(pParameter->getValueWidget(), layoutIndex, columnIndex++);
pGroupBoxGridLayout->addWidget(pParameter->getUnitLabel(), layoutIndex, columnIndex++);
pGroupBoxGridLayout->addWidget(pParameter->getCommentLabel(), layoutIndex, columnIndex++);
mParametersList.append(pParameter);
Expand Down Expand Up @@ -674,12 +790,11 @@ void ComponentParameters::updateComponentParameters()
bool valueChanged = false;
bool modifierValueChanged = false;
foreach (Parameter *pParameter, mParametersList) {
QLineEdit *pValueTextBox = pParameter->getValueTextBox();
QString className = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeNode()->getNameStructure();
QString componentModifier = QString(mpComponent->getName()).append(".").append(pParameter->getNameLabel()->text());
if (pValueTextBox->isModified()) {
if (pParameter->isValueModified()) {
valueChanged = true;
QString componentModifierValue = pValueTextBox->text().trimmed();
QString componentModifierValue = pParameter->getValue();
/* If the component is inherited then add the modifier value into the extends. */
if (mpComponent->isInheritedComponent()) {
if (mpComponent->getOMCProxy()->setExtendsModifierValue(className, mpComponent->getInheritedClassName(), componentModifier, componentModifierValue.prepend("=")))
Expand Down
17 changes: 16 additions & 1 deletion OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -45,12 +45,21 @@ class Parameter : public QObject
{
Q_OBJECT
public:
enum ValueType {
Normal, /* Integer, Real etc. */
Boolean,
Enumeration
};
Parameter(ComponentInfo *pComponentInfo, OMCProxy *pOMCProxy, QString className, QString componentBaseClassName,
QString componentClassName, QString componentName, bool inheritedComponent, QString inheritedClassName, bool showStartAttribute);
Label* getNameLabel() {return mpNameLabel;}
QCheckBox* getFixedCheckBox() {return mpFixedCheckBox;}
bool isShowStartAttribute() {return mshowStartAttribute;}
QLineEdit* getValueTextBox() {return mpValueTextBox;}
void setValueType(ValueType valueType) {mValueType = valueType;}
ValueType getValueType() {return mValueType;}
QWidget* getValueWidget();
bool isValueModified();
QString getValue();
Label* getUnitLabel() {return mpUnitLabel;}
Label* getCommentLabel() {return mpCommentLabel;}
void setFixedState(QString fixed);
Expand All @@ -61,10 +70,16 @@ class Parameter : public QObject
Label *mpNameLabel;
QCheckBox *mpFixedCheckBox;
bool mshowStartAttribute;
ValueType mValueType;
QComboBox *mpValueComboBox;
QLineEdit *mpValueTextBox;
Label *mpUnitLabel;
Label *mpCommentLabel;

void createValueWidget(OMCProxy *pOMCProxy, QString className);
void setValueWidget(QString value, bool defaultValue);
public slots:
void valueComboBoxChanged(int index);
void showFixedMenu();
void trueFixedClicked();
void falseFixedClicked();
Expand Down
30 changes: 29 additions & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -1013,13 +1013,25 @@ bool OMCProxy::isBuiltinType(QString typeName)
typeName == "Boolean");
}

/*!
Returns true if the given type is one of the predefined types in Modelica.
Returns also the name of the predefined type.
*/
QString OMCProxy::getBuiltinType(QString typeName)
{
sendCommand("getBuiltinType(" + typeName + ")");
QString result = StringHandler::unparse(getResult());
getErrorString();
return result;
}

/*!
Checks the class type.
\param type - the type to check.
\param className - the class to check.
\return true if the class is a specified type
*/
bool OMCProxy::isWhat(int type, QString className)
bool OMCProxy::isWhat(StringHandler::ModelicaClasses type, QString className)
{
switch (type)
{
Expand Down Expand Up @@ -1059,6 +1071,9 @@ bool OMCProxy::isWhat(int type, QString className)
case StringHandler::Optimization:
sendCommand("isOptimization(" + className + ")", true, className);
break;
case StringHandler::Enumeration:
sendCommand("isEnumeration(" + className + ")", true, className);
break;
default:
return false;
}
Expand Down Expand Up @@ -2514,6 +2529,19 @@ bool OMCProxy::copyClass(QString className, QString newClassName, QString withIn
return result;
}

/*!
Gets the list of enumeration literals of the class.
\param className - the enumeration class
\return the list of enumeration literals
*/
QStringList OMCProxy::getEnumerationLiterals(QString className)
{
sendCommand("getEnumerationLiterals(" + className + ")", true, className);
QStringList enumerationLiterals = StringHandler::unparseStrings(getResult());
printMessagesStringInternal();
return enumerationLiterals;
}

/*!
\class CustomExpressionBox
\brief A text box for executing OMC commands.
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -131,7 +131,8 @@ class OMCProxy : public QObject
QStringList getClassInformation(QString className);
bool isPackage(QString className);
bool isBuiltinType(QString typeName);
bool isWhat(int type, QString className);
QString getBuiltinType(QString typeName);
bool isWhat(StringHandler::ModelicaClasses type, QString className);
bool isProtected(QString parameter, QString className);
bool isProtectedClass(QString className, QString nestedClassName);
bool isPartial(QString className);
Expand Down Expand Up @@ -223,6 +224,7 @@ class OMCProxy : public QObject
bool setDebugFlags(QString flags);
bool exportToFigaro(QString className, QString database, QString mode, QString options, QString processor);
bool copyClass(QString className, QString newClassName, QString withIn);
QStringList getEnumerationLiterals(QString className);
signals:
void commandFinished();
public slots:
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Util/StringHandler.h
Expand Up @@ -50,7 +50,7 @@ class StringHandler : public QObject
~StringHandler();
enum ViewType {Icon, Diagram, ModelicaText, NoView};
enum ModelicaClasses {Model, Class, Connector, ExpandableConnector, Record, Block, Function, Package, Primitive, Type, Operator,
OperatorRecord, OperatorFunction, Optimization, Parameter, Constant, Protected};
OperatorRecord, OperatorFunction, Optimization, Parameter, Constant, Protected, Enumeration};
enum OpenModelicaErrors {Notification, Warning, OMError, NoOMError};
static const QString errorLevelToString[NoOMError+1];
enum OpenModelicaErrorKinds {Syntax, Grammar, Translation, Symbolic, Simulation, Scripting, NoOMErrorKind};
Expand Down

0 comments on commit 17b9de4

Please sign in to comment.