* ./vslsisapd/src/configuration:

- New: In Parameter, adds a priority for all the mutators method calls.
        Allows to sets values according to where they came from instead of
        only taking the last change. This is needed because we cannot ensure
        that the last sets value is the truly wanted one. Four priorities
        are avalaibles (in increasing order):
          1. - ApplicationBuiltin (the default).
          2. - ConfigurationFile  (currently: the XML parser).
          3. - CommandLine        (supplied by the command line, see Unicorn).
          4. - Interactive        (changed through ConfigurationWidget).
    - New: In ConfigurationWidget, hideTabs()/showTabs() to explicitly select
        which tabs are displayeds or hidden. Two modes are avalaibles:
        Incremental and Exact. In Exact mode only hidden tabs are hiddens and
        only shown tabs are shown.
    - Change: In ConfigurationWidget/ConfTabWidget/ParameterWidget, no longer
        relies on the Widget parent/child tree to find the ConfigurationWidget
        from a ParameterWidget (consequence of the hide/show capability which
        is implemented by cutting off hidden tabs). Adds an explicit attribute.
This commit is contained in:
Jean-Paul Chaput 2010-11-16 13:51:14 +00:00
parent 7506bae16e
commit a9d0783026
11 changed files with 276 additions and 138 deletions

View File

@ -54,7 +54,7 @@ int main ( int argc, char* argv[] )
options.add_options() options.add_options()
( "help,h" , "Print this help." ) ( "help,h" , "Print this help." )
( "disable-gtkstyle", boptions::bool_switch(&disableGtkStyle)->default_value(false) ( "disable-gtkstyle", boptions::bool_switch(&disableGtkStyle)->default_value(false)
, "Run the detailed router (Kite).") , "Do not uses GtkStyle (due to the File/Open native dialog bug).")
( "conf,c" , boptions::value<string>() ( "conf,c" , boptions::value<string>()
, "The path of the configuration file." ); , "The path of the configuration file." );
@ -93,9 +93,9 @@ int main ( int argc, char* argv[] )
} }
ConfEditorWidget* editor = new ConfEditorWidget (); ConfEditorWidget* editor = new ConfEditorWidget ();
//editor->getConfigurationWidget()->selectTab ( "Kite" );
editor->show (); editor->show ();
//QFileDialog::getOpenFileName(NULL, "Choose file", "", ""); //editor->getConfigurationWidget()->selectTab ( "Kite" );
//editor->getConfigurationWidget()->hideTabs ( "Kite;Mauka" );
returnCode = qa->exec (); returnCode = qa->exec ();
} }

View File

@ -49,11 +49,12 @@ namespace Cfg {
// Class : "Cfg::ConfTabWidget". // Class : "Cfg::ConfTabWidget".
ConfTabWidget::ConfTabWidget ( const string& name, QWidget* parent ) ConfTabWidget::ConfTabWidget ( ConfigurationWidget* parent, const string& name )
: QWidget (parent) : QWidget (parent)
, _gridLayout(new QGridLayout()) , _gridLayout(new QGridLayout())
, _columns (2) , _columns (2)
, _rowsCount (new int[_columns]) , _rowsCount (new int[_columns])
, _confWidget(parent)
, _parameters() , _parameters()
{ {
for ( int i=0 ; i<_columns ; ++i ) _rowsCount[i] = 0; for ( int i=0 ; i<_columns ; ++i ) _rowsCount[i] = 0;
@ -108,10 +109,13 @@ namespace Cfg {
} }
ConfigurationWidget* ConfTabWidget::getConfigurationWidget ()
{ return _confWidget; }
QFont& ConfTabWidget::getParentBoldFont () QFont& ConfTabWidget::getParentBoldFont ()
{ {
ConfigurationWidget* cw = rparent<ConfigurationWidget*> ( this ); return _confWidget->getBoldFont();
return cw->getBoldFont();
} }
@ -150,8 +154,7 @@ namespace Cfg {
, int span , int span
, int flags ) , int flags )
{ {
ConfigurationWidget* cw = rparent<ConfigurationWidget*> ( this ); ParameterWidget* pw = _confWidget->find(parameter);
ParameterWidget* pw = cw->find(parameter);
if ( pw != NULL ) { if ( pw != NULL ) {
cerr << "[ERROR] Parameter <" << parameter->getId() << "> already added." << endl; cerr << "[ERROR] Parameter <" << parameter->getId() << "> already added." << endl;

View File

@ -162,6 +162,7 @@ namespace {
_parameter = _configuration->addParameter ( attrId _parameter = _configuration->addParameter ( attrId
, type , type
, _getAttributeValue("value") , _getAttributeValue("value")
, Parameter::ConfigurationFile
); );
} else { } else {
_parameter->setString ( _getAttributeValue("value") _parameter->setString ( _getAttributeValue("value")
@ -427,7 +428,8 @@ namespace Cfg {
Parameter* Configuration::addParameter ( const string& id Parameter* Configuration::addParameter ( const string& id
, Parameter::Type type , Parameter::Type type
, const string& value ) , const string& value
, int priority )
{ {
Parameter* p = getParameter ( id ); Parameter* p = getParameter ( id );
if ( p != NULL ) { if ( p != NULL ) {
@ -435,7 +437,7 @@ namespace Cfg {
return p; return p;
} }
p = new Parameter ( id, type, value ); p = new Parameter ( id, type, value, priority );
_parameters.insert ( make_pair(id,p) ); _parameters.insert ( make_pair(id,p) );
return p; return p;

View File

@ -58,14 +58,15 @@ namespace Cfg {
ConfigurationWidget::ConfigurationWidget ( unsigned int flags, QWidget* parent ) ConfigurationWidget::ConfigurationWidget ( unsigned int flags, QWidget* parent )
: QWidget (parent) : QWidget (parent)
, _flags (flags) , _flags (flags)
, _boldFont (QApplication::font()) , _boldFont (QApplication::font())
, _tabWidget(new QTabWidget()) , _tabWidget (new QTabWidget())
, _apply (new QPushButton()) , _apply (new QPushButton())
, _save (NULL) , _save (NULL)
, _cancel (NULL) , _cancel (NULL)
, _log (NULL) , _tabWidgets()
, _log (NULL)
{ {
_boldFont.setBold ( true ); _boldFont.setBold ( true );
@ -111,21 +112,21 @@ namespace Cfg {
void ConfigurationWidget::addRuler ( const string& tabName ) void ConfigurationWidget::addRuler ( const string& tabName )
{ {
ConfTabWidget* tab = findOrCreate ( tabName ); ConfTabWidget* tab = findOrCreateTab ( tabName );
tab->addRuler (); tab->addRuler ();
} }
void ConfigurationWidget::addTitle ( const string& tabName, const string& title ) void ConfigurationWidget::addTitle ( const string& tabName, const string& title )
{ {
ConfTabWidget* tab = findOrCreate ( tabName ); ConfTabWidget* tab = findOrCreateTab ( tabName );
tab->addTitle ( title ); tab->addTitle ( title );
} }
void ConfigurationWidget::addSection ( const string& tabName, const string& section, int column ) void ConfigurationWidget::addSection ( const string& tabName, const string& section, int column )
{ {
ConfTabWidget* tab = findOrCreate ( tabName ); ConfTabWidget* tab = findOrCreateTab ( tabName );
tab->addSection ( section, column ); tab->addSection ( section, column );
} }
@ -143,7 +144,7 @@ namespace Cfg {
return pw; return pw;
} }
ConfTabWidget* tab = findOrCreate ( tabName ); ConfTabWidget* tab = findOrCreateTab ( tabName );
return tab->addParameter ( parameter, label, column, span, flags ); return tab->addParameter ( parameter, label, column, span, flags );
} }
@ -159,13 +160,16 @@ namespace Cfg {
{ return findChild<ParameterWidget*>(id.c_str()); } { return findChild<ParameterWidget*>(id.c_str()); }
ConfTabWidget* ConfigurationWidget::findOrCreate ( const string& tabName ) ConfTabWidget* ConfigurationWidget::findOrCreateTab ( const string& tabName )
{ {
ConfTabWidget* tab = findChild<ConfTabWidget*>(tabName.c_str()); //ConfTabWidget* tab = findChild<ConfTabWidget*>(tabName.c_str());
ConfTabWidget* tab = findTab(tabName,AllTabs);
if ( tab != NULL ) return tab; if ( tab != NULL ) return tab;
tab = new ConfTabWidget ( tabName ); tab = new ConfTabWidget ( this, tabName );
_tabWidget->addTab ( tab, tabName.c_str() ); _tabWidget->addTab ( tab, tabName.c_str() );
_tabWidgets.push_back ( tab );
connect ( this, SIGNAL(updateParameters()), tab, SIGNAL(updateParameters()) ); connect ( this, SIGNAL(updateParameters()), tab, SIGNAL(updateParameters()) );
if (_save) if (_save)
@ -219,15 +223,79 @@ namespace Cfg {
} }
void ConfigurationWidget::selectTab ( const std::string& tabName ) ConfTabWidget* ConfigurationWidget::findTab ( const std::string& tabName, int mode )
{ {
QString qtabName ( tabName.c_str() ); QString qtabName ( tabName.c_str() );
for ( int itab=0 ; itab<_tabWidget->count() ; ++itab ) {
if ( _tabWidget->tabText(itab) == qtabName ) { if ( mode & ShownTabs ) {
_tabWidget->setCurrentIndex ( itab ); for ( int itab=0 ; itab<_tabWidgets.size() ; ++itab ) {
return; if ( _tabWidgets[itab]->objectName() == qtabName ) return _tabWidgets[itab];
} }
} else {
// AllTabs.
for ( int itab=0 ; itab<_tabWidget->count() ; ++itab ) {
if ( _tabWidget->tabText(itab) == qtabName ) {
return qobject_cast<ConfTabWidget*>(_tabWidget->widget(itab));
}
} }
}
return NULL;
}
void ConfigurationWidget::selectTab ( const std::string& tabName )
{
ConfTabWidget* tab = findTab ( tabName, ShownTabs );
if ( tab ) _tabWidget->setCurrentWidget ( tab );
}
void ConfigurationWidget::showTabs ( const std::string& tabNames, int mode )
{
_tabWidget->setUpdatesEnabled ( false );
QString qtabNames ( tabNames.c_str() );
QStringList qtabList = qtabNames.split ( ";" );
if ( mode & ExactSet ) _tabWidget->clear ();
int insertIndex = 0;
for ( int itab=0 ; itab<_tabWidgets.size() ; ++itab ) {
ConfTabWidget* tab = _tabWidgets[itab];
int tabIndex = _tabWidget->indexOf ( tab );
if ( (tabIndex < 0) and qtabList.contains(tab->objectName()) ) {
tabIndex = _tabWidget->insertTab ( insertIndex, tab, tab->objectName() );
}
if ( tabIndex >= 0 ) insertIndex = tabIndex+1;
}
_tabWidget->setUpdatesEnabled ( true );
}
void ConfigurationWidget::hideTabs ( const std::string& tabNames, int mode )
{
_tabWidget->setUpdatesEnabled ( false );
QString qtabNames ( tabNames.c_str() );
QStringList qtabList = qtabNames.split ( ";" );
if ( mode & ExactSet ) _tabWidget->clear ();
for ( int itab=0 ; itab<_tabWidgets.size() ; ++itab ) {
ConfTabWidget* tab = _tabWidgets[itab];
int tabIndex = _tabWidget->indexOf ( tab );
if ( (tabIndex >= 0) and qtabList.contains(tab->objectName()) )
_tabWidget->removeTab ( tabIndex );
if ( (mode & ExactSet) and not qtabList.contains(tab->objectName()) )
_tabWidget->addTab ( tab, tab->objectName() );
}
_tabWidget->setUpdatesEnabled ( true );
} }

View File

@ -58,15 +58,21 @@ namespace Cfg {
Parameter::Parameter ( const std::string& id Parameter::Parameter ( const std::string& id
, Type type , Type type
, const std::string& value ) , const std::string& value
, int priority
)
: _id (id) : _id (id)
, _type (type) , _type (type)
, _value (value) , _value (value)
, _values ()
, _priority (priority)
, _flags (0) , _flags (0)
, _minInt (0) , _minInt (0)
, _maxInt (0) , _maxInt (0)
, _minDouble(0.0) , _minDouble(0.0)
, _maxDouble(0.0) , _maxDouble(0.0)
, _slaves ()
, _callbacks()
{ {
if ( type == Percentage ) { if ( type == Percentage ) {
setPercentage ( asDouble() ); setPercentage ( asDouble() );
@ -134,8 +140,11 @@ namespace Cfg {
} }
bool Parameter::setString ( const std::string& s, unsigned int flags ) bool Parameter::setString ( const std::string& s, unsigned int flags, int priority )
{ {
if ( priority < _priority ) return false;
_priority = priority;
if ( (flags & TypeCheck) and (_type != String) ) if ( (flags & TypeCheck) and (_type != String) )
cerr << "[ERROR] Parameter::setString(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setString(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id << " parameter <" << _id
@ -145,8 +154,11 @@ namespace Cfg {
} }
bool Parameter::setBool ( bool b ) bool Parameter::setBool ( bool b, int priority )
{ {
if ( priority < _priority ) return false;
_priority = priority;
if ( _type != Bool ) if ( _type != Bool )
cerr << "[ERROR] Parameter::setBool(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setBool(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id << " parameter <" << _id
@ -156,8 +168,11 @@ namespace Cfg {
} }
bool Parameter::setInt ( int i ) bool Parameter::setInt ( int i, int priority )
{ {
if ( priority < _priority ) return false;
_priority = priority;
if ( (_type != Int) and (_type != Enumerate) ) if ( (_type != Int) and (_type != Enumerate) )
cerr << "[ERROR] Parameter::setInt(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setInt(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id << " parameter <" << _id
@ -167,8 +182,11 @@ namespace Cfg {
} }
bool Parameter::setDouble ( double d ) bool Parameter::setDouble ( double d, int priority )
{ {
if ( priority < _priority ) return false;
_priority = priority;
if ( (_type != Double) and (_type != Percentage) ) if ( (_type != Double) and (_type != Percentage) )
cerr << "[ERROR] Parameter::setDouble(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setDouble(): Setting " << Parameter::typeToString(_type)
<< " parameter <" << _id << " parameter <" << _id
@ -178,7 +196,7 @@ namespace Cfg {
} }
bool Parameter::setPercentage ( double d ) bool Parameter::setPercentage ( double d, int priority )
{ {
if ( (_type != Double) and (_type != Percentage) ) if ( (_type != Double) and (_type != Percentage) )
cerr << "[ERROR] Parameter::setPercentage(): Setting " << Parameter::typeToString(_type) cerr << "[ERROR] Parameter::setPercentage(): Setting " << Parameter::typeToString(_type)

View File

@ -34,6 +34,7 @@
#include "vlsisapd/configuration/Parameter.h" #include "vlsisapd/configuration/Parameter.h"
#include "vlsisapd/configuration/FilePathEdit.h" #include "vlsisapd/configuration/FilePathEdit.h"
#include "vlsisapd/configuration/ParameterWidget.h" #include "vlsisapd/configuration/ParameterWidget.h"
#include "vlsisapd/configuration/ConfTabWidget.h"
#include "vlsisapd/configuration/ConfigurationWidget.h" #include "vlsisapd/configuration/ConfigurationWidget.h"
@ -47,12 +48,13 @@ namespace Cfg {
using std::ostringstream; using std::ostringstream;
ParameterWidget::ParameterWidget ( QObject* parent, Parameter* parameter, const std::string& label, int flags ) ParameterWidget::ParameterWidget ( ConfTabWidget* parent, Parameter* parameter, const std::string& label, int flags )
: QObject (parent) : QObject (parent)
, _parameter (parameter) , _confTabWidget(parent)
, _labelWidget(new QLabel()) , _parameter (parameter)
, _valueWidget(NULL) , _labelWidget (new QLabel())
, _flags (flags) , _valueWidget (NULL)
, _flags (flags)
{ {
setObjectName ( _parameter->getId().c_str() ); setObjectName ( _parameter->getId().c_str() );
@ -182,12 +184,12 @@ namespace Cfg {
if ( _parameter->getType() == Parameter::String ) if ( _parameter->getType() == Parameter::String )
{ {
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget); QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
_parameter->setString ( lineEdit->displayText().toStdString() ); _parameter->setString ( lineEdit->displayText().toStdString(), Parameter::Interactive );
} }
else if ( _parameter->getType() == Parameter::Bool ) else if ( _parameter->getType() == Parameter::Bool )
{ {
QCheckBox* checkBox = qobject_cast<QCheckBox*>(_valueWidget); QCheckBox* checkBox = qobject_cast<QCheckBox*>(_valueWidget);
_parameter->setBool ( checkBox->isChecked() ); _parameter->setBool ( checkBox->isChecked(), Parameter::Interactive );
} }
else if ( _parameter->getType() == Parameter::Int ) else if ( _parameter->getType() == Parameter::Int )
{ {
@ -195,14 +197,14 @@ namespace Cfg {
QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget); QSpinBox* spinBox = qobject_cast<QSpinBox*>(_valueWidget);
int value = spinBox->value(); int value = spinBox->value();
if ( not _parameter->setInt(value) ) if ( not _parameter->setInt(value,Parameter::Interactive) )
spinBox->setValue ( _parameter->asInt() ); spinBox->setValue ( _parameter->asInt() );
} else { } else {
bool success; bool success;
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget); QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
int value = lineEdit->displayText().toInt ( &success ); int value = lineEdit->displayText().toInt ( &success );
if ( not success or not _parameter->setInt(value) ) if ( not success or not _parameter->setInt(value,Parameter::Interactive) )
lineEdit->setText ( _parameter->asString().c_str() ); lineEdit->setText ( _parameter->asString().c_str() );
} }
} }
@ -212,7 +214,7 @@ namespace Cfg {
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget); QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
double value = lineEdit->displayText().toFloat ( &success ); double value = lineEdit->displayText().toFloat ( &success );
if ( not success or not _parameter->setDouble(value) ) if ( not success or not _parameter->setDouble(value,Parameter::Interactive) )
lineEdit->setText ( _parameter->asString().c_str() ); lineEdit->setText ( _parameter->asString().c_str() );
} }
else if ( _parameter->getType() == Parameter::Percentage ) else if ( _parameter->getType() == Parameter::Percentage )
@ -221,7 +223,7 @@ namespace Cfg {
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget); QLineEdit* lineEdit = qobject_cast<QLineEdit*>(_valueWidget);
double value = lineEdit->displayText().toFloat ( &success ); double value = lineEdit->displayText().toFloat ( &success );
if ( not success or not _parameter->setPercentage(value) ) { if ( not success or not _parameter->setPercentage(value,Parameter::Interactive) ) {
lineEdit->setText ( _parameter->asPercentageString().c_str() ); lineEdit->setText ( _parameter->asPercentageString().c_str() );
} }
} }
@ -230,7 +232,7 @@ namespace Cfg {
QComboBox* comboBox = qobject_cast<QComboBox*>(_valueWidget); QComboBox* comboBox = qobject_cast<QComboBox*>(_valueWidget);
const vector<Parameter::EnumValue>& values = _parameter->getValues(); const vector<Parameter::EnumValue>& values = _parameter->getValues();
_parameter->setInt ( values[comboBox->currentIndex()]._value ); _parameter->setInt ( values[comboBox->currentIndex()]._value, Parameter::Interactive );
} }
} }
@ -349,17 +351,11 @@ namespace Cfg {
void ParameterWidget::enableSlaves ( int state ) void ParameterWidget::enableSlaves ( int state )
{ {
ConfigurationWidget* cw = rparent<ConfigurationWidget*> ( this );
if ( cw == NULL ) {
cerr << "[ERROR] ParameterWidget::enableSlaves(): Cannot find parent ConfigurationWidget." << endl;
return;
}
bool enabled = ( state != Qt::Unchecked ); bool enabled = ( state != Qt::Unchecked );
const vector<string>& slaveIds = _parameter->getSlaves(); const vector<string>& slaveIds = _parameter->getSlaves();
for ( size_t islave=0 ; islave<slaveIds.size() ; ++islave ) { for ( size_t islave=0 ; islave<slaveIds.size() ; ++islave ) {
ParameterWidget* slave = cw->find(slaveIds[islave]); ParameterWidget* slave = getConfigurationWidget()->find(slaveIds[islave]);
if ( slave == NULL ) continue; if ( slave == NULL ) continue;
slave->getLabelWidget()->setEnabled ( enabled ); slave->getLabelWidget()->setEnabled ( enabled );
@ -368,4 +364,8 @@ namespace Cfg {
} }
ConfigurationWidget* ParameterWidget::getConfigurationWidget ()
{ return (_confTabWidget) ? _confTabWidget->getConfigurationWidget() : NULL; }
} // End of Cfg namespace. } // End of Cfg namespace.

View File

@ -45,24 +45,26 @@ namespace Cfg {
class ConfTabWidget : public QWidget { class ConfTabWidget : public QWidget {
Q_OBJECT; Q_OBJECT;
public: public:
ConfTabWidget ( const std::string& name="<noname>", QWidget* parent=NULL ); ConfTabWidget ( ConfigurationWidget* parent, const std::string& name="<noname>" );
virtual ~ConfTabWidget (); virtual ~ConfTabWidget ();
public: public:
QFont& getParentBoldFont (); ConfigurationWidget* getConfigurationWidget ();
void addRuler (); QFont& getParentBoldFont ();
void addTitle ( const std::string& title ); void addRuler ();
void addSection ( const std::string& section, int column=0 ); void addTitle ( const std::string& title );
ParameterWidget* addParameter ( Parameter*, const std::string& label, int column=0, int span=1, int flags=0 ); void addSection ( const std::string& section, int column=0 );
signals: ParameterWidget* addParameter ( Parameter*, const std::string& label, int column=0, int span=1, int flags=0 );
void updateParameters (); signals:
private: void updateParameters ();
int _getMaxRowCount (); private:
int _alignMaxRowCount (); int _getMaxRowCount ();
int _alignMaxRowCount ();
private: private:
QGridLayout* _gridLayout; QGridLayout* _gridLayout;
int _columns; int _columns;
int _span; int _span;
int* _rowsCount; int* _rowsCount;
ConfigurationWidget* _confWidget;
std::vector<ParameterWidget*> _parameters; std::vector<ParameterWidget*> _parameters;
}; };

View File

@ -72,7 +72,8 @@ namespace Cfg {
, Parameter::Type type=Parameter::Unknown ) const; , Parameter::Type type=Parameter::Unknown ) const;
Parameter* addParameter ( const std::string& id Parameter* addParameter ( const std::string& id
, Parameter::Type type , Parameter::Type type
, const std::string& value ); , const std::string& value
, int priority=0 );
inline void setFlags ( unsigned int mask ); inline void setFlags ( unsigned int mask );
inline bool hasLogs ( unsigned int mask ) const; inline bool hasLogs ( unsigned int mask ) const;
void addLog ( unsigned int mask, const std::string& id ); void addLog ( unsigned int mask, const std::string& id );

View File

@ -29,6 +29,7 @@
#include <QFont> #include <QFont>
#include <QWidget> #include <QWidget>
#include <QVector>
class QPushButton; class QPushButton;
class QTabWidget; class QTabWidget;
@ -49,7 +50,13 @@ namespace Cfg {
class ConfigurationWidget : public QWidget { class ConfigurationWidget : public QWidget {
Q_OBJECT; Q_OBJECT;
public: public:
enum Flags { Embedded=0x1, StandAlone=0x2 }; enum Flags { Embedded = 0x1
, StandAlone = 0x2
, AllTabs = 0x1
, ShownTabs = 0x2
, ExactSet = 0x4
, IncrementalSet = 0x8
};
public: public:
ConfigurationWidget ( unsigned int flags, QWidget* parent=NULL ); ConfigurationWidget ( unsigned int flags, QWidget* parent=NULL );
public: public:
@ -59,7 +66,8 @@ namespace Cfg {
inline QPushButton* getCancelButton (); inline QPushButton* getCancelButton ();
ParameterWidget* find ( Parameter* ) const; ParameterWidget* find ( Parameter* ) const;
ParameterWidget* find ( const std::string& id ) const; ParameterWidget* find ( const std::string& id ) const;
ConfTabWidget* findOrCreate ( const std::string& name ); ConfTabWidget* findTab ( const std::string& name, int mode );
ConfTabWidget* findOrCreateTab ( const std::string& name );
void addRuler ( const std::string& tabName ); void addRuler ( const std::string& tabName );
void addTitle ( const std::string& tabName void addTitle ( const std::string& tabName
, const std::string& title ); , const std::string& title );
@ -74,6 +82,8 @@ namespace Cfg {
, int flags =0 ); , int flags =0 );
void syncSlaves (); void syncSlaves ();
void selectTab ( const std::string& ); void selectTab ( const std::string& );
void showTabs ( const std::string&, int mode=IncrementalSet );
void hideTabs ( const std::string&, int mode=IncrementalSet );
public slots: public slots:
void applyClicked (); void applyClicked ();
signals: signals:
@ -81,13 +91,14 @@ namespace Cfg {
void confOk (); void confOk ();
void needRestart (); void needRestart ();
private: private:
unsigned int _flags; unsigned int _flags;
QFont _boldFont; QFont _boldFont;
QTabWidget* _tabWidget; QTabWidget* _tabWidget;
QPushButton* _apply; QPushButton* _apply;
QPushButton* _save; QPushButton* _save;
QPushButton* _cancel; QPushButton* _cancel;
LogWidget* _log; QVector<ConfTabWidget*> _tabWidgets;
LogWidget* _log;
}; };

View File

@ -38,24 +38,29 @@ namespace Cfg {
class Parameter { class Parameter {
public: public:
enum Type { Unknown = 0 enum Type { Unknown = 0
, String = 1 , String = 1
, Bool = 2 , Bool = 2
, Int = 3 , Int = 3
, Enumerate = 4 , Enumerate = 4
, Double = 5 , Double = 5
, Percentage = 6 , Percentage = 6
}; };
enum Flags { HasMin = 0x01 enum Flags { HasMin = 0x01
, HasMax = 0x02 , HasMax = 0x02
, IsFile = 0x04 , IsFile = 0x04
, IsPath = 0x08 , IsPath = 0x08
, NeedRestart = 0x10 , NeedRestart = 0x10
, MustExist = 0x20 , MustExist = 0x20
, TypeCheck = 0x40 , TypeCheck = 0x40
, FromString = 0x80 , FromString = 0x80
, AllRequirements = HasMin|HasMax|IsFile|IsPath|NeedRestart|MustExist|TypeCheck , AllRequirements = HasMin|HasMax|IsFile|IsPath|NeedRestart|MustExist|TypeCheck
}; };
enum Priority { ApplicationBuiltin = 1
, ConfigurationFile = 2
, CommandLine = 3
, Interactive = 4
};
typedef boost::function< void(Parameter*) > ParameterChangedCb_t; typedef boost::function< void(Parameter*) > ParameterChangedCb_t;
public: public:
class EnumValue { class EnumValue {
@ -70,7 +75,8 @@ namespace Cfg {
public: public:
Parameter ( const std::string& id Parameter ( const std::string& id
, Type type , Type type
, const std::string& value ); , const std::string& value
, int priority=0 );
inline bool isFile () const; inline bool isFile () const;
inline bool isPath () const; inline bool isPath () const;
inline bool hasMin () const; inline bool hasMin () const;
@ -99,17 +105,21 @@ namespace Cfg {
double asPercentage () const; double asPercentage () const;
inline void addValue ( const std::string&, int ); inline void addValue ( const std::string&, int );
inline void addSlave ( const std::string& ); inline void addSlave ( const std::string& );
inline void setPriority ( int );
inline void setFlags ( int mask ); inline void setFlags ( int mask );
inline void unsetFlags ( int mask ); inline void unsetFlags ( int mask );
bool setString ( const std::string&, unsigned int flags=AllRequirements ); bool setString ( const std::string&
bool setBool ( bool ); , unsigned int flags=AllRequirements
bool setInt ( int ); , int priority=ApplicationBuiltin
bool setDouble ( double ); );
bool setPercentage ( double ); bool setBool ( bool , int priority=ApplicationBuiltin );
inline void setMin ( int ); bool setInt ( int , int priority=ApplicationBuiltin );
inline void setMax ( int ); bool setDouble ( double, int priority=ApplicationBuiltin );
inline void setMin ( double ); bool setPercentage ( double, int priority=ApplicationBuiltin );
inline void setMax ( double ); inline void setMin ( int , int priority=ApplicationBuiltin );
inline void setMax ( int , int priority=ApplicationBuiltin );
inline void setMin ( double, int priority=ApplicationBuiltin );
inline void setMax ( double, int priority=ApplicationBuiltin );
inline void registerCb ( ParameterChangedCb_t ); inline void registerCb ( ParameterChangedCb_t );
private: private:
inline void _onValueChanged (); inline void _onValueChanged ();
@ -120,6 +130,7 @@ namespace Cfg {
Type _type; Type _type;
std::string _value; std::string _value;
std::vector<EnumValue> _values; std::vector<EnumValue> _values;
int _priority;
int _flags; int _flags;
int _minInt; int _minInt;
int _maxInt; int _maxInt;
@ -146,6 +157,9 @@ namespace Cfg {
inline double Parameter::getMinDouble () const { return _minDouble; } inline double Parameter::getMinDouble () const { return _minDouble; }
inline double Parameter::getMaxDouble () const { return _maxDouble; } inline double Parameter::getMaxDouble () const { return _maxDouble; }
inline const std::string& Parameter::asString () const { return _value; } inline const std::string& Parameter::asString () const { return _value; }
inline void Parameter::setFlags ( int mask ) { _flags |= mask; }
inline void Parameter::unsetFlags ( int mask ) { _flags &= ~mask; }
inline void Parameter::setPriority ( int priority ) { _priority = priority; }
inline bool Parameter::checkValue ( int value ) const { inline bool Parameter::checkValue ( int value ) const {
bool ok = not ( ( (_flags&HasMin) and (value < _minInt) ) bool ok = not ( ( (_flags&HasMin) and (value < _minInt) )
@ -178,16 +192,29 @@ namespace Cfg {
_values.push_back ( EnumValue(label,value) ); _values.push_back ( EnumValue(label,value) );
} }
inline void Parameter::setFlags ( int mask ) { _flags |= mask; } inline void Parameter::setMin ( int min, int priority )
inline void Parameter::unsetFlags ( int mask ) { _flags &= ~mask; } { if (priority >= _priority) { _priority=priority; _minInt = min; setFlags(HasMin); } }
inline void Parameter::setMin ( int min ) { _minInt = min; setFlags(HasMin); }
inline void Parameter::setMax ( int max ) { _maxInt = max; setFlags(HasMax); } inline void Parameter::setMax ( int max, int priority )
{ if (priority >= _priority) { _priority=priority; _maxInt = max; setFlags(HasMax); } }
inline void Parameter::setMin ( double min ) inline void Parameter::setMin ( double min, int priority )
{ _minDouble = min; setFlags(HasMin); if (_type==Percentage) _minDouble/=100.0; } { if (priority >= _priority) {
_priority = priority;
_minDouble = min;
setFlags ( HasMin );
if (_type==Percentage) _minDouble/=100.0;
}
}
inline void Parameter::setMax ( double max ) inline void Parameter::setMax ( double max, int priority )
{ _maxDouble = max; setFlags(HasMax); if (_type==Percentage) _maxDouble/=100.0; } { if (priority >= _priority) {
_priority = priority;
_maxDouble = max;
setFlags ( HasMax );
if (_type==Percentage) _maxDouble/=100.0;
}
}
inline Parameter::EnumValue::EnumValue ( const std::string& label, int value ) inline Parameter::EnumValue::EnumValue ( const std::string& label, int value )
: _label(label), _value(value) { } : _label(label), _value(value) { }

View File

@ -35,6 +35,8 @@ class QLabel;
namespace Cfg { namespace Cfg {
class Parameter; class Parameter;
class ConfTabWidget;
class ConfigurationWidget;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -46,34 +48,38 @@ namespace Cfg {
public: public:
enum Flags { UseSpinBox=0x1, IsFileName=0x2, IsPathName=0x4 }; enum Flags { UseSpinBox=0x1, IsFileName=0x2, IsPathName=0x4 };
public: public:
ParameterWidget ( QObject* parent, Parameter*, const std::string& label, int flags ); ParameterWidget ( ConfTabWidget* parent, Parameter*, const std::string& label, int flags );
inline Parameter* getParameter (); inline Parameter* getParameter ();
inline QLabel* getLabelWidget (); inline QLabel* getLabelWidget ();
inline QWidget* getValueWidget (); inline QWidget* getValueWidget ();
inline int getFlags () const; inline ConfTabWidget* getConfTabWidget ();
inline bool hasFlags ( int mask ) const; ConfigurationWidget* getConfigurationWidget ();
inline void setFlags ( int mask ); inline int getFlags () const;
inline void unsetFlags ( int mask ); inline bool hasFlags ( int mask ) const;
void onUpdateValueCb ( Parameter* ); inline void setFlags ( int mask );
public slots: inline void unsetFlags ( int mask );
void updateValue (); void onUpdateValueCb ( Parameter* );
void enableSlaves ( int ); public slots:
void updateValue ();
void enableSlaves ( int );
public: public:
Parameter* _parameter; ConfTabWidget* _confTabWidget;
QLabel* _labelWidget; Parameter* _parameter;
QWidget* _valueWidget; QLabel* _labelWidget;
int _flags; QWidget* _valueWidget;
int _flags;
}; };
// Inline Methods. // Inline Methods.
inline Parameter* ParameterWidget::getParameter () { return _parameter; } inline Parameter* ParameterWidget::getParameter () { return _parameter; }
inline QLabel* ParameterWidget::getLabelWidget () { return _labelWidget; } inline QLabel* ParameterWidget::getLabelWidget () { return _labelWidget; }
inline QWidget* ParameterWidget::getValueWidget () { return _valueWidget; } inline QWidget* ParameterWidget::getValueWidget () { return _valueWidget; }
inline int ParameterWidget::getFlags () const { return _flags; } inline ConfTabWidget* ParameterWidget::getConfTabWidget () { return _confTabWidget; }
inline bool ParameterWidget::hasFlags ( int mask ) const { return (_flags & mask); } inline int ParameterWidget::getFlags () const { return _flags; }
inline void ParameterWidget::setFlags ( int mask ) { _flags |= mask; } inline bool ParameterWidget::hasFlags ( int mask ) const { return (_flags & mask); }
inline void ParameterWidget::unsetFlags ( int mask ) { _flags &= ~mask; } inline void ParameterWidget::setFlags ( int mask ) { _flags |= mask; }
inline void ParameterWidget::unsetFlags ( int mask ) { _flags &= ~mask; }
} // End of Cfg namespace. } // End of Cfg namespace.