* ./vslsisapd/src/configuration:

- New: In Configuration, write methods are ables to completly drive the
        XML file (values & layout), selectable through flags.
    - New: In ConfigurationWidget, the Apply button is now outside the
        tabs. Also adds two modes: Embedded & StandAlone with different sets
        of buttons.
This commit is contained in:
Jean-Paul Chaput 2010-09-15 21:46:42 +00:00
parent 868e3788fb
commit c5427574a8
10 changed files with 389 additions and 103 deletions

View File

@ -39,7 +39,7 @@ namespace Cfg {
ConfEditorWidget::ConfEditorWidget ( QWidget* parent ) ConfEditorWidget::ConfEditorWidget ( QWidget* parent )
: QMainWindow (parent) : QMainWindow (parent)
, _configurationWidget (Configuration::get()->buildWidget()) , _configurationWidget (Configuration::get()->buildWidget(ConfigurationWidget::StandAlone))
, _fileMenu (NULL) , _fileMenu (NULL)
, _saveAction (NULL) , _saveAction (NULL)
, _quitAction (NULL) , _quitAction (NULL)
@ -90,7 +90,7 @@ namespace Cfg {
cout << "Saving configuration file: <" << dotConfigFile << ">."<< endl; cout << "Saving configuration file: <" << dotConfigFile << ">."<< endl;
Configuration::get()->writeToStream ( file ); Configuration::get()->writeToStream ( file, Configuration::DriveValues|Configuration::DriveLayout );
file.close (); file.close ();
} }

View File

@ -29,7 +29,6 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QGridLayout> #include <QGridLayout>
#include <QPushButton>
#include <QApplication> #include <QApplication>
#include "vlsisapd/configuration/Configuration.h" #include "vlsisapd/configuration/Configuration.h"
@ -62,22 +61,10 @@ namespace Cfg {
setObjectName ( name.c_str() ); setObjectName ( name.c_str() );
QVBoxLayout* vLayout = new QVBoxLayout (); QVBoxLayout* vLayout = new QVBoxLayout ();
vLayout->addLayout ( _gridLayout ); vLayout->addLayout ( _gridLayout );
QHBoxLayout* hLayout = new QHBoxLayout ();
hLayout->addStretch ();
QPushButton* apply = new QPushButton ();
apply->setText ( tr("Apply") );
hLayout->addWidget ( apply );
hLayout->addStretch ();
vLayout->addLayout ( hLayout );
vLayout->addStretch (); vLayout->addStretch ();
setLayout ( vLayout ); setLayout ( vLayout );
connect ( apply, SIGNAL(clicked()), this, SIGNAL(updateParameters()) );
} }
@ -157,7 +144,11 @@ namespace Cfg {
} }
ParameterWidget* ConfTabWidget::addParameter ( Parameter* parameter, const std::string& label, int column, int flags ) ParameterWidget* ConfTabWidget::addParameter ( Parameter* parameter
, const std::string& label
, int column
, int span
, int flags )
{ {
ConfigurationWidget* cw = rparent<ConfigurationWidget*> ( this ); ConfigurationWidget* cw = rparent<ConfigurationWidget*> ( this );
ParameterWidget* pw = cw->find(parameter); ParameterWidget* pw = cw->find(parameter);
@ -173,15 +164,23 @@ namespace Cfg {
if ( column < 0 ) column = 0; if ( column < 0 ) column = 0;
else column = _columns-1; else column = _columns-1;
} }
if ( span < 0 ) span = 1;
if ( (column+span > _columns) ) span = _columns - column;
if ( span > 1 ) _alignMaxRowCount ();
int qspan = 2*span-1;
//cerr << parameter->getId() << " span:" << span << " " << qspan << endl;
pw = new ParameterWidget ( this, parameter, label, flags ); pw = new ParameterWidget ( this, parameter, label, flags );
_gridLayout->addWidget ( pw->getLabelWidget(), row, column*2, Qt::AlignRight ); _gridLayout->addWidget ( pw->getLabelWidget(), row, column*2 , Qt::AlignRight );
_gridLayout->addWidget ( pw->getValueWidget(), row, 1+column*2, Qt::AlignLeft ); _gridLayout->addWidget ( pw->getValueWidget(), row, column*2+1, 1, qspan, Qt::AlignLeft );
connect ( this, SIGNAL(updateParameters()), pw, SLOT(updateValue()) ); connect ( this, SIGNAL(updateParameters()), pw, SLOT(updateValue()) );
_rowsCount[column]++; _rowsCount[column]++;
if ( span > 1 ) _alignMaxRowCount ();
return pw; return pw;
} }

View File

@ -24,7 +24,9 @@
#include <sstream> #include <sstream>
#include <fstream>
#include <iomanip> #include <iomanip>
#include <vector>
#include <libxml/xmlreader.h> #include <libxml/xmlreader.h>
#include "vlsisapd/configuration/Configuration.h" #include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/ConfigurationWidget.h" #include "vlsisapd/configuration/ConfigurationWidget.h"
@ -62,14 +64,14 @@ namespace {
}; };
XmlParser::XmlParser ( Configuration* conf XmlParser::XmlParser ( Configuration* conf
, const string& fileName ) , const string& fileName )
: _configuration (conf) : _configuration(conf)
, _fileName (fileName) , _fileName (fileName)
, _reader (NULL) , _reader (NULL)
, _status (1) , _status (1)
, _tool ("<none>") , _tool ("<none>")
, _parameter (NULL) , _parameter (NULL)
{ } { }
@ -275,6 +277,7 @@ namespace {
string attrType = _getAttributeValue("type"); string attrType = _getAttributeValue("type");
string attrLabel = _getAttributeValue("label"); string attrLabel = _getAttributeValue("label");
string attrColumn = _getAttributeValue("column"); string attrColumn = _getAttributeValue("column");
string attrSpan = _getAttributeValue("span");
string attrSpinBox = _getAttributeValue("spinbox"); string attrSpinBox = _getAttributeValue("spinbox");
if ( attrId.empty() and attrType.empty() ) { if ( attrId.empty() and attrType.empty() ) {
@ -287,6 +290,11 @@ namespace {
istringstream s ( attrColumn ); s >> column; istringstream s ( attrColumn ); s >> column;
} }
int span = 1;
if ( not attrSpan.empty() ) {
istringstream s ( attrSpan ); s >> span;
}
if ( not attrType.empty() ) { if ( not attrType.empty() ) {
if ( attrType == "title" ) _configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::title (attrLabel) ); if ( attrType == "title" ) _configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::title (attrLabel) );
if ( attrType == "section" ) _configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::section(attrLabel,column) ); if ( attrType == "section" ) _configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::section(attrLabel,column) );
@ -303,7 +311,7 @@ namespace {
int flags = 0; int flags = 0;
if ( attrSpinBox == "true" ) flags |= ParameterWidget::UseSpinBox; if ( attrSpinBox == "true" ) flags |= ParameterWidget::UseSpinBox;
_configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::parameter(attrId,attrLabel,column,flags) ); _configuration->getLayout().getBackTab()->addWidget ( WidgetDescription::parameter(attrId,attrLabel,column,span,flags) );
} }
@ -328,7 +336,9 @@ namespace Cfg {
using std::string; using std::string;
using std::map; using std::map;
using std::ostream; using std::ostream;
using std::ofstream;
using std::setw; using std::setw;
using std::vector;
Configuration* Configuration::_singleton = NULL; Configuration* Configuration::_singleton = NULL;
@ -347,8 +357,8 @@ namespace Cfg {
{ } { }
ConfigurationWidget* Configuration::buildWidget () ConfigurationWidget* Configuration::buildWidget ( unsigned int flags )
{ return _layout.buildWidget(); } { return _layout.buildWidget(flags); }
Parameter* Configuration::getParameter ( const string& name, Parameter::Type type ) const Parameter* Configuration::getParameter ( const string& name, Parameter::Type type ) const
@ -424,7 +434,19 @@ namespace Cfg {
} }
void Configuration::writeToStream ( ostream& out ) const bool Configuration::writeToFile ( const std::string& fileName, unsigned int flags ) const
{
ofstream out ( fileName.c_str() );
if ( out.fail() ) return false;
writeToStream ( out, flags );
out.close ();
return true;
}
void Configuration::writeToStream ( ostream& out, unsigned int flags ) const
{ {
out << "<configuration>" << endl; out << "<configuration>" << endl;
@ -435,7 +457,6 @@ namespace Cfg {
string id = "\"" + p->getId() + "\""; string id = "\"" + p->getId() + "\"";
string type = "\"" + Parameter::typeToString(p->getType()) + "\""; string type = "\"" + Parameter::typeToString(p->getType()) + "\"";
out << " <parameter" out << " <parameter"
<< " id=" << setw(40) << left << id << " id=" << setw(40) << left << id
<< " type=" << setw(12) << left << type << " type=" << setw(12) << left << type
@ -443,18 +464,59 @@ namespace Cfg {
if ( p->getType() == Parameter::Percentage ) out << p->asPercentage(); if ( p->getType() == Parameter::Percentage ) out << p->asPercentage();
else out << p->asString(); else out << p->asString();
out << "\"";
out << "\"/>" << endl; 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() << "\"";
} 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 ( (flags&DriveValues) and (p->getType() == Parameter::Enumerate) ) {
out << ">" << endl;
const std::vector<Parameter::EnumValue>& values = p->getValues();
for ( size_t ivalue=0 ; ivalue<values.size() ; ++ivalue ) {
out << " <item label=\"" << values[ivalue]._label << "\" "
<< "value=\"" << values[ivalue]._value << "\"/>" << endl;
}
out << " </parameter>" << endl;
} else
out << "/>" << endl;
} }
if ( flags & DriveValues ) {
for ( iparameter = _parameters.begin(); iparameter != _parameters.end(); ++iparameter ) {
Parameter* p = iparameter->second;
const vector<string>& slaves = p->getSlaves();
if ( slaves.empty() ) continue;
out << " <group>" << endl;
out << " <master id=\"" << p->getId() << "\"/>" << endl;
for ( size_t islave=0 ; islave<slaves.size() ; ++islave ) {
out << " <slave id=\"" << slaves[islave] << "\"/>" << endl;
}
out << " </group>" << endl;
}
}
if ( flags & DriveLayout ) _layout.writeToStream ( out );
out << "</configuration>" << endl; out << "</configuration>" << endl;
} }
void Configuration::readFromFile ( const std::string& fileName ) bool Configuration::readFromFile ( const std::string& fileName )
{ {
XmlParser parser ( this, fileName ); XmlParser parser ( this, fileName );
parser.parse (); return parser.parse ();
} }

View File

@ -23,8 +23,14 @@
// x-----------------------------------------------------------------x // x-----------------------------------------------------------------x
#include <string>
#include <vector>
#include <map> #include <map>
#include <QApplication> #include <QApplication>
#include <QTabWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "vlsisapd/configuration/Configuration.h" #include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/ParameterWidget.h" #include "vlsisapd/configuration/ParameterWidget.h"
@ -39,19 +45,54 @@ namespace Cfg {
using std::endl; using std::endl;
using std::string; using std::string;
using std::map; using std::map;
using std::pair;
using std::make_pair;
using std::vector;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Class : "Cfg::ConfigurationWidget". // Class : "Cfg::ConfigurationWidget".
ConfigurationWidget::ConfigurationWidget ( QWidget* parent ) ConfigurationWidget::ConfigurationWidget ( unsigned int flags, QWidget* parent )
: QTabWidget(parent) : QWidget (parent)
, _flags (flags)
, _boldFont (QApplication::font()) , _boldFont (QApplication::font())
, _tabWidget(new QTabWidget())
, _apply (new QPushButton())
, _save (NULL)
, _cancel (NULL)
{ {
_boldFont.setBold ( true ); _boldFont.setBold ( true );
setAttribute ( Qt::WA_QuitOnClose, false ); setAttribute ( Qt::WA_QuitOnClose, false );
QVBoxLayout* vLayout = new QVBoxLayout ();
vLayout->addWidget ( _tabWidget );
QHBoxLayout* hLayout = new QHBoxLayout ();
hLayout->addStretch ();
_apply->setText ( tr( (_flags&Embedded)?"Apply":"OK") );
hLayout->addWidget ( _apply );
hLayout->addStretch ();
if ( _flags & StandAlone ) {
_save = new QPushButton ();
_save->setText ( tr("Save") );
hLayout->addWidget ( _save );
hLayout->addStretch ();
_cancel = new QPushButton ();
_cancel->setText ( tr("Cancel") );
hLayout->addWidget ( _cancel );
hLayout->addStretch ();
}
vLayout->addLayout ( hLayout );
vLayout->addStretch ();
setLayout ( vLayout );
} }
@ -84,6 +125,7 @@ namespace Cfg {
, Parameter* parameter , Parameter* parameter
, const std::string& label , const std::string& label
, int column , int column
, int span
, int flags ) , int flags )
{ {
ParameterWidget* pw = find(parameter); ParameterWidget* pw = find(parameter);
@ -93,7 +135,7 @@ namespace Cfg {
} }
ConfTabWidget* tab = findOrCreate ( tabName ); ConfTabWidget* tab = findOrCreate ( tabName );
return tab->addParameter ( parameter, label, column, flags ); return tab->addParameter ( parameter, label, column, span, flags );
} }
@ -114,7 +156,9 @@ namespace Cfg {
if ( tab != NULL ) return tab; if ( tab != NULL ) return tab;
tab = new ConfTabWidget ( tabName ); tab = new ConfTabWidget ( tabName );
addTab ( tab, tabName.c_str() ); _tabWidget->addTab ( tab, tabName.c_str() );
connect ( _apply, SIGNAL(clicked()), tab, SIGNAL(updateParameters()) );
return tab; return tab;
} }
@ -134,6 +178,40 @@ namespace Cfg {
pw->enableSlaves ( pw->getParameter()->asBool() ); pw->enableSlaves ( pw->getParameter()->asBool() );
} }
} }
string toXml ( const string& source )
{
static vector< pair<string,string> > translations;
if ( translations.empty() ) {
translations.push_back ( make_pair("&","&amp;") );
translations.push_back ( make_pair("<","&lt;") );
translations.push_back ( make_pair(">","&gt;") );
}
string translated = source;
for ( size_t pos=0 ; pos<translated.size() ; ) {
bool match = false;
for ( size_t i=0 ; i<translations.size() ; ++i ) {
const string& original = translations[i].first;
const string& translation = translations[i].second;
if ( translated.compare(pos,original.size(),original) == 0 ) {
translated.replace(pos,original.size(),translation);
pos += translation.size();
match = true;
break;
}
}
pos += (match) ? 0 : 1;
}
return translated;
}
} // End of Cfg namespace. } // End of Cfg namespace.

View File

@ -25,54 +25,146 @@
#include "vlsisapd/configuration/LayoutDescription.h" #include "vlsisapd/configuration/LayoutDescription.h"
#include "vlsisapd/configuration/Configuration.h" #include "vlsisapd/configuration/Configuration.h"
#include "vlsisapd/configuration/ParameterWidget.h"
#include "vlsisapd/configuration/ConfigurationWidget.h" #include "vlsisapd/configuration/ConfigurationWidget.h"
namespace Cfg { namespace Cfg {
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
using std::ostream;
ConfigurationWidget* LayoutDescription::buildWidget () TabDescription* LayoutDescription::getTab ( const string& tabName )
{ {
ConfigurationWidget* cw = new ConfigurationWidget (); for ( size_t itab=0 ; itab<_tabs.size() ; ++itab ) {
if ( _tabs[itab]->getName() == tabName ) return _tabs[itab];
}
for ( size_t itab=0 ; itab<_tabs.size() ; ++itab ) { addTab ( new TabDescription(tabName) );
const vector<WidgetDescription*> widgets = _tabs[itab]->getWidgets(); return getBackTab();
}
for ( size_t iwidget=0 ; iwidget<widgets.size() ; ++iwidget ) { void LayoutDescription::addRule ( const string& tabName )
switch ( widgets[iwidget]->getType() ) { {
case WidgetDescription::Rule: TabDescription* tab = getTab ( tabName );
cw->addRuler ( _tabs[itab]->getName() ); tab->addWidget ( WidgetDescription::rule() );
break; }
case WidgetDescription::Title:
cw->addTitle ( _tabs[itab]->getName()
, widgets[iwidget]->getTitle() ); void LayoutDescription::addTitle ( const string& tabName, const string& title )
break; {
case WidgetDescription::Section: TabDescription* tab = getTab ( tabName );
cw->addSection ( _tabs[itab]->getName() tab->addWidget ( WidgetDescription::title(title) );
, widgets[iwidget]->getTitle() }
, widgets[iwidget]->getColumn() );
break;
case WidgetDescription::Parameter: void LayoutDescription::addSection ( const string& tabName, const string& section, int column )
Parameter* parameter = _configuration->getParameter ( widgets[iwidget]->getId() ); {
cw->addParameter ( _tabs[itab]->getName() TabDescription* tab = getTab ( tabName );
, parameter tab->addWidget ( WidgetDescription::section(section,column) );
, widgets[iwidget]->getLabel() }
, widgets[iwidget]->getColumn()
, widgets[iwidget]->getFlags() );
break; void LayoutDescription::addParameter ( const string& tabName
} , const string& id
, const string& label
, int column
, int span
, unsigned int flags )
{
TabDescription* tab = getTab ( tabName );
tab->addWidget ( WidgetDescription::parameter(id,label,column,span,flags) );
}
ConfigurationWidget* LayoutDescription::buildWidget ( unsigned int flags )
{
ConfigurationWidget* cw = new ConfigurationWidget ( flags );
for ( size_t itab=0 ; itab<_tabs.size() ; ++itab ) {
const vector<WidgetDescription*> widgets = _tabs[itab]->getWidgets();
for ( size_t iwidget=0 ; iwidget<widgets.size() ; ++iwidget ) {
switch ( widgets[iwidget]->getType() ) {
case WidgetDescription::Rule:
cw->addRuler ( _tabs[itab]->getName() );
break;
case WidgetDescription::Title:
cw->addTitle ( _tabs[itab]->getName()
, widgets[iwidget]->getLabel() );
break;
case WidgetDescription::Section:
cw->addSection ( _tabs[itab]->getName()
, widgets[iwidget]->getLabel()
, widgets[iwidget]->getColumn() );
break;
case WidgetDescription::Parameter:
Parameter* parameter = _configuration->getParameter ( widgets[iwidget]->getId() );
cw->addParameter ( _tabs[itab]->getName()
, parameter
, widgets[iwidget]->getLabel()
, widgets[iwidget]->getColumn()
, widgets[iwidget]->getSpan()
, widgets[iwidget]->getFlags() );
break;
} }
} }
cw->syncSlaves ();
return cw;
} }
cw->syncSlaves ();
return cw;
}
void LayoutDescription::writeToStream ( ostream& out ) const
{
out << " <layout>" << endl;
for ( size_t itab=0 ; itab<_tabs.size() ; ++itab ) {
out << " <tab name=\"" << _tabs[itab]->getName() << "\">" << endl;
const vector<WidgetDescription*>& widgets = _tabs[itab]->getWidgets();
for ( size_t iwidget=0 ; iwidget<widgets.size() ; ++iwidget ) {
WidgetDescription* widget = widgets[iwidget];
out << " <widget ";
switch ( widget->getType() ) {
case WidgetDescription::Rule:
out << "type=\"rule\"";
break;
case WidgetDescription::Title:
out << "type=\"title\" label=\"" << toXml(widget->getLabel()) << "\"";
break;
case WidgetDescription::Section:
out << "type=\"section\""
<< " label=\"" << widget->getLabel() << "\""
<< " column=\"" << widget->getColumn() << "\"";
break;
case WidgetDescription::Parameter:
out << " id=\"" << widget->getId() << "\""
<< " label=\"" << widget->getLabel() << "\""
<< " column=\"" << widget->getColumn() << "\"";
if ( widget->getSpan() != 1 ) out << " span=\"" << widget->getSpan() << "\"";
if ( widget->getFlags() & ParameterWidget::UseSpinBox ) out << " spinbox=\"true\"";
break;
}
out << "/>" << endl;
}
out << " </tab>" << endl;
}
out << " </layout>" << endl;
}
} // End of Cfg namespace. } // End of Cfg namespace.

View File

@ -63,6 +63,8 @@ namespace Cfg {
case Parameter::String: case Parameter::String:
{ {
QLineEdit* lineEdit = new QLineEdit(); QLineEdit* lineEdit = new QLineEdit();
lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Fixed );
lineEdit->setMinimumWidth ( 375 );
lineEdit->setText ( QString("%1").arg(_parameter->asString().c_str()) ); lineEdit->setText ( QString("%1").arg(_parameter->asString().c_str()) );
_valueWidget = lineEdit; _valueWidget = lineEdit;
} }
@ -151,6 +153,7 @@ namespace Cfg {
int currentValue = _parameter->asInt(); int currentValue = _parameter->asInt();
int currentIndex = 0; int currentIndex = 0;
QComboBox* comboBox = new QComboBox(); QComboBox* comboBox = new QComboBox();
//comboBox->setSizePolicy ( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
const vector<Parameter::EnumValue>& values = _parameter->getValues(); const vector<Parameter::EnumValue>& values = _parameter->getValues();
for ( size_t i=0 ; i != values.size() ; ++i ) { for ( size_t i=0 ; i != values.size() ; ++i ) {
comboBox->addItem ( values[i]._label.c_str(), values[i]._value ); comboBox->addItem ( values[i]._label.c_str(), values[i]._value );

View File

@ -52,7 +52,7 @@ namespace Cfg {
void addRuler (); void addRuler ();
void addTitle ( const std::string& title ); void addTitle ( const std::string& title );
void addSection ( const std::string& section, int column=0 ); void addSection ( const std::string& section, int column=0 );
ParameterWidget* addParameter ( Parameter*, const std::string& label, int column=0, int flags=0 ); ParameterWidget* addParameter ( Parameter*, const std::string& label, int column=0, int span=1, int flags=0 );
signals: signals:
void updateParameters (); void updateParameters ();
private: private:
@ -61,6 +61,7 @@ namespace Cfg {
private: private:
QGridLayout* _gridLayout; QGridLayout* _gridLayout;
int _columns; int _columns;
int _span;
int* _rowsCount; int* _rowsCount;
std::vector<ParameterWidget*> _parameters; std::vector<ParameterWidget*> _parameters;
}; };

View File

@ -39,11 +39,13 @@ namespace Cfg {
class Configuration { class Configuration {
public:
enum Flags { DriveValues=0x1, DriveLayout=0x2 };
public: public:
static Configuration* get (); static Configuration* get ();
public: public:
// Methods. // Methods.
ConfigurationWidget* buildWidget (); ConfigurationWidget* buildWidget ( unsigned int flags );
inline const std::map<const std::string,Parameter*>& inline const std::map<const std::string,Parameter*>&
getParameters () const; getParameters () const;
inline const LayoutDescription& getLayout () const; inline const LayoutDescription& getLayout () const;
@ -54,8 +56,9 @@ namespace Cfg {
, Parameter::Type type , Parameter::Type type
, const std::string& value ); , const std::string& value );
void print ( std::ostream& ) const; void print ( std::ostream& ) const;
void readFromFile ( const std::string& ); bool readFromFile ( const std::string& );
void writeToStream ( std::ostream& ) const; bool writeToFile ( const std::string&, unsigned int flags ) const;
void writeToStream ( std::ostream&, unsigned int flags ) const;
private: private:
// Attributes. // Attributes.
static Configuration* _singleton; static Configuration* _singleton;

View File

@ -27,9 +27,10 @@
#ifndef __CFG_CONFIGURATION_WIDGET__ #ifndef __CFG_CONFIGURATION_WIDGET__
#define __CFG_CONFIGURATION_WIDGET__ #define __CFG_CONFIGURATION_WIDGET__
//#include <map>
#include <QFont> #include <QFont>
#include <QTabWidget> #include <QWidget>
class QPushButton;
class QTabWidget;
namespace Cfg { namespace Cfg {
@ -44,25 +45,48 @@ namespace Cfg {
// Class : "Cfg::ConfigurationWidget". // Class : "Cfg::ConfigurationWidget".
class ConfigurationWidget : public QTabWidget { class ConfigurationWidget : public QWidget {
Q_OBJECT; Q_OBJECT;
public: public:
ConfigurationWidget ( QWidget* parent=NULL ); enum Flags { Embedded=0x1, StandAlone=0x2 };
public:
ConfigurationWidget ( unsigned int flags, QWidget* parent=NULL );
public: public:
QFont& getBoldFont (); QFont& getBoldFont ();
ParameterWidget* find ( Parameter* ) const; inline QPushButton* getApplyButton ();
ParameterWidget* find ( const std::string& id ) const; inline QPushButton* getSaveButton ();
ConfTabWidget* findOrCreate ( const std::string& name ); inline QPushButton* getCancelButton ();
void addRuler ( const std::string& tabName ); ParameterWidget* find ( Parameter* ) const;
void addTitle ( const std::string& tabName, const std::string& title ); ParameterWidget* find ( const std::string& id ) const;
void addSection ( const std::string& tabName, const std::string& section, int column=0 ); ConfTabWidget* findOrCreate ( const std::string& name );
ParameterWidget* addParameter ( const std::string& tabName, Parameter*, const std::string& label, int column=0, int flags=0 ); void addRuler ( const std::string& tabName );
void syncSlaves (); void addTitle ( const std::string& tabName
, const std::string& title );
void addSection ( const std::string& tabName
, const std::string& section
, int column=0 );
ParameterWidget* addParameter ( const std::string& tabName
, Parameter*
, const std::string& label
, int column=0
, int span =1
, int flags =0 );
void syncSlaves ();
private: private:
QFont _boldFont; unsigned int _flags;
QFont _boldFont;
QTabWidget* _tabWidget;
QPushButton* _apply;
QPushButton* _save;
QPushButton* _cancel;
}; };
inline QPushButton* ConfigurationWidget::getApplyButton () { return _apply; }
inline QPushButton* ConfigurationWidget::getSaveButton () { return _save; }
inline QPushButton* ConfigurationWidget::getCancelButton () { return _cancel; }
// Functions Templates. // Functions Templates.
template<typename QTypeWidget> template<typename QTypeWidget>
QTypeWidget rparent ( QObject* object ) QTypeWidget rparent ( QObject* object )
@ -79,6 +103,10 @@ namespace Cfg {
} }
// Misc. Utility.
std::string toXml ( const std::string& );
} // End of Cfg namespace. } // End of Cfg namespace.

View File

@ -29,6 +29,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream>
namespace Cfg { namespace Cfg {
@ -51,26 +52,29 @@ namespace Cfg {
inline static WidgetDescription* parameter ( const std::string& id inline static WidgetDescription* parameter ( const std::string& id
, const std::string& label , const std::string& label
, int column , int column
, int span
, int flags , int flags
); );
inline Type getType () const; inline Type getType () const;
inline const std::string& getId () const; inline const std::string& getId () const;
inline const std::string& getLabel () const; inline const std::string& getLabel () const;
inline const std::string& getTitle () const;
inline int getColumn () const; inline int getColumn () const;
inline int getSpan () const;
inline int getFlags () const; inline int getFlags () const;
private: private:
Type _type; Type _type;
std::string _id; // Alternate id, title or section. std::string _id; // Note: title, section & rule have no id.
std::string _label; std::string _label;
int _column; int _column;
int _span;
int _flags; int _flags;
private: private:
inline WidgetDescription ( Type type inline WidgetDescription ( Type type
, const std::string& id ="<none>" , const std::string& id ="<none>"
, const std::string& label ="<none>" , const std::string& label ="<none>"
, int column=0 , int column=0
, int flags=0 , int span =1
, int flags =0
); );
}; };
@ -80,31 +84,33 @@ namespace Cfg {
, const std::string& id , const std::string& id
, const std::string& label , const std::string& label
, int column , int column
, int span
, int flags ) , int flags )
: _type(type), _id(id), _label(label), _column(column), _flags(flags) : _type(type), _id(id), _label(label), _column(column), _span(span), _flags(flags)
{ } { }
inline WidgetDescription* WidgetDescription::rule () inline WidgetDescription* WidgetDescription::rule ()
{ return new WidgetDescription(Rule); } { return new WidgetDescription(Rule); }
inline WidgetDescription* WidgetDescription::title ( const std::string& title ) inline WidgetDescription* WidgetDescription::title ( const std::string& title )
{ return new WidgetDescription(Title,title); } { return new WidgetDescription(Title,"<none>",title); }
inline WidgetDescription* WidgetDescription::section ( const std::string& title, int column ) inline WidgetDescription* WidgetDescription::section ( const std::string& section, int column )
{ return new WidgetDescription(Section,title,"<none>",column); } { return new WidgetDescription(Section,"<none>",section,column); }
inline WidgetDescription* WidgetDescription::parameter ( const std::string& id inline WidgetDescription* WidgetDescription::parameter ( const std::string& id
, const std::string& label , const std::string& label
, int column , int column
, int span
, int flags , int flags
) )
{ return new WidgetDescription(Parameter,id,label,column,flags); } { return new WidgetDescription(Parameter,id,label,column,span,flags); }
inline WidgetDescription::Type WidgetDescription::getType () const { return _type; } inline WidgetDescription::Type WidgetDescription::getType () const { return _type; }
inline const std::string& WidgetDescription::getId () const { return _id; } inline const std::string& WidgetDescription::getId () const { return _id; }
inline const std::string& WidgetDescription::getLabel () const { return _label; } inline const std::string& WidgetDescription::getLabel () const { return _label; }
inline const std::string& WidgetDescription::getTitle () const { return _id; }
inline int WidgetDescription::getColumn () const { return _column; } inline int WidgetDescription::getColumn () const { return _column; }
inline int WidgetDescription::getSpan () const { return _span; }
inline int WidgetDescription::getFlags () const { return _flags; } inline int WidgetDescription::getFlags () const { return _flags; }
@ -148,8 +154,22 @@ namespace Cfg {
inline LayoutDescription ( Configuration* ); inline LayoutDescription ( Configuration* );
inline void addTab ( TabDescription* ); inline void addTab ( TabDescription* );
inline TabDescription* getBackTab (); inline TabDescription* getBackTab ();
TabDescription* getTab ( const std::string& tabName );
inline const std::vector<TabDescription*>& getTabs () const; inline const std::vector<TabDescription*>& getTabs () const;
ConfigurationWidget* buildWidget (); void addRule ( const std::string& tabName );
void addTitle ( const std::string& tabName
, const std::string& title );
void addSection ( const std::string& tabName
, const std::string& section
, int column=0 );
void addParameter ( const std::string& tabName
, const std::string& id
, const std::string& label
, int column=0
, int span =1
, unsigned int flags =0 );
ConfigurationWidget* buildWidget ( unsigned int flags );
void writeToStream ( std::ostream& ) const;
private: private:
Configuration* _configuration; Configuration* _configuration;
std::vector<TabDescription*> _tabs; std::vector<TabDescription*> _tabs;