#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Data.h>
#include <Config_WidgetAPI.h>
+#include <Config_PropManager.h>
+#include <QDir>
+#include <QFile>
#include <QWidget>
#include <QLayout>
#include <QLabel>
#include <QButtonGroup>
#include <QGroupBox>
#include <QRadioButton>
+#include <QTextStream>
#include <QToolButton>
+void getValues(const std::string& thePath, const std::string& theFileName,
+ QStringList& theValues)
+{
+ QString aFileName = thePath.c_str();
+ aFileName += QDir::separator();
+ aFileName += theFileName.c_str();
+
+ QFile aFile(aFileName);
+ if (!aFile.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+
+ QTextStream aStream(&aFile);
+ while (!aStream.atEnd()) {
+ QString aLine = aStream.readLine();
+ if (!aLine.isEmpty())
+ theValues.append(aLine);
+ }
+}
ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
const Config_WidgetAPI* theData)
foreach(QString aType, QString(aTypes.c_str()).split(' ')) {
aList.append(translate(aType.toStdString()));
}
+ if (aTypes.empty()) {
+ aList.clear();
+ std::string aFileName = theData->getProperty("file_name");
+ if (!aFileName.empty()) {
+ std::string aPath = Config_PropManager::string("Plugins", "combo_box_elements_path");
+ getValues(aPath, aFileName, aList);
+ }
+ }
if (theData->getBooleanAttribute("use_in_title", false))
myButtonTitles = aList;
+ bool aHasDefaultValue;
+ int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue);
// Widget type can be combobox or radiobuttons
std::string aWgtType = theData->getProperty("widget_type");
if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) {
myButtons->addButton(aBtn, aId++);
}
}
- myButtons->button(0)->setChecked(true);
+ int aCheckedId = aHasDefaultValue ? aDefaultVal : 0;
+ myButtons->button(aDefaultVal)->setChecked(true);
connect(myButtons, SIGNAL(buttonClicked(int)), this, SLOT(onCurrentIndexChanged(int)));
} else {
myLabel = new QLabel(aLabelText, this);
myCombo->addItems(aList);
+ if (aHasDefaultValue && aDefaultVal < aList.size())
+ myCombo->setCurrentIndex(aDefaultVal);
+
connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
}
}
myCombo->blockSignals(isBlocked);
} else {
bool isBlocked = myButtons->blockSignals(true);
- myButtons->button(aIntAttr->value())->setChecked(true);
+ if (aIntAttr->isInitialized())
+ myButtons->button(aIntAttr->value())->setChecked(true);
+ else {
+ bool aHasDefaultValue;
+ int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue);
+ myButtons->button(aHasDefaultValue ? aDefaultVal : 0)->setChecked(true);
+ }
myButtons->blockSignals(isBlocked);
emit itemSelected(this, aIntAttr->value());
}