From d249c9c6319e81bb9ee22ca26056cc6d6fae847c Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sat, 16 Aug 2025 15:28:18 +0200 Subject: [PATCH] simplified model commands. --- src/application/xqappdata.cpp | 8 ++--- src/items/xqitem.cpp | 11 +++++- src/items/xqitem.h | 1 + src/items/xqitemdelegate.cpp | 31 ++++++++-------- src/items/xqitemdelegate.h | 2 -- src/items/xqitemfactory.cpp | 9 ++++- src/items/xqitemtype.cpp | 4 +-- src/main.cpp | 10 +++++- src/model/xqviewmodel.cpp | 67 +++++++++++++++++++++++++---------- src/model/xqviewmodel.h | 5 ++- xml/modelsheets.xml | 50 +++++++++++++++++++++++--- 11 files changed, 147 insertions(+), 51 deletions(-) diff --git a/src/application/xqappdata.cpp b/src/application/xqappdata.cpp index df86997..db723d0 100644 --- a/src/application/xqappdata.cpp +++ b/src/application/xqappdata.cpp @@ -77,10 +77,10 @@ namespace XQAppData namedInsert( "BrowserStop", QStyle::SP_BrowserStop ); namedInsert( "icn33Dummy", QStyle::SP_DriveHDIcon ); namedInsert( "icn34Dummy", QStyle::SP_MessageBoxQuestion ); - namedInsert( "icn35Dummy", QStyle::SP_CommandLink ); + namedInsert( "CommandLink", QStyle::SP_CommandLink ); namedInsert( "icn36Dummy", QStyle::SP_DriveNetIcon ); - namedInsert( "icn37Dummy", QStyle::SP_MessageBoxWarning ); - namedInsert( "icn38Dummy", QStyle::SP_ComputerIcon ); + namedInsert( "MessageBoxWarning", QStyle::SP_MessageBoxWarning ); + namedInsert( "ComputerIcon", QStyle::SP_ComputerIcon ); namedInsert( "icn39Dummy", QStyle::SP_FileDialogBack ); namedInsert( "icn40Dummy", QStyle::SP_TitleBarCloseButton ); namedInsert( "icn42Dummy", QStyle::SP_FileDialogContentsView ); @@ -114,7 +114,7 @@ namespace XQAppData namedInsert( "TrashIcon", QStyle::SP_TrashIcon ); namedInsert( "icn72Dummy", QStyle::SP_DialogSaveButton ); namedInsert( "icn73Dummy", QStyle::SP_MediaPause ); - namedInsert( "icn74Dummy", QStyle::SP_VistaShield ); + namedInsert( "VistaShield", QStyle::SP_VistaShield ); namedInsert( "icn75Dummy", QStyle::SP_DialogYesButton ); namedInsert( "icn76Dummy", QStyle::SP_MediaPlay ); namedInsert( "icn77Dummy", QStyle::SP_DirClosedIcon ); diff --git a/src/items/xqitem.cpp b/src/items/xqitem.cpp index 702bef8..3e1c282 100644 --- a/src/items/xqitem.cpp +++ b/src/items/xqitem.cpp @@ -257,6 +257,14 @@ void XQItem::clearFlag( Qt::ItemFlag newFlag ) setFlags( flags() & ~newFlag); } + +//! gibt die itemFlags als string zurück. + +QString XQItem::itemFlagsToString() const +{ + return'(' + data(XQItem::FlagsRole).toString() +')'; +} + /// /// data() access shortcuts /// @@ -277,6 +285,7 @@ QString XQItem::renderStyleToString() const } + //! setzt den editorType. wird im itemType gespeichert. void XQItem::setRenderStyle(RenderStyle renderStyle ) @@ -483,7 +492,7 @@ QVariant XQItem::data(int role ) const case Qt::ToolTipRole: { - return content() + ":" + itemType().text() + ":" + renderStyleToString() + ":" + unitTypeToString(); + return content() + ":" + unitTypeToString() + ":" + renderStyleToString() + ":" + unitTypeToString() + ":" + itemFlagsToString(); } // diff --git a/src/items/xqitem.h b/src/items/xqitem.h index 38fa77d..55412fe 100644 --- a/src/items/xqitem.h +++ b/src/items/xqitem.h @@ -161,6 +161,7 @@ public: // __fix! das können die selber !? void addFlag( Qt::ItemFlag newFlag ); void clearFlag( Qt::ItemFlag newFlag ); + QString itemFlagsToString() const; //das ist ein Sonderfall: Ein ist ein dereferenzierter Zeiger auf 'unser' Atrribut in // XQNodePtr, also unserem contentNode(). Das wird hier direkt aufgelöst und nicht auf diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index 79883b3..475133e 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -81,22 +81,6 @@ XQItem& XQItemDelegate::xqItemFromIndex( const QModelIndex& index ) const } - -QWidget* XQItemDelegate::prepareHeaderOption(const QStyleOptionViewItem& option, const QModelIndex& index, QStyleOptionHeader& headerOption) const -{ - // use the header as "parent" for style init - QWidget* srcWidget = treeTable()->header(); - headerOption.initFrom(srcWidget); - headerOption.text = index.data(Qt::DisplayRole).toString(); - headerOption.rect = option.rect; - headerOption.styleObject = option.styleObject; - // __ch: reduce inner offset when painting - headerOption.textAlignment |= Qt::AlignVCenter; - - return srcWidget; - -} - void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { if( !index.isValid() ) @@ -131,11 +115,24 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option } +//! einen section header im header-style zeichnen void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionHeader headerOption; - QWidget* srcWidget = prepareHeaderOption(option, index, headerOption); + + XQItem& item = xqItemFromIndex( index ); + + // use the header as "parent" for style init + QWidget* srcWidget = treeTable();//->header(); + headerOption.initFrom(srcWidget); + headerOption.text = index.data(Qt::DisplayRole).toString(); + headerOption.rect = option.rect.adjusted(0,0,0,3); + headerOption.styleObject = option.styleObject; + // __ch: reduce inner offset when painting + headerOption.textAlignment |= Qt::AlignVCenter; + headerOption.icon = item.icon(); + if (srcWidget != nullptr) { // save painter diff --git a/src/items/xqitemdelegate.h b/src/items/xqitemdelegate.h index bc3c46b..63b9ecf 100644 --- a/src/items/xqitemdelegate.h +++ b/src/items/xqitemdelegate.h @@ -46,8 +46,6 @@ public: protected: - QWidget* prepareHeaderOption(const QStyleOptionViewItem& option, const QModelIndex& index, QStyleOptionHeader& headerOption) const; - void drawHeaderStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void drawProgressBarStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void drawComboBoxStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index 957d89f..db324b7 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -278,7 +278,14 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& co // der content wird indirect über den tag-name des sheetnode geholt contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); - return new XQItem( itemType, contentPtr ); + XQItem* newItem = new XQItem( itemType, contentPtr ); + if( newItem->isCheckable() ) + { + qDebug() << " --- yooo: " << newItem->toolTip(); + newItem->setCheckState( Qt::Checked ); + } + + return newItem; } diff --git a/src/items/xqitemtype.cpp b/src/items/xqitemtype.cpp index 189e0d1..491a43d 100644 --- a/src/items/xqitemtype.cpp +++ b/src/items/xqitemtype.cpp @@ -255,8 +255,8 @@ QString XQItemType::makeItemTypeKey() key = key.arg( renderStyleToString() ); key = key.arg( editorTypeToString() ); key = key.arg( unitTypeToString() ); - key = key.arg( contentFormat() ); - key = key.arg( data(XQItem::FlagsRole).toString() ); + key = key.arg( contentFormat() ); + key = key.arg( itemFlagsToString() ); // icons haben leider keine namen, es sei denn, sie kommen aus einen theme //key = key.arg( icon().name() ); //key = key.arg( icon().cacheKey() ); diff --git a/src/main.cpp b/src/main.cpp index 0da358a..6189c3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,15 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); - QIcon icon; + /* + // Signal für einzelne QStandardItem-Änderungen +connect(model, &QStandardItemModel::itemChanged, + this, [](QStandardItem *changedItem){ + QVariant state = changedItem->data(Qt::CheckStateRole); + qDebug() << "Neuer Check-State:" << state.toInt(); +}); + */ + //app.setStyle("fusion"); XQMainWindow window; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 2350b37..b52673b 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -192,16 +192,7 @@ void XQViewModel::onActionTriggered(QAction* action) } - -//! führt die 'redo' action des gegebenen commnds aus. - -void XQViewModel::onCommandRedo( XQCommand& command ) -{ - QMap> s_RedoMap; - - try - { - +/* switch (command.commandType()) { case XQCommand::cmdToggleSection: @@ -225,6 +216,28 @@ void XQViewModel::onCommandRedo( XQCommand& command ) default: qDebug() << " --- onCommandRedo: default: not handled: " << command.toString(); } + */ + +//! führt die 'redo' action des gegebenen commnds aus. + +void XQViewModel::onCommandRedo( XQCommand& command ) +{ + static MemCallMap redoCalls + { + { XQCommand::cmdToggleSection, &XQViewModel::cmdToggleSection }, + { XQCommand::cmdCut, &XQViewModel::cmdCut }, + { XQCommand::cmdPaste, &XQViewModel::cmdPaste }, + { XQCommand::cmdNew, &XQViewModel::cmdNew }, + { XQCommand::cmdDelete, &XQViewModel::cmdDelete } + }; + + try + { + MemCall memCall = redoCalls[command.commandType()]; + if( memCall ) + (this->*memCall)( command ); + else + qDebug() << " --- onCommandRedo: default: not handled: " << command.toString(); } catch( XQException& exception ) { @@ -233,12 +246,7 @@ void XQViewModel::onCommandRedo( XQCommand& command ) } } - -//! führt die 'undo' action des gegebenen commnds aus. - -void XQViewModel::onCommandUndo( XQCommand& command ) -{ - qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count; +/* try { switch (command.commandType()) @@ -273,13 +281,35 @@ void XQViewModel::onCommandUndo( XQCommand& command ) default: qDebug() << " --- onCommandUndo: default: not handled: " << command.toString(); } + */ +//! führt die 'undo' action des gegebenen commnds aus. + +void XQViewModel::onCommandUndo( XQCommand& command ) +{ + qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count; + + static MemCallMap undoCalls + { + { XQCommand::cmdToggleSection, &XQViewModel::cmdToggleSection }, + { XQCommand::cmdCut, &XQViewModel::cmdCutUndo }, + { XQCommand::cmdPaste, &XQViewModel::cmdPasteUndo }, + { XQCommand::cmdNew, &XQViewModel::cmdNewUndo }, + { XQCommand::cmdDelete, &XQViewModel::cmdDeleteUndo }, + }; + + try + { + MemCall memCall = undoCalls[command.commandType()]; + if( memCall ) + (this->*memCall)( command ); + else + qDebug() << " --- onCommandUndo: default: not handled: " << command.toString(); } catch( XQException& exception ) { qDebug() << exception.what(); QMessageBox::critical( nullptr, "Failure", QString("Failure: %1").arg(exception.what()) ); } - } // undo-/redo-able stuff @@ -461,8 +491,9 @@ void XQViewModel::cmdNewUndo( XQCommand& command ) //! schaltet eine section sichtbar oder unsichtbar. -void XQViewModel::cmdToggleSection( const QModelIndex& index ) +void XQViewModel::cmdToggleSection( XQCommand& command ) { + const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); int fstRow = _sections.firstRow( index ); diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 8b84534..f52370a 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -58,7 +58,7 @@ public: // undo-/redo-able stuff - virtual void cmdToggleSection( const QModelIndex& index ); + virtual void cmdToggleSection( XQCommand& command ); virtual void cmdCut( XQCommand& command ); virtual void cmdCutUndo( XQCommand& command ); virtual void cmdPaste( XQCommand& command ); @@ -111,6 +111,9 @@ protected: protected: + using MemCall = void (XQViewModel::*)(XQCommand&); + using MemCallMap = QMap; + // das eine reference auf ein globales singleton XQItemFactory& _itemFactory; XQSimpleClipBoard _clipBoard; diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 7b4d78d..a55d630 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -8,12 +8,13 @@ - - + + - + + @@ -71,7 +72,7 @@ - + @@ -79,6 +80,47 @@ +
+
+ + + + + + + +
+ + + + + + + + + +
+ +
+
+ + + + + + + +
+ + + + + + + + + +