diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index dff6018..87dee9b 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -60,17 +60,9 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) // den neuen eintrag in die passende section der übersicht eintragen ... section.headerItem().appendRow( newItem ); - // ... ausklappen... - const QModelIndex index = section.headerItem().index(); - _treeTable->expand( index ); - // ... und markieren - _treeTable->setCurrentIndex( index ); - // quellknoten auch speichern - //newItem->setContentNode( contentNode ); - //emit itemCreated( newItem ); - // erzeuger sheet node speichern newItem->setSheetNode( sheetNode ); + expandNewItem(section.headerItem().index() ); return newItem; } } @@ -80,24 +72,8 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) void XQMainModel::addSectionItem( const XQModelSection& section, XQItem* projectItem ) { - - qDebug() << " --- SUPPA0: " << section.contentType(); - 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(); - XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection"); XQItem* newItem = _itemFactory.makeSingleItem( sheetNode, section.contentType() ); projectItem->appendRow( newItem ); - //qDebug() << " --- SUPPA4: -> " << section.contentRootNode()->to_string(); - - - /* - XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection"); - XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, nullptr, c_ContentType ); - projectItem->appendRow( list ); - _treeTable->expand( projectItem->index() ); -*/ - + expandNewItem(projectItem->index() ); } diff --git a/src/model/xqmodelsectionlist.h b/src/model/xqmodelsectionlist.h index 0ddfb2b..cc59bd7 100644 --- a/src/model/xqmodelsectionlist.h +++ b/src/model/xqmodelsectionlist.h @@ -57,9 +57,8 @@ protected: Q_DECLARE_METATYPE(XQModelSection) -/** - * @brief Maptor containing all header sections. - */ + +//! 'maptor' struktur, die alle sections enthält class XQModelSectionList : public XQMaptor { diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 4bae855..8882622 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -83,6 +83,16 @@ XQItem& XQViewModel::xqFirstItem(int row) const return *static_cast( QStandardItemModel::item(row) ); } +void XQViewModel::expandNewItem(const QModelIndex& index) +{ + if( _treeTable ) + { + // ... ausklappen... + _treeTable->expand( index ); + // ... und markieren + _treeTable->setCurrentIndex( index ); + } +} //! initialisiert dieses model über den namen. Es wird hier //! nur die strukur erzeugt, keine inhalte. @@ -148,6 +158,27 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sectionNod } +void XQViewModel::onToggleSection(const QString& sectionKey ) +{ + qDebug() << " --- onToggleSection: " << sectionKey; + /* + + connect(model, &QStandardItemModel::dataChanged, this, &YourClass::onItemChanged); + +void YourClass::onItemChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) +{ + if (roles.contains(Qt::CheckStateRole)) { + Qt::CheckState state = static_cast(topLeft.data(Qt::CheckStateRole).toInt()); + if (state == Qt::Checked) { + qDebug() << "Checkbox wurde aktiviert!"; + // Hier kannst du dein QObject benachrichtigen + } + } +} + + +} + //! SLOT, der aufgerufen wird, wenn eine edit-action getriggert wurde. void XQViewModel::onActionTriggered(QAction* action) @@ -428,6 +459,29 @@ void XQViewModel::cmdNew( const XQCommand& command ) */ } +void XQViewModel::toggleSection( const XQModelSection& section ) +{ + + /* + + if(_treeTable) + { + + qDebug() << " ---- FIRZ: " << _sections.keyOf( sec ); + int fstRow = _sections.firstRow( index ); + int lstRow = _sections.lastRow( index ); + _treeTable->toggleRowsHidden(fstRow, lstRow ); + + + + } + + */ + + emit sectionToggled( section ); + +} + //! entfernt die neu angelegte zeile. void XQViewModel::cmdNewUndo( const XQCommand& command ) @@ -441,19 +495,11 @@ void XQViewModel::cmdToggleSection( const XQCommand& command ) { const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); - - int fstRow = _sections.firstRow( index ); - int lstRow = _sections.lastRow( index ); - - bool hidden =_treeTable->isRowHidden( fstRow, _treeTable->rootIndex() ); - for (int row = fstRow; row < lstRow; ++row ) - _treeTable->setRowHidden( row, _treeTable->rootIndex(), !hidden ); - - emit sectionToggled( _sections.sectionFromIndex(index) ); + toggleSection( _sections.sectionFromIndex(index) ); } -//! git die treetable zurück +//! gibt die treetable zurück XQTreeTable* XQViewModel::treeTable() { diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 0634196..ed92405 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -54,6 +54,9 @@ public: virtual void initModel( const QString& modelName); + void expandNewItem(const QModelIndex& index); + void toggleSection( const XQModelSection& section ); + //little helpers const XQItem& xqRootItem(); @@ -96,6 +99,7 @@ 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 ); diff --git a/src/widgets/xqtreetable.cpp b/src/widgets/xqtreetable.cpp index 7a9c400..4e82e68 100644 --- a/src/widgets/xqtreetable.cpp +++ b/src/widgets/xqtreetable.cpp @@ -51,6 +51,12 @@ XQItem& XQTreeTable::xqItemFromIndex(const QModelIndex& index ) return modelView()->xqItemFromIndex( index ); } +void XQTreeTable::toggleRowsHidden( int fstRow, int lstRow ) +{ + bool hidden = isRowHidden( fstRow, rootIndex() ); + for (int row = fstRow; row < lstRow; ++row ) + setRowHidden( row, rootIndex(), !hidden ); +} //! override von 'currentChanged' (noch nicht implementiert) diff --git a/src/widgets/xqtreetable.h b/src/widgets/xqtreetable.h index 39772de..8f6db0a 100644 --- a/src/widgets/xqtreetable.h +++ b/src/widgets/xqtreetable.h @@ -41,6 +41,8 @@ public: XQViewModel* modelView(); XQItem& xqItemFromIndex(const QModelIndex& index ); + void toggleRowsHidden(int fstRow, int lstRow ); + protected: void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;