diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index b599226..5b7b68c 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -81,8 +81,11 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) void XQMainModel::addSectionItem( const XQModelSection& section, XQItem* projectItem ) { + + qDebug() << " --- SUPPA0: " << section.contentType(); - qDebug() << " --- SUPPA1: -> " << projectItem->contentNode()->to_string(); + if( projectItem->hasContentNode()) + qDebug() << " --- SUPPA1: -> " << projectItem->contentNode()->to_string(); qDebug() << " --- SUPPA2: -> " << projectItem->sheetNode()->to_string(); qDebug() << " --- SUPPA3: -> " << projectItem->sheetNode()->find_child_by_tag_name("CurrentSection")->to_string(); diff --git a/src/items/xqitem.cpp b/src/items/xqitem.cpp index 84fa1a7..be2c601 100644 --- a/src/items/xqitem.cpp +++ b/src/items/xqitem.cpp @@ -141,7 +141,8 @@ XQItem::XQItem( XQItemType* itemType ) XQItem::XQItem(XQItemType* itemType, const QString *content ) : XQItem{ itemType } { - setContent(content); + // hier setzen wir direkt ohne umwege den string pointer + QStandardItem::setData( QVariant::fromValue(content), XQItem::ContentRole ); } XQItem::XQItem( XQItemType* itemType, const QString& content ) @@ -160,20 +161,29 @@ XQItem* XQItem::clone() const //! false für ein ungültiges item. 'ungültig' heisst hier, dass nur ein //! mockup-itemtype gesetzt ist. -bool XQItem::isValid() const +bool XQItem::isValidX() const { XQItemType* dummyType = XQItemType::staticItemType(); return QStandardItem::data( XQItem::ItemTypeRole ).value() != dummyType; } -//! testet, ob es einen content-node gibt. - bool XQItem::hasContentNode() const { - return contentNode() != nullptr; -} + if( column() == 0) + { + QVariant value = QStandardItem::data( XQItem::ContentNodeRole ); + return !value.isNull(); + } + // sonst: delegieren an den node-Besitzer + QModelIndex pIndex = model()->index( row(), 0 ); + if( pIndex.isValid() ) + { + XQItem& firstItem = xqItemFromIndex( pIndex ); + return firstItem.hasContentNode(); + } +} //! gibt den content-node zurück. @@ -346,21 +356,6 @@ QString* XQItem::content() const */ -//! Setzt den content()-string pointer. (als leihgabe) - -void XQItem::setContent( const QString* content ) -{ - setData( QVariant::fromValue(content), XQItem::ContentRole ); -} - - -//! Holt den schlüssel bzw. bezeicher des content() string aus 'unserem' content knoten. - -QString XQItem::contentKey() const -{ - return contentNode()->attributes().key_of( rawText() ); -} - //! Gibt den content-format string zurück QString XQItem::contentFormat() const @@ -432,6 +427,10 @@ QString XQItem::dataRoleName(int role) const return XQItem::fetchItemDataRoleName(role); } +bool XQItem::hasContentPtr() const +{ + return !QStandardItem::data( XQItem::ContentRole ).isNull(); +} //! Gibt den content()-String zurück, sofern vorhanden. //! sonst: gibt der ihnalt der Qt::DisplayRole als fallback @@ -439,9 +438,12 @@ QString XQItem::dataRoleName(int role) const QString XQItem::contentFallBackText() const { - const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value(); - if(contentPtr) - return *contentPtr; + if( hasContentPtr() ) + { + const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value(); + if(contentPtr) + return *contentPtr; + } // wenn wir keinen contentPtr haben, benutzen wir als fallback // die basis-text() role @@ -516,16 +518,24 @@ QVariant XQItem::data(int role ) const case ContentNodeRole: { - // Das Node-Besitzer-Item wohnt in der ersten Spalte, - // wenn wir also der Node-Besitzer item sind ... - if( column() == 0) - return QStandardItem::data( XQItem::ContentNodeRole ); + // Das Node-Besitzer-Item wohnt in der ersten Spalte, + // wenn wir also der Node-Besitzer item sind ... + if( column() == 0) + { + QVariant value = QStandardItem::data( XQItem::ContentNodeRole ); + if( !value.isNull() ) + return value; + throw XQException( "ContentNode is nullptr!"); + } - // sonst: delegieren an den node-Besitzer - QModelIndex pIndex = model()->index( row(), 0 ); + // sonst: delegieren an den node-Besitzer + QModelIndex pIndex = model()->index( row(), 0 ); + if( pIndex.isValid()) + { XQItem& firstItem = xqItemFromIndex( pIndex ); - return firstItem.data( XQItem::ContentNodeRole ); + } + throw XQException( "Item has no valid index (yet)!"); } case Qt::StatusTipRole: @@ -606,7 +616,7 @@ void XQItem::setData(const QVariant& value, int role ) // fallback: wenns keinen content node gibt, dann nehmen wir // das standardverfahren. int role = XQItem::ContentRole; - if( !hasContentNode() ) + if( !hasContentPtr() ) role = Qt::DisplayRole; QStandardItem::setData( plainText, role ); return; @@ -728,13 +738,10 @@ 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) { return s_UnitTypeMap[unitType]; } - -/// --- -/// --- -/// --- diff --git a/src/items/xqitem.h b/src/items/xqitem.h index 20b5992..47796e0 100644 --- a/src/items/xqitem.h +++ b/src/items/xqitem.h @@ -141,15 +141,16 @@ public: //! -- not used at the moment -- XQItem* clone() const override; - //! - bool isValid() const; + //! __fix Tested, ob ein itemtype vorhanden ist. + bool isValidX() const; - bool hasContentNode() const; + bool hasContentNode() const; //! gibt den zu diesem item gehörigen datenknoten zurück - virtual XQNodePtr contentNode() const; + XQNodePtr contentNode() const; - virtual XQNodePtr sheetNode() const; - virtual void setSheetNode( const XQNodePtr& sheetNode ); + + XQNodePtr sheetNode() const; + void setSheetNode( const XQNodePtr& sheetNode ); XQItemType& itemType() const; void setItemType( XQItemType* itemTypePtr ); @@ -165,8 +166,7 @@ public: // changed: gibt jetzt den pointer zurück. //QString* content() const; - QString contentKey() const; - void setContent( const QString* content ); + //void setContent( const QString* content ); // // Convenience-Funktionen zum Memberzugriff, die Implementierung @@ -243,6 +243,7 @@ protected: XQItem(const XQItem& other) = default; XQItem& operator=(const XQItem& other) = default; + bool hasContentPtr() const; QString contentFallBackText() const; // das ist protected, weil damit der content()-zugriff demoliert werden kann diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index dc0bece..ceae9fe 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -87,29 +87,28 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option qDebug() << " index DEAD!"; XQItem& item = xqItemFromIndex( index ); - if( item.isValid() ) + + + switch( item.renderStyle() ) { + case XQItem::HeaderStyle : + return drawHeaderStyle( painter, option, index ); - switch( item.renderStyle() ) - { - case XQItem::HeaderStyle : - return drawHeaderStyle( painter, option, index ); + case XQItem::ComboBoxStyle : + return drawComboBoxStyle( painter, option, index ); - case XQItem::ComboBoxStyle : - return drawComboBoxStyle( painter, option, index ); + case XQItem::HiddenStyle : + return; - case XQItem::HiddenStyle : - return; - - //case XQItem::ProgressBarStyle : - // return drawProgressBarStyle( painter, option, index ); + //case XQItem::ProgressBarStyle : + // return drawProgressBarStyle( painter, option, index ); - default: - break; - } // switch + default: + break; + } // switch + - } QStyledItemDelegate::paint(painter, option, index); @@ -226,7 +225,7 @@ QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte { XQItem& item = xqItemFromIndex(index); XQItem::EditorType edType = item.editorType(); - if( !item.hasContentNode() || edType == XQItem::NoEditorType ) + if( edType == XQItem::NoEditorType ) { qDebug() << "---- NO Content or NO EditorType"; return nullptr; @@ -235,7 +234,7 @@ QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte qDebug() << "---- ed type:" << XQItem::fetchEditorTypeToString( edType ) << ": " << edType; //return QStyledItemDelegate::createEditor( parent, option, index ); - return itemEditorFactory()->createEditor(edType, parent); + return itemEditorFactory()->createEditor(edType, parent); } diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 7027bc1..a34039f 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -8,8 +8,8 @@ - - + + @@ -75,7 +75,7 @@ - + @@ -98,12 +98,12 @@ - - - + + + - + @@ -119,9 +119,9 @@ - - - + + +