From c89cdfef71c1ff2268112d7eacec656e11e9d08d Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sat, 9 Aug 2025 07:45:32 +0200 Subject: [PATCH] cleanups. --- src/items/xqitem.cpp | 40 ++++++++++++++++++++++++++++--------- src/items/xqitemfactory.cpp | 2 ++ src/items/xqitemtype.cpp | 9 +++++++-- src/items/xqitemtype.h | 1 - xml/modelsheets.xml | 30 ++++++++++++++-------------- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/items/xqitem.cpp b/src/items/xqitem.cpp index ecacfed..aae05b6 100644 --- a/src/items/xqitem.cpp +++ b/src/items/xqitem.cpp @@ -304,9 +304,7 @@ QString XQItem::editorTypeToString() const void XQItem::setEditorType(EditorType editorType) { - setData( QVariant::fromValue(editorType), XQItem::EditorTypeRole); - // Der EditorType wohnt im ItemType - //itemType().replaceAttribute( this, EditorTypeRole, editorType ); + setData( QVariant::fromValue(editorType), XQItem::EditorTypeRole); } @@ -453,7 +451,6 @@ QVariant XQItem::data(int role ) const case IconRole: // aka Qt::DecorationRole, case RenderStyleRole: case EditorTypeRole: - case UnitTypeRole: case ContentFormatRole: case FixedChoicesRole: { @@ -485,7 +482,7 @@ QVariant XQItem::data(int role ) const case Qt::ToolTipRole: { - return content() + ":" + itemType().text() + ":" + renderStyleToString(); + return content() + ":" + itemType().text() + ":" + renderStyleToString() + ":" + unitTypeToString(); } // @@ -507,11 +504,12 @@ QVariant XQItem::data(int role ) const return firstItem.data( XQItem::ContentNodeRole ); } + case UnitTypeRole: + case Qt::StatusTipRole: case Qt::WhatsThisRole: case Qt::SizeHintRole: - case Qt::FontRole: case Qt::TextAlignmentRole: case Qt::BackgroundRole: @@ -556,7 +554,6 @@ void XQItem::setData(const QVariant& value, int role ) case RenderStyleRole : case EditorTypeRole : - case UnitTypeRole: case ContentFormatRole: case FlagsRole: // Stimmt das? case IconRole: @@ -574,7 +571,7 @@ void XQItem::setData(const QVariant& value, int role ) case ContentRole: { // what will happen? value is a string ptr ?! - qDebug() << " --- setting content: " << value.toString(); + //qDebug() << " --- setting content: " << value.toString(); // string ptr setzen kann die basis. break; return; @@ -596,6 +593,8 @@ void XQItem::setData(const QVariant& value, int role ) } // alles andere wie gehabt + case UnitTypeRole: + case ContentNodeRole: case SheetNodeRole: @@ -610,12 +609,17 @@ void XQItem::setData(const QVariant& value, int role ) } +//! gibt ein statisches invalid-item zurück, anstelle von nullptr + XQItem& XQItem::fallBackDummyItem() { static XQItem s_fallBackDummyItem; return s_fallBackDummyItem; } + +//! gibt das item für den gegebenen index aus. + XQItem& XQItem::xqItemFromIndex(const QModelIndex& index) { if (index.isValid()) @@ -624,10 +628,12 @@ XQItem& XQItem::xqItemFromIndex(const QModelIndex& index) if (mdl) return mdl->xqItemFromIndex(index); } - return fallBackDummyItem(); } + +//! gibt den enum-type für den gegebenen datarole-key aus. + int XQItem::fetchItemDataRole( const QString& dataRoleKey ) { if(!dataRoleKey.isEmpty() && s_ItemDataRoleMap.contains(dataRoleKey) ) @@ -637,12 +643,16 @@ int XQItem::fetchItemDataRole( const QString& dataRoleKey ) } +//! gibt die bezeichung für die gegebene datarole aus. + QString XQItem::fetchItemDataRoleName( int dataRole ) { return s_ItemDataRoleMap.key(dataRole); } +//! gibt das flag für den gegebenen itemflag-key aus. + Qt::ItemFlag XQItem::fetchItemFlag( const QString& flagKey ) { if(!flagKey.isEmpty() && s_ItemFlagMap.contains(flagKey) ) @@ -650,6 +660,7 @@ Qt::ItemFlag XQItem::fetchItemFlag( const QString& flagKey ) return Qt::NoItemFlags; } +//! gibt die bezeichung für das gegebene itemFlag aus. QString XQItem::fetchItemFlagName( int flag ) { @@ -657,6 +668,8 @@ QString XQItem::fetchItemFlagName( int flag ) } +//! gibt den enum-type für den gegebenen renderStyle-key aus. + XQItem::RenderStyle XQItem::fetchRenderStyle(const QString& styleKey ) { if(!styleKey.isEmpty() && s_RenderStyleMap.contains(styleKey) ) @@ -665,12 +678,16 @@ XQItem::RenderStyle XQItem::fetchRenderStyle(const QString& styleKey ) } +//! gibt die bezeichung für den gegebenen renderStyle aus. + QString XQItem::fetchRenderStyleToString(XQItem::RenderStyle renderStyle ) { return s_RenderStyleMap.key(renderStyle); } +//! gibt den renderstyle enum-type für den gegebenen editorType-key aus. + XQItem::EditorType XQItem::fetchEditorType( const QString& editorTypeKey ) { if(!editorTypeKey.isEmpty() && s_EditorTypeMap.contains(editorTypeKey) ) @@ -679,17 +696,22 @@ XQItem::EditorType XQItem::fetchEditorType( const QString& editorTypeKey ) } +//! gibt die bezeichung für den gegebenen editorType aus. + QString XQItem::fetchEditorTypeToString( EditorType editorType ) { return s_EditorTypeMap.key(editorType); } +//! gibt den unitType für den gegebenen unitType-key aus. + XQItem::UnitType XQItem::fetchUnitType(const QString& unitTypeKey) { return s_UnitTypeMap.key(unitTypeKey); } +//! gibt die bezeichung für den gegebenen unitType aus. QString XQItem::fetchUnitTypeToString( UnitType unitType) { diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index bd0ab4d..d4529e7 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -28,6 +28,7 @@ void XQItemFactory::initItemFactory( const QString& modelSheetFileName ) // über alle attribute for( const auto& [key,value] : sheetNode->attributes() ) { + qDebug() << " --- conf: " << key << " : " << value; setItemDataFromString( *itemType, key, value ); } }; @@ -168,6 +169,7 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const case XQItem::UnitTypeRole: { + qDebug() << " --- make unit type: " << source; XQItem::UnitType unitType = XQItem::fetchUnitType( source ); value = QVariant::fromValue(unitType); break; diff --git a/src/items/xqitemtype.cpp b/src/items/xqitemtype.cpp index 370f10f..7231769 100644 --- a/src/items/xqitemtype.cpp +++ b/src/items/xqitemtype.cpp @@ -63,8 +63,9 @@ QVariant XQItemType::data( int role ) const //! ruft QStandardItem::setData auf -void XQItemType::setData(const QVariant &value, int role ) +void XQItemType::setData(const QVariant& value, int role ) { + qDebug() << " --- itemType set Data:" << role << " : " << value.toString(); return QStandardItem::setData(value,role); } @@ -104,7 +105,11 @@ void XQItemType::replaceAttribute( XQItem* item, const QVariant& newValue, int r QVariant XQItemType::formatText( const XQItem& item ) const { - return "type says:"+ item.content(); + XQItem::UnitType uType = unitType(); + const QString& cont = item.content(); + if( uType != XQItem::NoUnitType ) + return formatToSI( cont, uType ); + return cont; } //! firz diff --git a/src/items/xqitemtype.h b/src/items/xqitemtype.h index 37e14eb..ba37502 100644 --- a/src/items/xqitemtype.h +++ b/src/items/xqitemtype.h @@ -42,7 +42,6 @@ public: virtual QVariant formatText( const XQItem& item ) const; - // FIX! Das gehört hier nicht her! QString formatToSI(const QString& rawText, XQItem::UnitType unitType ) const; QString unFormatFromSI(const QString& valueText ) const; diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 9520e55..73a0d0d 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -10,7 +10,7 @@ - + @@ -31,7 +31,7 @@ @@ -40,32 +40,32 @@ - - - - - - + + + + + + - - + + - + - - - - + + + +