* ./vslsisapd/src/configuration:

- New: Attributes "needRestart", "mustExist", "isFile" and "isPath".
    - New: Display a warning message when a parameter with mustExist or
        needRestart is modificated.
    - New: In ConfigurationWidget, method selectTab() to select the current
        displayed tab.
    - Change: In Configuration::writeToFile() and writeToStream(), adds a
        third parameter telling which parameter to save. It's a semicolon
        separated list of parameter head id. Example: "kite;mauka".
This commit is contained in:
Jean-Paul Chaput 2010-10-06 22:03:35 +00:00
parent 3d2d3e545d
commit 9f0fb0b467
18 changed files with 708 additions and 182 deletions

View File

@ -7,10 +7,11 @@
)
set ( mocIncludes vlsisapd/configuration/FilePathEdit.h
vlsisapd/configuration/ConfigurationWidget.h
vlsisapd/configuration/ConfigurationDialog.h
vlsisapd/configuration/ParameterWidget.h
vlsisapd/configuration/ConfTabWidget.h
vlsisapd/configuration/LogWidget.h
vlsisapd/configuration/ConfigurationWidget.h
vlsisapd/configuration/ConfEditorWidget.h
)
set ( includes vlsisapd/configuration/Parameter.h
@ -23,6 +24,7 @@
FilePathEdit.cpp
ParameterWidget.cpp
ConfTabWidget.cpp
LogWidget.cpp
ConfigurationWidget.cpp
ConfigurationDialog.cpp
ConfEditorWidget.cpp

View File

@ -93,6 +93,7 @@ int main ( int argc, char* argv[] )
}
ConfEditorWidget* editor = new ConfEditorWidget ();
//editor->getConfigurationWidget()->selectTab ( "Kite" );
editor->show ();
//QFileDialog::getOpenFileName(NULL, "Choose file", "", "");

View File

@ -90,6 +90,7 @@ namespace Cfg {
cout << "Saving configuration file: <" << dotConfigFile << ">."<< endl;
//Configuration::get()->writeToStream ( file, 0, ";misc;kite;;mauka;;" );
Configuration::get()->writeToStream ( file, 0 );
//Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout );
file.close ();

View File

@ -23,6 +23,7 @@
// x-----------------------------------------------------------------x
#include <cstring>
#include <sstream>
#include <fstream>
#include <iomanip>
@ -40,6 +41,24 @@ namespace {
using namespace Cfg;
void tokenize ( set<string>& tokens, const string& line )
{
static std::string separators = " ;";
size_t iBegin = 0;
size_t iEnd = 0;
for ( ; iEnd < line.size() ; ++iEnd ) {
if ( separators.find(line[iEnd]) != std::string::npos ) {
if ( iBegin < iEnd )
tokens.insert ( line.substr(iBegin,iEnd-iBegin) );
iBegin = iEnd+1;
}
}
if ( iBegin < iEnd )
tokens.insert ( line.substr(iBegin,iEnd-iBegin) );
}
class XmlParser {
public:
XmlParser ( Configuration*, const string& fileName );
@ -125,6 +144,10 @@ namespace {
string attrId = _getAttributeValue("id");
string attrType = _getAttributeValue("type");
string attrRestart = _getAttributeValue("needRestart");
string attrMustExist = _getAttributeValue("mustExist");
string attrIsFile = _getAttributeValue("isFile");
string attrIsPath = _getAttributeValue("isPath");
Parameter::Type type = Parameter::String;
if ( attrType == "string" ) type = Parameter::String;
@ -144,6 +167,11 @@ namespace {
_parameter->setString ( _getAttributeValue("value"), false );
}
if ( not attrRestart.empty() ) _parameter->setFlags ( Parameter::NeedRestart );
if ( not attrMustExist.empty() ) _parameter->setFlags ( Parameter::MustExist );
if ( not attrIsFile.empty() ) _parameter->setFlags ( Parameter::IsFile );
if ( not attrIsPath.empty() ) _parameter->setFlags ( Parameter::IsPath );
if ( type == Parameter::Percentage ) {
istringstream s ( _getAttributeValue("value") );
double ratio;
@ -257,7 +285,7 @@ namespace {
{
string attrName = _getAttributeValue("name");
_configuration->getLayout().addTab ( new TabDescription(attrName) );
_configuration->getLayout().addTab ( attrName );
_status = xmlTextReaderRead ( _reader );
while ( _status == 1 ) {
@ -359,7 +387,13 @@ namespace Cfg {
Configuration::Configuration ()
: _parameters()
, _layout (this)
{ }
, _flags (0)
, _logSets ()
{
_logSets.reserve ( LogTypeSize );
for ( size_t ilog=0 ; ilog<LogTypeSize ; ++ilog )
_logSets.push_back ( set<string>() );
}
ConfigurationWidget* Configuration::buildWidget ( unsigned int flags )
@ -409,6 +443,18 @@ namespace Cfg {
}
void Configuration::addLog ( unsigned int type, const string& id )
{
_logSets[ (type<LogTypeSize) ? type : 0 ].insert ( id );
}
void Configuration::removeLog ( unsigned int type, const string& id )
{
_logSets[ (type<LogTypeSize) ? type : 0 ].erase ( id );
}
void Configuration::print ( ostream& out ) const
{
map<const string,Parameter*>::const_iterator iparameter = _parameters.begin();
@ -442,20 +488,23 @@ namespace Cfg {
}
bool Configuration::writeToFile ( const std::string& fileName, unsigned int flags ) const
bool Configuration::writeToFile ( const std::string& fileName, unsigned int flags, const string& tabs ) const
{
ofstream out ( fileName.c_str() );
if ( out.fail() ) return false;
writeToStream ( out, flags );
writeToStream ( out, flags, tabs );
out.close ();
return true;
}
void Configuration::writeToStream ( ostream& out, unsigned int flags ) const
void Configuration::writeToStream ( ostream& out, unsigned int flags, const string& tabs ) const
{
set<string> tabset;
tokenize ( tabset, tabs );
out << "<configuration>" << endl;
map<const string,Parameter*>::const_iterator iparameter = _parameters.begin();
@ -465,23 +514,37 @@ namespace Cfg {
string id = "\"" + p->getId() + "\"";
string type = "\"" + Parameter::typeToString(p->getType()) + "\"";
if ( not tabset.empty() ) {
set<string>::iterator itab = tabset.begin();
for ( ; itab != tabset.end() ; ++itab ) {
if ( id.compare(1,(*itab).size(),*itab) == 0 ) {
break;
}
}
if ( itab == tabset.end() ) continue;
}
out << " <parameter"
<< " id=" << setw(40) << left << id
<< " type=" << setw(12) << left << type
<< " value=\"";
if ( p->getType() == Parameter::Percentage ) out << p->asPercentage();
if ( p->getType() == Parameter::Percentage ) out << p->asPercentageString();
else out << p->asString();
out << "\"";
if ( flags & DriveValues ) {
if ( p->getType() == Parameter::Int ) {
if ( p->hasFlags(Parameter::HasMin) ) out << " min=\"" << p->getMinInt() << "\"";
if ( p->hasFlags(Parameter::HasMax) ) out << " max=\"" << p->getMaxInt() << "\"";
if ( p->hasMin() ) out << " min=\"" << p->getMinInt() << "\"";
if ( p->hasMax() ) out << " max=\"" << p->getMaxInt() << "\"";
} else if ( p->getType() == Parameter::Double ) {
if ( p->hasFlags(Parameter::HasMin) ) out << " min=\"" << p->getMinDouble() << "\"";
if ( p->hasFlags(Parameter::HasMax) ) out << " max=\"" << p->getMaxDouble() << "\"";
if ( p->hasMin() ) out << " min=\"" << p->getMinDouble() << "\"";
if ( p->hasMax() ) out << " max=\"" << p->getMaxDouble() << "\"";
}
if ( p->hasMustExist() ) out << " mustExist=\"true\"";
if ( p->hasNeedRestart() ) out << " needRestart=\"true\"";
if ( p->isFile() ) out << " isFile=\"true\"";
if ( p->isPath() ) out << " isPath=\"true\"";
}
if ( (flags&DriveValues) and (p->getType() == Parameter::Enumerate) ) {

View File

@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/choose.png</file>
<file>images/warning.png</file>
</qresource>
</RCC>

View File

@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include <map>
#include <map>
#include <QApplication>
#include <QTabWidget>
#include <QPushButton>
@ -35,6 +36,7 @@
#include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/ParameterWidget.h"
#include "vlsisapd/configuration/ConfTabWidget.h"
#include "vlsisapd/configuration/LogWidget.h"
#include "vlsisapd/configuration/ConfigurationWidget.h"
@ -44,6 +46,7 @@ namespace Cfg {
using std::cerr;
using std::endl;
using std::string;
using std::set;
using std::map;
using std::pair;
using std::make_pair;
@ -62,6 +65,7 @@ namespace Cfg {
, _apply (new QPushButton())
, _save (NULL)
, _cancel (NULL)
, _log (NULL)
{
_boldFont.setBold ( true );
@ -93,6 +97,8 @@ namespace Cfg {
vLayout->addStretch ();
setLayout ( vLayout );
connect ( _apply, SIGNAL(clicked()), this, SLOT(applyClicked()) );
}
@ -158,7 +164,7 @@ namespace Cfg {
tab = new ConfTabWidget ( tabName );
_tabWidget->addTab ( tab, tabName.c_str() );
connect ( _apply, SIGNAL(clicked()), tab, SIGNAL(updateParameters()) );
connect ( this, SIGNAL(updateParameters()), tab, SIGNAL(updateParameters()) );
return tab;
}
@ -180,6 +186,37 @@ namespace Cfg {
}
void ConfigurationWidget::applyClicked ()
{
emit updateParameters();
checkConfiguration ();
}
void ConfigurationWidget::checkConfiguration ()
{
Configuration* configuration = Configuration::get();
if ( configuration->hasLogs() ) {
if ( _log == NULL ) _log = new LogWidget(this);
_log->updateLogs ();
_log->exec ();
}
}
void ConfigurationWidget::selectTab ( const std::string& tabName )
{
QString qtabName ( tabName.c_str() );
for ( int itab=0 ; itab<_tabWidget->count() ; ++itab ) {
if ( _tabWidget->tabText(itab) == qtabName ) {
_tabWidget->setCurrentIndex ( itab );
return;
}
}
}
string toXml ( const string& source )
{
static vector< pair<string,string> > translations;

View File

@ -35,16 +35,40 @@ namespace Cfg {
using std::endl;
using std::string;
using std::vector;
using std::map;
using std::make_pair;
using std::ostream;
void TabDescription::addWidget ( WidgetDescription* widget )
{
_widgets.push_back(widget);
_layout->addWidgetLookup(widget);
}
WidgetDescription* LayoutDescription::getWidget ( const string& id )
{
map<const string,WidgetDescription*>::iterator iwid = _widgets.find(id);
if ( iwid != _widgets.end() ) return (*iwid).second;
return NULL;
}
void LayoutDescription::addWidgetLookup ( WidgetDescription* widget )
{
_widgets.insert ( make_pair(widget->getId(),widget) );
}
TabDescription* LayoutDescription::getTab ( const string& tabName )
{
for ( size_t itab=0 ; itab<_tabs.size() ; ++itab ) {
if ( _tabs[itab]->getName() == tabName ) return _tabs[itab];
}
addTab ( new TabDescription(tabName) );
addTab ( new TabDescription(this,tabName) );
return getBackTab();
}
@ -78,7 +102,9 @@ namespace Cfg {
, unsigned int flags )
{
TabDescription* tab = getTab ( tabName );
tab->addWidget ( WidgetDescription::parameter(id,label,column,span,flags) );
WidgetDescription* widget = WidgetDescription::parameter(id,label,column,span,flags);
tab->addWidget ( widget );
}

View File

@ -0,0 +1,151 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | C o n f i g u r a t i o n D a t a - B a s e |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Module : "./LogWidget.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#include <set>
#include <string>
#include <QCloseEvent>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFrame>
#include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/LogWidget.h"
namespace Cfg {
using std::set;
using std::string;
using std::cerr;
using std::endl;
LogWidget::LogWidget ( QWidget* parent )
: QDialog (parent)
, _restartMessage (new QLabel())
, _needExistMessage(new QLabel())
{
setModal ( true );
setWindowTitle( tr("<Configuration Message>") );
setToolTip ( tr("You should better follow these instructions...") );
_restartMessage->setTextFormat ( Qt::RichText );
_restartMessage->setText ( "<b>Oups! I did it again!</b>" );
QLabel* ok = new QLabel ();
ok->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
ok->setPixmap ( QPixmap(":/images/warning.png") );
ok->setStyleSheet ( "QLabel { background-color: #FF9999;"
" padding: 5px }" );
QPushButton* okButton = new QPushButton ();
okButton->setSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed );
okButton->setText ( tr("Continue") );
QHBoxLayout* hLayout2 = new QHBoxLayout ();
hLayout2->addStretch ( 1 );
hLayout2->addWidget ( okButton, Qt::AlignCenter );
hLayout2->addStretch ( 1 );
QVBoxLayout* vLayout1 = new QVBoxLayout ();
vLayout1->setContentsMargins ( 10, 10, 10, 10 );
vLayout1->setSpacing ( 0 );
vLayout1->addWidget ( _restartMessage , Qt::AlignCenter );
vLayout1->addWidget ( _needExistMessage, Qt::AlignCenter );
vLayout1->addSpacing ( 10 );
vLayout1->addLayout ( hLayout2, Qt::AlignCenter );
QHBoxLayout* hLayout1 = new QHBoxLayout ();
hLayout1->setSizeConstraint ( QLayout::SetFixedSize );
hLayout1->setContentsMargins ( 0, 0, 0, 0 );
hLayout1->addWidget ( ok );
hLayout1->addLayout ( vLayout1 );
setLayout ( hLayout1 );
connect ( okButton, SIGNAL(clicked()), this, SLOT(accept()) );
}
void LogWidget::closeEvent ( QCloseEvent* event )
{
event->ignore ();
}
void LogWidget::updateLogs ()
{
Configuration* configuration = Configuration::get();
for ( size_t ilog=0 ; ilog<Configuration::LogTypeSize ; ++ilog ) {
const set<string>& logs = configuration->getLogs(ilog);
QLabel* messageLabel = NULL;
QString contents;
const char* header = NULL;
switch ( ilog ) {
case Configuration::LogRestart:
messageLabel = _restartMessage;
header = "<b>Program needs restart for these parameters to take effect:</b><br>";
break;
case Configuration::LogNeedExist:
messageLabel = _needExistMessage;
header = "<b>Those parameters needs file/path to exists:</b><br>";
break;
}
if ( messageLabel == NULL ) continue;
if ( not logs.empty() ) {
contents += header;
set<string>::const_iterator iid = logs.begin();
for ( ; iid != logs.end() ; ++iid ) {
Parameter* p = configuration->getParameter((*iid));
if ( p != NULL ) {
WidgetDescription* desc = configuration->getLayout().getWidget ( p->getId() );
contents += "&nbsp;&nbsp;&nbsp;";
if ( desc != NULL ) {
contents += desc->getLabel().c_str();
contents += "&nbsp;&nbsp;";
}
contents += "<tt>&lt;";
contents += p->getId().c_str();
contents += "&gt;</tt>: ";
if ( p->asString().size() > 30 ) contents += "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
contents += p->asString().c_str();
contents += "<br>";
}
}
}
messageLabel->setText ( contents );
}
}
} // End of Hurricane Namespace.

View File

@ -24,7 +24,11 @@
#include <iostream>
#include <boost/filesystem/operations.hpp>
namespace bfs = boost::filesystem;
#include "vlsisapd/configuration/Parameter.h"
#include "vlsisapd/configuration/Configuration.h"
namespace Cfg {
@ -69,6 +73,20 @@ namespace Cfg {
}
string Parameter::asPercentageString () const
{
if ( (_type != Double) and (_type != Percentage) )
cerr << "[ERROR] Accessing " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(Percentage)<< " (type mismatch)." << endl;
std::istringstream is ( _value ); double r; is >> r;
std::ostringstream os; os << (r*100.0);
return os.str();
}
bool Parameter::asBool () const
{
if ( _type != Bool )
@ -113,64 +131,121 @@ namespace Cfg {
}
void Parameter::setString ( const std::string& s, bool check )
bool Parameter::setString ( const std::string& s, bool check )
{
if ( check and (_type != String) )
cerr << "[ERROR] Parameter::setString(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(String)<< " (type mismatch)." << endl;
if ( _value == s ) return true;
_value = s;
_onValueChanged();
_checkRequirements();
return true;
}
void Parameter::setBool ( bool b )
bool Parameter::setBool ( bool b )
{
if ( _type != Bool )
cerr << "[ERROR] Parameter::setBool(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(Bool)<< " (type mismatch)." << endl;
std::ostringstream s; s << std::boolalpha << b; _value = s.str();
std::ostringstream s; s << std::boolalpha << b;
if ( _value == s.str() ) return true;
_value = s.str();
_onValueChanged();
_checkRequirements();
return true;
}
void Parameter::setInt ( int i )
bool Parameter::setInt ( int i )
{
if ( (_type != Int) and (_type != Enumerate) )
cerr << "[ERROR] Parameter::setInt(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(Int)<< " (type mismatch)." << endl;
std::ostringstream s; s << i; _value = s.str();
bool success = checkValue(i);
if ( success ) {
std::ostringstream s; s << i;
if ( _value == s.str() ) return true;
_value = s.str();
_onValueChanged();
_checkRequirements();
}
return success;
}
void Parameter::setDouble ( double d )
bool Parameter::setDouble ( double d )
{
if ( (_type != Double) and (_type != Percentage) )
cerr << "[ERROR] Parameter::setDouble(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl;
std::ostringstream s; s << d; _value = s.str();
bool success = checkValue(d);
if ( success ) {
std::ostringstream s; s << d;
if ( _value == s.str() ) return true;
_value = s.str();
_onValueChanged();
_checkRequirements();
}
return success;
}
void Parameter::setPercentage ( double d )
bool Parameter::setPercentage ( double d )
{
if ( (_type != Double) and (_type != Percentage) )
cerr << "[ERROR] Parameter::setPercentage(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id
<< "> as " << Parameter::typeToString(Double)<< " (type mismatch)." << endl;
std::ostringstream s; s << (d/100.0); _value = s.str();
bool success = checkValue(d/100.0);
if ( success ) {
std::ostringstream s; s << (d/100.0);
if ( _value == s.str() ) return true;
_value = s.str();
_onValueChanged();
_checkRequirements();
}
return success;
}
void Parameter::_checkRequirements () const
{
Configuration* configuration = Configuration::get();
if ( hasFlags(NeedRestart) ) {
configuration->addLog ( Configuration::LogRestart, _id );
}
if ( hasFlags(MustExist) ) {
if ( _type == String ) {
bfs::path filePath = ( asString() );
if ( not bfs::exists(filePath) )
configuration->addLog ( Configuration::LogNeedExist, _id );
else
configuration->removeLog ( Configuration::LogNeedExist, _id );
}
}
}

View File

@ -173,9 +173,7 @@ namespace Cfg {
string valueId = _parameter->getId() + ".edit";
_valueWidget->setObjectName ( valueId.c_str() );
//Parameter::ParameterChangedCb_t cb = boost::bind(&ParameterWidget::updateValueCb,this);
_parameter->registerCb ( boost::bind(&ParameterWidget::updateValueCb,this,_1) );
_parameter->registerCb ( boost::bind(&ParameterWidget::onUpdateValueCb,this,_1) );
}
@ -197,6 +195,113 @@ namespace Cfg {
QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget);
int value = spinBox->value();
if ( not _parameter->setInt(value) )
spinBox->setValue ( _parameter->asInt() );
} else {
bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
int value = lineEdit->displayText().toInt ( &success );
if ( not success or not _parameter->setInt(value) )
lineEdit->setText ( _parameter->asString().c_str() );
}
}
else if ( _parameter->getType() == Parameter::Double )
{
bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
double value = lineEdit->displayText().toFloat ( &success );
if ( not success or not _parameter->setDouble(value) )
lineEdit->setText ( _parameter->asString().c_str() );
}
else if ( _parameter->getType() == Parameter::Percentage )
{
bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
double value = lineEdit->displayText().toFloat ( &success );
if ( not success or not _parameter->setPercentage(value) ) {
lineEdit->setText ( _parameter->asPercentageString().c_str() );
}
}
else if ( _parameter->getType() == Parameter::Enumerate )
{
QComboBox* comboBox = qobject_cast<QComboBox*>(_valueWidget);
const vector<Parameter::EnumValue>& values = _parameter->getValues();
_parameter->setInt ( values[comboBox->currentIndex()]._value );
}
}
void ParameterWidget::onUpdateValueCb ( Parameter* )
{
if ( _parameter->getType() == Parameter::String )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
lineEdit->setText ( _parameter->asString().c_str() );
}
else if ( _parameter->getType() == Parameter::Bool )
{
QCheckBox* checkBox = qobject_cast<QCheckBox*>(_valueWidget);
checkBox->setChecked ( _parameter->asBool() );
}
else if ( _parameter->getType() == Parameter::Int )
{
if ( hasFlags(UseSpinBox) ) {
QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget);
spinBox->setValue ( _parameter->asInt() );
} else {
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
lineEdit->setText ( _parameter->asString().c_str() );
}
}
else if ( _parameter->getType() == Parameter::Double )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
lineEdit->setText ( _parameter->asString().c_str() );
}
else if ( _parameter->getType() == Parameter::Percentage )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
lineEdit->setText ( _parameter->asPercentageString().c_str() );
}
else if ( _parameter->getType() == Parameter::Enumerate )
{
QComboBox* comboBox = qobject_cast<QComboBox*>(_valueWidget);
int value = _parameter->asInt();
const vector<Parameter::EnumValue>& values = _parameter->getValues();
for ( size_t ival=0 ; ival < values.size() ; ++ival ) {
if ( values[ival]._value == value ) {
comboBox->setCurrentIndex ( ival );
break;
}
}
}
}
#if BACKUP
void ParameterWidget::onUpdateValueCb ( Parameter* )
{
if ( _parameter->getType() == Parameter::String )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
_parameter->setString ( lineEdit->displayText().toStdString() );
}
else if ( _parameter->getType() == Parameter::Bool )
{
QCheckBox* checkBox = qobject_cast<QCheckBox*>(_valueWidget);
_parameter->setBool ( checkBox->isChecked() );
}
else if ( _parameter->getType() == Parameter::Int )
{
if ( hasFlags(UseSpinBox) ) {
QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget);
int value = spinBox->value();
if ( _parameter->checkValue(value) ) _parameter->setInt ( value );
else spinBox->setValue ( _parameter->asInt() );
} else {
@ -237,67 +342,7 @@ namespace Cfg {
_parameter->setInt ( values[comboBox->currentIndex()]._value );
}
}
void ParameterWidget::updateValueCb ( Parameter* p )
{
if ( _parameter->getType() == Parameter::String )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
if ( _parameter->asString() != lineEdit->displayText().toStdString() ) return;
lineEdit->setText ( _parameter->asString().c_str() );
}
else if ( _parameter->getType() == Parameter::Bool )
{
QCheckBox* checkBox = qobject_cast<QCheckBox*>(_valueWidget);
if ( _parameter->asBool() == checkBox->isChecked() ) return;
checkBox->setCheckState ( Qt::Checked );
}
else if ( _parameter->getType() == Parameter::Int )
{
if ( hasFlags(UseSpinBox) ) {
QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget);
if ( spinBox->value() == _parameter->asInt() ) return;
spinBox->setValue ( _parameter->asInt() );
} else {
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
if ( _parameter->asString() == lineEdit->displayText().toStdString() ) return;
lineEdit->setText ( _parameter->asString().c_str() );
}
}
else if ( _parameter->getType() == Parameter::Double )
{
bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
if ( _parameter->asDouble() == lineEdit->displayText().toFloat(&success) ) return;
lineEdit->setText ( _parameter->asString().c_str() );
}
else if ( _parameter->getType() == Parameter::Percentage )
{
bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
double value = lineEdit->displayText().toFloat ( &success );
if ( value == _parameter->asPercentage() ) return;
lineEdit->setText ( QString("%1").arg(_parameter->asPercentage()) );
}
else if ( _parameter->getType() == Parameter::Enumerate )
{
QComboBox* comboBox = qobject_cast<QComboBox*>(_valueWidget);
const vector<Parameter::EnumValue>& values = _parameter->getValues();
if ( values[comboBox->currentIndex()]._value == _parameter->asInt() ) return;
for ( size_t ivalue=0 ; ivalue<values.size() ; ++ivalue ) {
if ( values[ivalue]._value == _parameter->asInt() )
comboBox->setCurrentIndex ( ivalue );
}
}
}
#endif
void ParameterWidget::enableSlaves ( int state )

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -42,6 +42,7 @@ namespace Cfg {
ConfEditorWidget ( QWidget* parent=NULL );
void createActions ();
void createMenus ();
inline ConfigurationWidget* getConfigurationWidget ();
public slots:
void save ();
private:
@ -52,6 +53,11 @@ namespace Cfg {
};
// Inline Functions.
inline ConfigurationWidget* ConfEditorWidget::getConfigurationWidget ()
{ return _configurationWidget; }
} // End of Cfg namespace.
#endif // __VLSISAPD_CONF_EDITOR_WIDGET__

View File

@ -28,6 +28,7 @@
#include <string>
#include <map>
#include <set>
#include <iostream>
#include "vlsisapd/configuration/Parameter.h"
#include "vlsisapd/configuration/LayoutDescription.h"
@ -42,6 +43,7 @@ namespace Cfg {
class Configuration {
public:
enum Flags { DriveValues=0x1, DriveLayout=0x2 };
enum LogType { LogRestart=0, LogNeedExist, LogTypeSize };
public:
static Configuration* get ();
public:
@ -50,6 +52,9 @@ namespace Cfg {
ConfigurationDialog* buildDialog ();
inline const std::map<const std::string,Parameter*>&
getParameters () const;
inline const std::set<std::string>&
getLogs ( unsigned int type ) const;
inline unsigned int getFlags () const;
inline const LayoutDescription& getLayout () const;
inline LayoutDescription& getLayout ();
Parameter* getParameter ( const std::string& id
@ -57,15 +62,22 @@ namespace Cfg {
Parameter* addParameter ( const std::string& id
, Parameter::Type type
, const std::string& value );
inline void setFlags ( unsigned int mask );
inline bool hasLogs () const;
void addLog ( unsigned int type, const std::string& id );
void removeLog ( unsigned int type, const std::string& id );
inline void clearLogs ();
void print ( std::ostream& ) const;
bool readFromFile ( const std::string& );
bool writeToFile ( const std::string&, unsigned int flags ) const;
void writeToStream ( std::ostream&, unsigned int flags ) const;
bool writeToFile ( const std::string&, unsigned int flags, const std::string& tabs="" ) const;
void writeToStream ( std::ostream&, unsigned int flags, const std::string& tabs="" ) const;
private:
// Attributes.
static Configuration* _singleton;
std::map<const std::string,Parameter*> _parameters;
LayoutDescription _layout;
unsigned int _flags;
std::vector< std::set<std::string> > _logSets;
private:
Configuration ();
};
@ -75,8 +87,26 @@ namespace Cfg {
inline const std::map<const std::string,Parameter*>& Configuration::getParameters () const
{ return _parameters; }
inline const std::set<std::string>& Configuration::getLogs ( unsigned int type ) const
{ return _logSets[(type<LogTypeSize) ? type : 0]; }
inline const LayoutDescription& Configuration::getLayout () const { return _layout; }
inline LayoutDescription& Configuration::getLayout () { return _layout; }
inline unsigned int Configuration::getFlags () const { return _flags; }
inline void Configuration::setFlags ( unsigned int mask ) { _flags |= mask; }
inline bool Configuration::hasLogs () const
{
for ( size_t ilog=0 ; ilog<_logSets.size() ; ++ilog )
if ( not _logSets[ilog].empty () ) return true;
return false;
}
inline void Configuration::clearLogs ()
{
for ( size_t ilog=0 ; ilog<_logSets.size() ; ++ilog )
_logSets[ilog].clear ();
}
inline Parameter* getParamString ( const std::string& id, const std::string& value="<undefined>" )
@ -144,6 +174,8 @@ namespace Cfg {
}
} // End of Cfg namespace.

View File

@ -39,6 +39,7 @@ namespace Cfg {
class Parameter;
class ParameterWidget;
class ConfTabWidget;
class LogWidget;
// -------------------------------------------------------------------
@ -72,6 +73,12 @@ namespace Cfg {
, int span =1
, int flags =0 );
void syncSlaves ();
void checkConfiguration ();
void selectTab ( const std::string& );
public slots:
void applyClicked ();
signals:
void updateParameters ();
private:
unsigned int _flags;
QFont _boldFont;
@ -79,6 +86,7 @@ namespace Cfg {
QPushButton* _apply;
QPushButton* _save;
QPushButton* _cancel;
LogWidget* _log;
};

View File

@ -29,6 +29,7 @@
#include <string>
#include <vector>
#include <map>
#include <iostream>
@ -36,6 +37,7 @@ namespace Cfg {
class Configuration;
class ConfigurationWidget;
class LayoutDescription;
// -------------------------------------------------------------------
@ -120,24 +122,22 @@ namespace Cfg {
class TabDescription {
public:
inline TabDescription ( const std::string& name );
inline void addWidget ( WidgetDescription* );
inline TabDescription ( LayoutDescription*, const std::string& name );
void addWidget ( WidgetDescription* );
inline const std::string& getName () const;
inline const std::vector<WidgetDescription*>& getWidgets () const;
private:
LayoutDescription* _layout;
std::string _name;
std::vector<WidgetDescription*> _widgets;
};
// Inline Methods.
inline TabDescription::TabDescription ( const std::string& name )
: _name(name), _widgets()
inline TabDescription::TabDescription ( LayoutDescription* layout, const std::string& name )
: _layout(layout), _name(name), _widgets()
{ }
inline void TabDescription::addWidget ( WidgetDescription* widget )
{ _widgets.push_back(widget); }
inline const std::string& TabDescription::getName () const
{ return _name; }
@ -152,7 +152,10 @@ namespace Cfg {
class LayoutDescription {
public:
inline LayoutDescription ( Configuration* );
WidgetDescription* getWidget ( const std::string& id );
void addWidgetLookup ( WidgetDescription* );
inline void addTab ( TabDescription* );
inline void addTab ( const std::string& tabName );
inline TabDescription* getBackTab ();
TabDescription* getTab ( const std::string& tabName );
inline const std::vector<TabDescription*>& getTabs () const;
@ -173,17 +176,21 @@ namespace Cfg {
private:
Configuration* _configuration;
std::vector<TabDescription*> _tabs;
std::map<const std::string,WidgetDescription*> _widgets;
};
// Inline Methods.
inline LayoutDescription::LayoutDescription ( Configuration* cfg )
: _configuration(cfg), _tabs()
: _configuration(cfg), _tabs(), _widgets()
{ }
inline void LayoutDescription::addTab ( TabDescription* tab )
{ _tabs.push_back(tab); }
inline void LayoutDescription::addTab ( const std::string& tabName )
{ addTab ( new TabDescription(this,tabName) ); }
inline TabDescription* LayoutDescription::getBackTab ()
{ return _tabs.back(); }

View File

@ -0,0 +1,53 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | C o n f i g u r a t i o n D a t a - B a s e |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Header : "./vlsispad/configuration/LogWidget.h" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#ifndef __CONFIGURATION_LOG_WIDGET__
#define __CONFIGURATION_LOG_WIDGET__
#include <QDialog>
class QLabel;
namespace Cfg {
class LogWidget : public QDialog {
Q_OBJECT;
public:
LogWidget ( QWidget* parent=NULL);
void updateLogs ();
private:
QLabel* _restartMessage;
QLabel* _needExistMessage;
protected:
virtual void closeEvent ( QCloseEvent* );
};
} // End of Configuration namespace.
#endif // __CONFIGURATION_LOG_WIDGET__

View File

@ -46,8 +46,12 @@ namespace Cfg {
, Double = 5
, Percentage = 6
};
enum Flags { HasMin = 0x1
, HasMax = 0x2
enum Flags { HasMin = 0x01
, HasMax = 0x02
, IsFile = 0x04
, IsPath = 0x08
, NeedRestart = 0x10
, MustExist = 0x20
};
typedef boost::function< void(Parameter*) > ParameterChangedCb_t;
public:
@ -64,6 +68,13 @@ namespace Cfg {
Parameter ( const std::string& id
, Type type
, const std::string& value );
inline bool isFile () const;
inline bool isPath () const;
inline bool hasMin () const;
inline bool hasMax () const;
inline bool hasNeedRestart () const;
inline bool hasMustExist () const;
inline bool hasFlags ( int mask ) const;
inline const std::string& getId () const;
inline const Type getType () const;
inline const std::vector<EnumValue>&
@ -71,7 +82,6 @@ namespace Cfg {
inline const std::vector<std::string>&
getSlaves () const;
inline int getFlags () const;
inline bool hasFlags ( int mask ) const;
inline int getMinInt () const;
inline int getMaxInt () const;
inline double getMinDouble () const;
@ -79,19 +89,20 @@ namespace Cfg {
inline bool checkValue ( int ) const;
inline bool checkValue ( double ) const;
inline const std::string& asString () const;
std::string asPercentageString () const;
bool asBool () const;
int asInt () const;
double asDouble () const;
double asPercentage () const;
inline void addValue ( const std::string&, int );
inline void addSlave ( const std::string& );
void setString ( const std::string&, bool check=true );
inline void setFlags ( int mask );
inline void unsetFlags ( int mask );
void setBool ( bool );
void setInt ( int );
void setDouble ( double );
void setPercentage ( double );
bool setString ( const std::string&, bool check=true );
bool setBool ( bool );
bool setInt ( int );
bool setDouble ( double );
bool setPercentage ( double );
inline void setMin ( int );
inline void setMax ( int );
inline void setMin ( double );
@ -99,6 +110,7 @@ namespace Cfg {
inline void registerCb ( ParameterChangedCb_t );
private:
inline void _onValueChanged ();
void _checkRequirements () const;
private:
// Attributes.
std::string _id;
@ -116,6 +128,12 @@ namespace Cfg {
// Inline Methods.
inline bool Parameter::isFile () const { return hasFlags(IsFile); };
inline bool Parameter::isPath () const { return hasFlags(IsPath); };
inline bool Parameter::hasMin () const { return hasFlags(HasMin); };
inline bool Parameter::hasMax () const { return hasFlags(HasMax); };
inline bool Parameter::hasNeedRestart () const { return hasFlags(NeedRestart); };
inline bool Parameter::hasMustExist () const { return hasFlags(MustExist); };
inline const std::string& Parameter::getId () const { return _id; }
inline const Parameter::Type Parameter::getType () const { return _type; }
inline int Parameter::getFlags () const { return _flags; }

View File

@ -54,7 +54,7 @@ namespace Cfg {
inline bool hasFlags ( int mask ) const;
inline void setFlags ( int mask );
inline void unsetFlags ( int mask );
void updateValueCb ( Parameter* );
void onUpdateValueCb ( Parameter* );
public slots:
void updateValue ();
void enableSlaves ( int );