/** * @RDE_HEADER@ * $Id$ * $HeadURL$ * $Author$ */ #pragma once #include #include namespace SymbologyXML { // Um die Moeglichkeiten des typechecking zu nutzehn, erstellen wird die // folgende Klasse als template-class: template class AttributeData { protected: // enum -> internal String (XML-File) QMap enum2str; // internal String (XML-File)-> enum QMap str2enum; // enum -> external String (for translation) QMap enum2Tr; // Order to fill the ComboBox QVector order; public: void insert(const TYPE &enumKey, const QString &InternalString, const QString &ExternalString) { enum2str.insert(enumKey, InternalString); str2enum.insert(InternalString, enumKey); enum2Tr.insert(enumKey, ExternalString); order.push_back(enumKey); } QString convert_enum2str(const TYPE &enumKey) const { QString ret; if ( enum2str.contains(enumKey) ) { ret = enum2str[enumKey]; } else { ret = enum2str.value(*order.begin()); // == "FOO_UNDEFINED" } return ret; } QString convert_enum2tr(const TYPE &enumKey) const { QString ret; if ( enum2Tr.contains(enumKey) ) { ret = enum2Tr[enumKey]; } else { ret = enum2str.value(*order.begin()); // == "FOO_UNDEFINED" } return ret; } TYPE convert_str2enum(const QString& str_ref, bool* bOk = nullptr) const { TYPE ret = *order.begin(); // == FOO_UNDEFINED if ( str2enum.contains(str_ref) ) { ret = str2enum[str_ref]; if (bOk) *bOk = true; } else { if (bOk) *bOk = false; } return ret; } TYPE convert_str2enum(const QStringRef& str_ref, bool* bOk = nullptr) const { return convert_str2enum(str_ref.toString(), bOk); } void clear() { enum2str.clear(); str2enum.clear(); enum2Tr.clear(); order.clear(); } size_t size() const { return order.size(); } QMap getContainerAsInt() const { QMap retMap; QVectorIterator i(order); TYPE val; while (i.hasNext()) { val = i.next(); retMap.insert((int)val, convert_enum2tr(val)); } return retMap; } QVectorIterator getIterator() const { return order; } }; // Um die Moeglichkeiten des typechecking zu nutzen, erstellen wird die // folgende Klasse als template-class: template class AttributeDataSectorIcon : public AttributeData { protected: QVector orderSector1; QVector orderSector2; QVector orderSectorMain; QVector orderSectorMainComboBox; QVector orderSectorMainListView; QVector orderSectorFullFramed; public: size_t size() const = delete; void clear() { AttributeData::clear(); orderSector1.clear(); orderSector2.clear(); orderSectorMain.clear(); orderSectorMainComboBox.clear(); orderSectorMainListView.clear(); orderSectorFullFramed.clear(); } bool contains(const TYPE_SECTORICON &id, SymbolTypes::t_sector_position sectorPosition, SymbolTypes::t_select_widget selectWidget = SymbolTypes::SELECT_WIDGET_UNDEFINED) const { bool found = false; const QVector* cont_p = this->getContainer(sectorPosition, selectWidget); if (cont_p) { found = cont_p->contains(id); } return found; } void insert(const TYPE_SECTORICON &enumKey, const QString &InternalString, const QString &ExternalString, int sectorPositions, SymbolTypes::t_select_widget selectWidget = SymbolTypes::SELECT_WIDGET_UNDEFINED) { AttributeData::insert(enumKey, InternalString, ExternalString); if (sectorPositions & SymbolTypes::SECTOR1) this->orderSector1.push_back(enumKey); if (sectorPositions & SymbolTypes::SECTOR2) this->orderSector2.push_back(enumKey); if (sectorPositions & SymbolTypes::SECTORMAIN) { this->orderSectorMain.push_back(enumKey); switch (selectWidget) { case SymbolTypes::SELECT_WIDGET_UNDEFINED: { // empty } break; case SymbolTypes::SELECT_WIDGET_CB: this->orderSectorMainComboBox.push_back(enumKey); break; case SymbolTypes::SELECT_WIDGET_LV: this->orderSectorMainListView.push_back(enumKey); break; } // switch } // if if (sectorPositions & SymbolTypes::SECTORFF) this->orderSectorFullFramed.push_back(enumKey); }; const QVector* getContainer(SymbolTypes::t_sector_position sectorPosition, SymbolTypes::t_select_widget selectWidget = SymbolTypes::SELECT_WIDGET_UNDEFINED) const { const QVector* cont_p = nullptr; switch(sectorPosition) { case SymbolTypes::SECTOR1: cont_p = &orderSector1; break; case SymbolTypes::SECTOR2: cont_p = &orderSector2; break; case SymbolTypes::SECTORMAIN: { switch (selectWidget) { case SymbolTypes::SELECT_WIDGET_UNDEFINED: cont_p = &orderSectorMain; break; case SymbolTypes::SELECT_WIDGET_CB: cont_p = &orderSectorMainComboBox; break; case SymbolTypes::SELECT_WIDGET_LV: cont_p = &orderSectorMainListView; break; } // switch } break; case SymbolTypes::SECTORFF: cont_p = &orderSectorFullFramed; break; case SymbolTypes::SECTOR_POSITION_UNDEFINED: { // empty - avoiding compiler warning } } // switch return cont_p; } const QMap getContainerAsInt(SymbolTypes::t_sector_position sectorPosition, SymbolTypes::t_select_widget selectWidget = SymbolTypes::SELECT_WIDGET_UNDEFINED) const { QMap retMap; const QVector* cont_p = getContainer(sectorPosition, selectWidget); QVectorIterator iter(*cont_p); TYPE_SECTORICON val; while (iter.hasNext()) { val = iter.next(); retMap.insert((int)val, this->convert_enum2tr(val)); } return retMap; }; }; // AttributeDataSectorIcon }; // namespace SymbologyXML