From 89c671295fd00a42b3a84c9699f4991d9877dfa1 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sat, 6 Sep 2025 14:07:25 +0200 Subject: [PATCH] finally, fixed hiding of headers. --- src/application/xqmainwindow.cpp | 4 +-- src/model/xqcommand.cpp | 2 +- src/model/xqsectionmanager.cpp | 49 ++++++++++++++++---------------- src/model/xqsectionmanager.h | 4 +-- src/model/xqviewmodel.cpp | 33 ++++++++++----------- src/util/xqmaptor.h | 36 +++++++++++++++++++++-- 6 files changed, 79 insertions(+), 49 deletions(-) diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index bd8ba14..511f89f 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -126,7 +126,7 @@ void XQMainWindow::initMainWindow() // #2. load demo data loadDocument( c_DocumentFileName1 ); //loadDocumentQML( c_DocumentFileName2 ); - loadDocument( c_DocumentFileName2 ); + //loadDocument( c_DocumentFileName2 ); qDebug() << " --- all here: " << XQNode::s_Count; @@ -311,7 +311,7 @@ void XQMainWindow::onChildViewTabClicked( int idx ) void XQMainWindow::onSectionCreated( const XQModelSection& section ) { - qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); + //qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); if( _currentProjectItem ) { _mainModel.addSectionItem( section, _currentProjectItem ); diff --git a/src/model/xqcommand.cpp b/src/model/xqcommand.cpp index d7bbb37..33fa559 100644 --- a/src/model/xqcommand.cpp +++ b/src/model/xqcommand.cpp @@ -108,7 +108,7 @@ void XQCommand::setOriginIndex( const QModelIndex& origin ) void XQCommand::saveNodes( const QModelIndexList& list ) { clear(); - // über jede zeil + // über jede zeile for( auto entry : list ) { // knoten holen diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index 7c5928b..041d1f1 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -19,7 +19,7 @@ //! der datenknoten. XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNode) - : _modelIndex{ modelIndex }, _sectionRootNode{ sheetNode } + : _modelIndex{ modelIndex }, _sectionSheetRootNode{ sheetNode } { } @@ -29,7 +29,7 @@ XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNod bool XQModelSection::operator==(const XQModelSection& other) const { - return _modelIndex == other._modelIndex && _sectionRootNode == other._sectionRootNode; + return _modelIndex == other._modelIndex && _sectionSheetRootNode == other._sectionSheetRootNode; } @@ -37,7 +37,7 @@ bool XQModelSection::operator==(const XQModelSection& other) const bool XQModelSection::isValid() const { - return _modelIndex.isValid() && _sectionRootNode; + return _modelIndex.isValid() && _sectionSheetRootNode; } QModelIndex XQModelSection::startIndex() const @@ -47,7 +47,7 @@ QModelIndex XQModelSection::startIndex() const XQNodePtr XQModelSection::sectionRootNode() const { - return _sectionRootNode; + return _sectionSheetRootNode; } //! Gibt den sheet-node zurück, das ist die model-beschreibung, @@ -60,7 +60,7 @@ XQNodePtr XQModelSection::sectionRootNode() const XQNodePtr XQModelSection::sheetRootNode() const { - return _sectionRootNode->find_child_by_tag_name( c_ModelSheet ); + return _sectionSheetRootNode->find_child_by_tag_name( c_ModelSheet ); } @@ -90,7 +90,8 @@ int XQModelSection::XQModelSection::firstRow() const const QString& XQModelSection::contentType() const { - return _sectionRootNode->attribute( c_ContentType ); + //qDebug() << " ---AUA & AUS!"; + return _sectionSheetRootNode->attribute( c_ContentType ); } @@ -116,8 +117,7 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey if( hasValidSection( sectionKey ) ) return _sections.at(sectionKey); - static const XQModelSection s_DummySection; - return s_DummySection; + throw XQException( "No section for key: ", sectionKey); } @@ -127,21 +127,31 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const { + /* + for( const XQModelSection& section : _sections ) + { + qDebug() << " --- sectionByRow: " <= 0; --i) { - if ( _sections.at(i).startIndex().row() < itemRow ) + if ( _sections.at(i).startIndex().row() <= itemRow ) return _sections.at(i); } - static XQModelSection s_DummySection; - return s_DummySection; + throw XQException( "No section for item row: ", QString::number(itemRow)); } -const XQModelSection& XQSectionManager::createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode) +const XQModelSection& XQSectionManager::createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode) { - // 6. jetzt können wir auch die sction erzeugen + const QString& sectionKey = sheetNode->attribute(c_ContentType); + qDebug() << " --- create Section: " << sectionKey << ": " << modelIndex.data().toString(); XQModelSection section(modelIndex, sheetNode ); _sections.addAtKey( sectionKey, section); return sectionByKey(sectionKey); @@ -151,20 +161,9 @@ const XQModelSection& XQSectionManager::createSection(const QString& sectionKey, //! ermittelt die zeile unterhalb des gegebenen modelindex, //! zum einfügen neuer items ebendort. -/* -int XQSectionManager::lastRow(const QModelIndex& idx) const -{ - return lastRow(sectionByRow(idx.row())); -} - - -//! ermittelt die zeile unterhalb der gegebenen section, -//! zum einfügen neuer items ebendort. -*/ - int XQSectionManager::lastRow(const XQModelSection& section ) const { - qDebug() << " -- last row in section: " << section.startIndex().data().toString() << " --> " << section.startIndex().row(); + //qDebug() << " -- last row in section: " << section.startIndex().data().toString() << " --> " << section.startIndex().row(); // row() der section unterhalb dieser // __fix? index mit speichern? int index = _sections.indexOf(section); diff --git a/src/model/xqsectionmanager.h b/src/model/xqsectionmanager.h index 686dacb..91b7157 100644 --- a/src/model/xqsectionmanager.h +++ b/src/model/xqsectionmanager.h @@ -51,7 +51,7 @@ protected: QPersistentModelIndex _modelIndex; - mutable XQNodePtr _sectionRootNode{}; + mutable XQNodePtr _sectionSheetRootNode{}; mutable XQNodePtr _contentRootNode{}; }; @@ -77,7 +77,7 @@ public: const XQModelSection& sectionByKey( const QString& sectionKey ) const; const XQModelSection& sectionByRow( int row ) const; - const XQModelSection& createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode); + const XQModelSection& createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode); int lastRow(const XQModelSection& section ) const; XQSectionRange sectionRange(const XQModelSection §ion) const; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 1b37dd4..f037628 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -165,9 +165,8 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sheetNode // 5. das erzeugt dann auch valide indices appendRow(list); - const QString §ionKey = sheetNode->attribute(c_ContentType); - // 6. jetzt können wir auch die sction erzeugen - const XQModelSection& section = _sections.createSection( sectionKey, list[0]->index(), sheetNode ); + // 6. jetzt können wir auch die section erzeugen + const XQModelSection& section = _sections.createSection( list[0]->index(), sheetNode ); // ... und es der welt mitteilen. emit sectionCreated( section ); @@ -187,18 +186,17 @@ void XQViewModel::onToggleSection(const QString& sectionKey ) void XQViewModel::toggleSection( const XQModelSection& section ) { - qDebug() << " --- toggleSection: " << section.contentType(); if( section.isValid() && _treeTable ) { - XQSectionRange pos = _sections.sectionRange(section); - //int fstRow = _sections.firstRow(index); - //int lstRow = _sections.lastRow(index); - _treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow ); qDebug() << " --- toggleSection: " << section.contentType(); - + XQSectionRange pos = _sections.sectionRange(section); + _treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow ); // hier nicht!? - emit sectionToggled(section); - + //emit sectionToggled(section); + } + else + { + qDebug() << " --- toggleSection: FAIL!"; } } @@ -217,7 +215,7 @@ void XQViewModel::onItemChanged(XQItem* item ) void XQViewModel::onActionTriggered(QAction* action) { - qDebug() << " --- onActionTriggered: count:" << XQNode::s_Count; + qDebug() << " --- onActionTriggered: count:" << action->text() <<": " << XQNode::s_Count; // all selected indices QModelIndexList selectionList = treeTable()->selectionModel()->selectedRows(); @@ -226,6 +224,7 @@ void XQViewModel::onActionTriggered(QAction* action) switch( cmdType ) { + // just handle undo ... case XQCommand::cmdUndo : return _undoStack->undo(); @@ -250,14 +249,15 @@ void XQViewModel::onActionTriggered(QAction* action) // we create a command XQCommand* command = new XQCommand( cmdType, this ); + QModelIndex currentIndex = treeTable()->currentIndex(); + command->setOriginIndex(currentIndex); // store the row positions of the selected indices command->saveNodes( selectionList ); - command->setOriginIndex( treeTable()->currentIndex() ); + // execute command _undoStack->push( command ); - } @@ -455,7 +455,7 @@ void XQViewModel::cmdDeleteUndo( const XQCommand& command ) { for (const auto& entry : command) { - qDebug() << " --- delete UNDo: " << entry.contentNode->to_string(); + qDebug() << " --- delete UNDo: " << entry.contentNode->friendly_name(); } } @@ -506,7 +506,8 @@ void XQViewModel::cmdToggleSection( const XQCommand& command ) { const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); - toggleSection( _sections.sectionByRow(index.row()) ); + const XQModelSection& section = _sections.sectionByRow(index.row()); + toggleSection( section ); } diff --git a/src/util/xqmaptor.h b/src/util/xqmaptor.h index 9aa6c60..1f8bb12 100644 --- a/src/util/xqmaptor.h +++ b/src/util/xqmaptor.h @@ -89,6 +89,7 @@ public: } + inline bool isEmpty() const { return (_data.size()==0); @@ -156,14 +157,14 @@ public: T& operator[]( const QString& key ) { if( key.isEmpty() || !contains(key) ) - throw XQException("maprow operator[]: key empty || not found: " + key); + throw XQException("XQMaptor operator[]: key empty || not found: " + key); return _data[ _index[key] ]; } const T& operator[]( const QString& key ) const { if (key.isEmpty() || !contains(key)) - throw XQException("maprow operator[]: key empty || not found: " + key); + throw XQException("XQMaptor operator[]: key empty || not found: " + key); return _data[_index[key]]; } @@ -177,6 +178,35 @@ public: return (*this)[key]; } + const T& last() const + { + if(_data.isEmpty()) + throw XQException( "XQMaptor last: is empty!" ); + return _data.last(); + } + + const T& first() const + { + if(_data.isEmpty()) + throw XQException( "XQMaptor first: is empty!" ); + return _data.first(); + } + + T& last() + { + if(_data.isEmpty()) + throw XQException( "XQMaptor last: is empty!" ); + return _data.last(); + } + + T& first() + { + if(_data.isEmpty()) + throw XQException( "XQMaptor first: is empty!" ); + return _data.first(); + } + + virtual int add( const T& item ) { _data.push_back( item ); @@ -186,7 +216,7 @@ public: virtual void addAtIndex( int index, const T& item ) { if(contains(index)) - throw XQException( "QStringrow::add: index out of range!" ); + throw XQException( "XQMaptor add at index: index out of range!" ); _data[index] = item; }