|
| 1 | +#include "categorydefinition.h" |
| 2 | +#include "gslib/gslibparameterfiles/gslibparamtypes.h" |
| 3 | +#include "gslib/gslibparams/widgets/widgetgslibparmultivaluedfixed.h" |
| 4 | + |
| 5 | +CategoryDefinition::CategoryDefinition(QString path) : IntIntQStringTriplets ( path ) |
| 6 | +{ |
| 7 | +} |
| 8 | + |
| 9 | +CategoryDefinition::~CategoryDefinition() |
| 10 | +{ |
| 11 | + //TODO: delete the objects in m_createdParameters here. |
| 12 | +} |
| 13 | + |
| 14 | +void CategoryDefinition::save(QTextStream *txt_stream) |
| 15 | +{ |
| 16 | + (*txt_stream) << this->getFileType() << ":" << this->getFileName() << '\n'; |
| 17 | +} |
| 18 | + |
| 19 | +QWidget *CategoryDefinition::createContentElementWidget() |
| 20 | +{ |
| 21 | + //create a parameter set with default values to represent a triplet of code, color, name. |
| 22 | + GSLibParMultiValuedFixed* par = new GSLibParMultiValuedFixed("","",""); |
| 23 | + GSLibParInt *pint = new GSLibParInt("","",""); |
| 24 | + int num_cats = m_stashOfCreatedParameters.size() + 1; |
| 25 | + pint->_value = num_cats; |
| 26 | + par->_parameters.append( pint ); |
| 27 | + GSLibParColor *pcol = new GSLibParColor("","",""); |
| 28 | + pcol->_color_code = num_cats % 25; //max. color code is 24. |
| 29 | + par->_parameters.append( pcol ); |
| 30 | + GSLibParString *pstr = new GSLibParString("","",""); |
| 31 | + pstr->_value = QString("Category ") + QString::number( num_cats ); |
| 32 | + par->_parameters.append( pstr ); |
| 33 | + //store the pointer to delete some time later. |
| 34 | + m_stashOfCreatedParameters.append( par ); |
| 35 | + //return the widget tailored for the data types of the triplet. |
| 36 | + return par->getWidget(); |
| 37 | +} |
| 38 | + |
| 39 | +QWidget *CategoryDefinition::createWidgetFilledWithContentElement(uint iContent) |
| 40 | +{ |
| 41 | + //create a parameter set with the code, color and name values. |
| 42 | + GSLibParMultiValuedFixed* par = new GSLibParMultiValuedFixed("","",""); |
| 43 | + GSLibParInt *pint = new GSLibParInt("","",""); |
| 44 | + pint->_value = get1stValue( iContent ); // the category code |
| 45 | + par->_parameters.append( pint ); |
| 46 | + GSLibParColor *pcol = new GSLibParColor("","",""); |
| 47 | + pcol->_color_code = get2ndValue( iContent ); // the GSLib color code |
| 48 | + par->_parameters.append( pcol ); |
| 49 | + GSLibParString *pstr = new GSLibParString("","",""); |
| 50 | + pstr->_value = get3rdValue( iContent ); //the Category name |
| 51 | + par->_parameters.append( pstr ); |
| 52 | + //store the pointer to delete some time later. |
| 53 | + m_stashOfCreatedParameters.append( par ); |
| 54 | + //return the widget tailored for the data types of the triplet. |
| 55 | + return par->getWidget(); |
| 56 | +} |
| 57 | + |
| 58 | +void CategoryDefinition::addContentElementFromWidget(QWidget *w) |
| 59 | +{ |
| 60 | + //surely the widget is a WidgetGSLibParMultiValuedFixed. |
| 61 | + WidgetGSLibParMultiValuedFixed *widget = (WidgetGSLibParMultiValuedFixed*)w; |
| 62 | + |
| 63 | + //build a parameter set adequate to read the user-entered values in the passed widget. |
| 64 | + GSLibParMultiValuedFixed* par = new GSLibParMultiValuedFixed("","",""); |
| 65 | + par->_parameters.append( new GSLibParInt("","","") ); |
| 66 | + par->_parameters.append( new GSLibParColor("","","") ); |
| 67 | + par->_parameters.append( new GSLibParString("","","") ); |
| 68 | + |
| 69 | + //read the values from the widget into the parameter set object. |
| 70 | + widget->updateValue( par ); |
| 71 | + |
| 72 | + //add the triplet of the values read. |
| 73 | + addTriplet( ((GSLibParInt*)par->_parameters[0])->_value, |
| 74 | + ((GSLibParColor*)par->_parameters[1])->_color_code, |
| 75 | + ((GSLibParString*)par->_parameters[2])->_value ); |
| 76 | + |
| 77 | + //store the parameter set pointer to delete some time later. |
| 78 | + m_stashOfCreatedParameters.append( par ); |
| 79 | +} |
0 commit comments