/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-2012 University of Bonn. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* StringQtQuery.cpp
*
* Created on: Oct 25, 2010
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include "CodePatterns/MemDebug.hpp"
#include "UIElements/Qt4/Query/QtQuery.hpp"
QtDialog::StringQtQuery::StringQtQuery(Parameter &_param, std::string _title,QBoxLayout *_parent,Dialog *_dialog) :
QtQuery(_param, _title),
parent(_parent),
dialog(_dialog)
{
temp = "";
if (param.isSet())
temp = param.get();
thisLayout = new QHBoxLayout();
titleLabel = new QLabel(QString(getTitle().c_str()));
parent->addLayout(thisLayout);
thisLayout->addWidget(titleLabel);
if (dynamic_cast*>(&_param.getValidator()) != NULL){
// Discrete set of valid string -> use a ComboBox.
const std::vector &strings = dynamic_cast*>(&_param.getValidator())->getValidValues();
comboBox = new QComboBox();
for(vector::const_iterator iter = strings.begin();
iter != strings.end();
++iter) {
comboBox->addItem(QString((*iter).c_str()));
}
thisLayout->addWidget(comboBox);
connect(comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(onUpdateCombo(int)));
onUpdateCombo(0);
}else{
// Use a LineEdit.
inputBox = new QLineEdit();
thisLayout->addWidget(inputBox);
onUpdate(inputBox->text());
connect(inputBox,SIGNAL(textChanged(const QString&)),this,SLOT(onUpdate(const QString&)));
}
}
QtDialog::StringQtQuery::~StringQtQuery()
{
}
void QtDialog::StringQtQuery::onUpdate(const QString& newText) {
temp = newText.toStdString();
dialog->update();
}
void QtDialog::StringQtQuery::onUpdateCombo(int newIndex) {
temp = comboBox->itemText(newIndex).toStdString();
dialog->update();
}