Parameter set in ParameterWidget

This commit is contained in:
amarjeetkapoor1 2016-07-14 01:17:21 +05:30
parent 5d16b5de66
commit f5829d6e67
4 changed files with 66 additions and 8 deletions

View file

@ -38,7 +38,8 @@
ParameterWidget::ParameterWidget(QWidget *parent) : QWidget(parent)
{
setupUi(this);
getParameterSet("save.json");
setComboBoxForSet();
descriptionShow=true;
autoPreviewTimer.setInterval(500);
autoPreviewTimer.setSingleShot(true);
@ -51,6 +52,26 @@ ParameterWidget::~ParameterWidget()
{
}
void ParameterWidget::setComboBoxForSet(){
this->comboBox->addItem("No Set Selected",
QVariant(QString::fromStdString("")));
for(Parameterset::iterator it=parameterSet.begin();it != parameterSet.end();it++){
this->comboBox->addItem(QString::fromStdString(it->first),
QVariant(QString::fromStdString(it->first)));
}
this->comboBox->setCurrentText("No Set Selected");
connect(comboBox, SIGNAL(currentIndexChanged(int)),this,SLOT(onSetChanged(int)));
}
void ParameterWidget::onSetChanged(int idx){
const string v = comboBox->itemData(idx).toString().toUtf8().constData();
applyParameterSet(v);
emit previewRequested();
}
void ParameterWidget::onDescriptionShow()
{
if(checkBoxDetailedDescription->isChecked()){
@ -203,4 +224,30 @@ if(groupMap.find("Global")!=groupMap.end()){
end();
}
void ParameterWidget::applyParameterSet(string setName){
Parameterset::iterator set=parameterSet.find(setName);
if(set==parameterSet.end()){
qWarning("no set");
return ;
}
SetOfParameter setofparameter=set->second;
for(SetOfParameter::iterator i = setofparameter.begin();i!=setofparameter.end();i++){
entry_map_t::iterator entry =entries.find(i->first);
if(entry!=entries.end()){
if(entry->second->dvt == Value::STRING){
entry->second->value=ValuePtr(i->second);
}else if(entry->second->dvt== Value::BOOL){
entry->second->value=ValuePtr(i->second=="true");
}
else{
entry->second->value=ValuePtr(QString::fromStdString(i->second).toDouble());
}
}
}
}

View file

@ -31,8 +31,9 @@
#include "parameterextractor.h"
#include "ui_ParameterWidget.h"
#include "groupwidget.h"
#include "parameterset.h"
class ParameterWidget : public QWidget, public Ui::ParameterWidget, public ParameterExtractor
class ParameterWidget : public QWidget, public Ui::ParameterWidget, public ParameterExtractor, public ParameterSet
{
Q_OBJECT
private:
@ -51,6 +52,7 @@ protected slots:
void onValueChanged();
void onPreviewTimerElapsed();
void onDescriptionShow();
void onSetChanged(int idx);
signals:
@ -61,5 +63,7 @@ protected:
void begin();
void addEntry(class ParameterVirtualWidget *entry);
void end();
void setComboBoxForSet();
void applyParameterSet(string setName);
};

View file

@ -16,7 +16,7 @@ ParameterSet::ParameterSet()
{
}
bool ParameterSet::getParameterSet(string filename){
void ParameterSet::getParameterSet(string filename){
try{
std::fstream myfile;
@ -32,15 +32,13 @@ bool ParameterSet::getParameterSet(string filename){
SetOfParameter setofparameter;
std::cout<<"model name"<<v.first<<std::endl;
for(pt::ptree::value_type &vi : v.second){
setofparameter[vi.first]=vi.second.data();
std::cout<<vi.first<<std::endl;
}
parameterSet[v.first]=setofparameter;
}
myfile.close();
print();
}
catch (std::exception const& e)
{
@ -73,14 +71,22 @@ void ParameterSet::applyParameterSet(FileModule *fileModule,string setName)
}
SetOfParameter setofparameter=set->second;
ModuleContext ctx;
for (AssignmentList::iterator it = fileModule->scope.assignments.begin();it != fileModule->scope.assignments.end();it++) {
for(SetOfParameter::iterator i = setofparameter.begin();i!=setofparameter.end();i++){
if(i->first== (*it).name){
Assignment *assignment;
assignment=&(*it);
assignment=&(*it);
const ValuePtr defaultValue = assignment->expr.get()->evaluate(&ctx);
if(defaultValue->type()== Value::STRING){
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(i->second)));
}else if(defaultValue->type()== Value::BOOL){
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(i->second=="true")));
}else{
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(QString::fromStdString(i->second).toDouble()))) ;
}
}
}

View file

@ -10,6 +10,7 @@ using namespace std;
class ParameterSet
{
protected:
typedef map<string,string >SetOfParameter;
typedef map<string,SetOfParameter> Parameterset;
Parameterset parameterSet;
@ -17,7 +18,7 @@ class ParameterSet
public:
ParameterSet();
bool getParameterSet(string filename);
void getParameterSet(string filename);
void print();
void applyParameterSet(FileModule *fileModule,string setName);