diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index 61198b2..1fe71fb 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -57,8 +57,7 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot ) const XQModelSection& section = _sections.sectionByKey( key ); section.setContentRootNode( contentEntry->parent() ); - // FaRZ! - //int newRow = _sections.lastRow(section); + int newRow = _sections.lastRow(section); XQNodePtr sheetNode = section.sheetRootNode(); XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); @@ -80,8 +79,7 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content if(section.isValid() ) { section.setContentRootNode( contentEntry->parent() ); - // FARZ! - int newRow = 1;//_sections.lastRow(section); + int newRow =_sections.lastRow(section); XQNodePtr sheetNode = section.sheetRootNode(); XQItemList list = _itemFactory.makeRow( sheetNode, nullptr ); insertRow( newRow, list); diff --git a/src/model/xqcommand.h b/src/model/xqcommand.h index 3317403..607f186 100644 --- a/src/model/xqcommand.h +++ b/src/model/xqcommand.h @@ -61,6 +61,8 @@ public: cmdNew, cmdDelete, + cmdToggleSection, + cmdExtern //?? }; diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index 4f09f01..b546a87 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -40,7 +40,7 @@ bool XQModelSection::isValid() const return _modelIndex.isValid() && _sectionRootNode; } -QModelIndex XQModelSection::persistentModelIndex() const +QModelIndex XQModelSection::startIndex() const { return _modelIndex.operator QModelIndex(); } @@ -80,7 +80,7 @@ void XQModelSection::setContentRootNode( const XQNodePtr contentRootNode ) const //! gibt die zeile des start-index zurück. -int XQModelSection::XQModelSection::row() const +int XQModelSection::XQModelSection::firstRow() const { return _modelIndex.row(); } @@ -111,7 +111,7 @@ bool XQSectionManager::hasValidSection(const QString& sectionKey) const return _sections.at(sectionKey).isValid(); } -const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey ) +const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey ) const { if( hasValidSection( sectionKey ) ) return _sections.at(sectionKey); @@ -121,29 +121,20 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey } -//! gibt für einen model index die 'zuständige' section zurück. - -const XQModelSection& XQSectionManager::sectionByIndex( const QModelIndex& index ) const -{ - return sectionByRow( index.row() ); -} - //! gibt für eine zeile die 'zuständige' section zurück: der bestand an section wird //! nach der passenden section durchsucht. const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const { - int i = _sections.size() - 1; for (; i >= 0; --i) { - if ( _sections.at(i).persistentModelIndex().row() < itemRow ) + if ( _sections.at(i).startIndex().row() < itemRow ) return _sections.at(i); } static XQModelSection s_DummySection; - return s_DummySection; } @@ -156,14 +147,6 @@ const XQModelSection& XQSectionManager::createSection(const QString& sectionKey, return sectionByKey(sectionKey); } -//! ermittelt die erste zeile einer section. - -/* -int XQSectionManager::firstRow(const QModelIndex& idx) const -{ - return sectionByRow(idx.row() ).row(); -} -*/ //! ermittelt die zeile unterhalb des gegebenen modelindex, //! zum einfügen neuer items ebendort. @@ -177,10 +160,11 @@ int XQSectionManager::lastRow(const QModelIndex& idx) const //! 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.modelIndex.data().toString() << " --> " << section.modelIndex.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); @@ -188,23 +172,18 @@ int XQSectionManager::lastRow(const XQModelSection& section ) const { // last section? return last row of model if (index == _sections.size() - 1) - return section.persistentModelIndex().model()->rowCount();// - 1; + return section.startIndex().model()->rowCount() - 1; // return row above the row of the next section -> last row of given section - return _sections.at(index+1).row(); + return _sections.at(index+1).firstRow() - 1; } return -1; } -*/ -/* - int firstRow(const QModelIndex& idx) const; - int lastRow(const QModelIndex& idx) const; - int lastRow(const XQModelSection& section) const; - */ -XQSectionPos XQSectionManager::sectionPos() +XQSectionRange XQSectionManager::sectionRange(const XQModelSection& section ) const { - return XQSectionPos(); + qDebug() << " ---- Section RANGE: " << section.startIndex().row() << " -> " << lastRow(section); + return XQSectionRange{ section.startIndex().row(), lastRow(section) }; } @@ -215,7 +194,7 @@ void XQSectionManager::dump() const qDebug() << " --- sections dump(): " <<_sections.size() << " entries."; for( int i = 0; i<_sections.size(); ++i ) { - QModelIndex idx = _sections.at(i).persistentModelIndex(); + QModelIndex idx = _sections.at(i).startIndex(); qDebug() << " --- sections:" << i << "row: " << idx.row() << " keyOf(i): " << _sections.keyOf(i) << " indexData: "<< idx.data().toString() << " itemData: " << XQItem::xqItemFromIndex(idx).data(Qt::DisplayRole).toString(); } diff --git a/src/model/xqsectionmanager.h b/src/model/xqsectionmanager.h index 9db755b..686dacb 100644 --- a/src/model/xqsectionmanager.h +++ b/src/model/xqsectionmanager.h @@ -36,9 +36,9 @@ public: bool operator==(const XQModelSection& other) const; bool isValid() const; - int row() const; + int firstRow() const; - QModelIndex persistentModelIndex() const; + QModelIndex startIndex() const; XQNodePtr sectionRootNode() const; XQNodePtr sheetRootNode() const; XQNodePtr contentRootNode() const; @@ -59,7 +59,7 @@ protected: Q_DECLARE_METATYPE(XQModelSection) //! Erste und letzte ziele einer XQModelSection -struct XQSectionPos +struct XQSectionRange { int firstRow{-1}; int lastRow{-1}; @@ -74,19 +74,12 @@ public: bool hasValidSection(const QString& sectionKey) const; - const XQModelSection& sectionByKey( const QString& sectionKey ); + const XQModelSection& sectionByKey( const QString& sectionKey ) const; const XQModelSection& sectionByRow( int row ) const; - const XQModelSection& sectionByIndex( const QModelIndex& index ) const; const XQModelSection& createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode); - - /* - int firstRow(const QModelIndex& idx) const; - int lastRow(const QModelIndex& idx) const; - int lastRow(const XQModelSection& section) const; - */ - - XQSectionPos sectionPos(); + int lastRow(const XQModelSection& section ) const; + XQSectionRange sectionRange(const XQModelSection §ion) const; void dump()const; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 967b323..14ee63f 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -175,24 +175,33 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sectionNod } +//! SLOT, toggled die section mit dem 'sectionKey' (hier: contentType) + void XQViewModel::onToggleSection(const QString& sectionKey ) { - qDebug() << " --- onToggleSection: " << sectionKey; - if( _sections.hasValidSection( sectionKey ) && _treeTable ) - { - //const XQModelSection& section =_sections.sectionByKey(sectionKey); + toggleSection( _sections.sectionByKey(sectionKey) ); +} + +//! toggled die gegebene model section. + +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(fstRow, lstRow); + // hier nicht!? //emit sectionToggled(section); + } - } - /* //! SLOT als weiterleitung vom SIGNAL itemchanged @@ -463,7 +472,7 @@ void XQViewModel::cmdNew( const XQCommand& command ) //... - const XQModelSection& section = _sections.sectionByIndex( origin ); + const XQModelSection& section = _sections.sectionByRow( origin.row() ); // neue, leere zeile erzeugen ... XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode ); @@ -489,14 +498,13 @@ void XQViewModel::cmdNewUndo( const XQCommand& command ) //! schaltet eine section sichtbar oder unsichtbar. -/* void XQViewModel::cmdToggleSection( const XQCommand& command ) { const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); - toggleSection( _sections.sectionByIndex(index) ); + toggleSection( _sections.sectionByRow(index.row()) ); } -*/ + //! gibt die treetable zurück diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 20db1f0..128babb 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -55,7 +55,7 @@ public: virtual void initModel( const QString& modelName); void expandNewItem(const QModelIndex& index); - void toggleSection( const QString& sectionKey ); + void toggleSection( const XQModelSection& section ); //little helpers const XQItem& xqRootItem(); @@ -66,7 +66,7 @@ public: // undo-/redo-able stuff - //virtual void cmdToggleSection( const XQCommand& command ); + virtual void cmdToggleSection( const XQCommand& command ); virtual void cmdCut( const XQCommand& command ); virtual void cmdCutUndo( const XQCommand& command ); virtual void cmdPaste( const XQCommand& command ); @@ -91,13 +91,10 @@ public slots: virtual void onShowContextMenu(const QPoint& point); virtual void onActionTriggered(QAction* action); virtual void onToggleSection(const QString& sectionKey ); - // handle XQCommands ( == UndoCommand ) virtual void onCommandRedo( const XQCommand& command ); virtual void onCommandUndo( const XQCommand& command ); - - protected: void addSection(const XQItemList& list, const XQNodePtr& sheetNode ); diff --git a/src/widgets/xqcontextmenu.cpp b/src/widgets/xqcontextmenu.cpp index 316fdab..4c8a562 100644 --- a/src/widgets/xqcontextmenu.cpp +++ b/src/widgets/xqcontextmenu.cpp @@ -31,7 +31,7 @@ void XQContextMenu::addAction(const QString& text, XQCommand::CmdType commandTyp QAction* newAction = new QAction(text, this); newAction->setData(commandType); _actionMap[commandType] = newAction; - QWidget::addAction(newAction); + QMenu::addAction(newAction); setActionEnabled( commandType, enabled ); } @@ -53,7 +53,7 @@ void XQContextMenu::addAction(const QIcon& icon, const QString& text, XQCommand: QAction* newAction = new QAction(icon, text, this); newAction->setData(commandType); _actionMap[commandType] = newAction; - QWidget::addAction(newAction); + QMenu::addAction(newAction); setActionEnabled( commandType, enabled ); }