diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index 1fe71fb..f95aed2 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -91,26 +91,26 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content void XQChildModel::initContextMenu() { - - _sections.dump(); - // __fixme! add a menu title _contextMenu->clear(); const QModelIndex& curIdx = _treeTable->currentIndex(); - bool hasSel = curIdx.isValid() && _treeTable->selectionModel()->hasSelection(); - bool canPaste = _clipBoard.canPaste( curIdx ); - _contextMenu->addAction( "icn11Dummy", "Undo", XQCommand::cmdUndo, _undoStack->canUndo() ); _contextMenu->addAction( "icn17Dummy", "Redo", XQCommand::cmdRedo, _undoStack->canRedo() ); - _contextMenu->addAction( "icn58Dummy", "Cut", XQCommand::cmdCut, hasSel ); - _contextMenu->addAction( "icn61Dummy", "Paste", XQCommand::cmdPaste, canPaste ); - _contextMenu->addAction( "icn55Dummy", "Copy", XQCommand::cmdCopy, hasSel ); - //_contextMenu->addAction( "icn35Dummy", "Move", XQCommand::cmdMove, hasSel ); - _contextMenu->addAction( "icn70Dummy", "New", XQCommand::cmdNew, hasSel ); - _contextMenu->addAction( "icn50Dummy", "Delete", XQCommand::cmdDelete, hasSel ); + // editieren nur wenns kein header ist. + if ( !xqItemFromIndex(curIdx).isHeaderStyle() ) + { + bool hasSel = curIdx.isValid() && _treeTable->selectionModel()->hasSelection(); + bool canPaste = _clipBoard.canPaste( curIdx ); + _contextMenu->addAction( "icn58Dummy", "Cut", XQCommand::cmdCut, hasSel ); + _contextMenu->addAction( "icn61Dummy", "Paste", XQCommand::cmdPaste, canPaste ); + _contextMenu->addAction( "icn55Dummy", "Copy", XQCommand::cmdCopy, hasSel ); + //_contextMenu->addAction( "icn35Dummy", "Move", XQCommand::cmdMove, hasSel ); + _contextMenu->addAction( "icn70Dummy", "New", XQCommand::cmdNew, hasSel ); + _contextMenu->addAction( "icn50Dummy", "Delete", XQCommand::cmdDelete, hasSel ); + } // __fixme! set 'toggle section ' entry //contextMenu.actions().first()->setText(""); _contextMenu->addAction( "icn29Dummy", "Hide Section", XQCommand::cmdToggleSection, true ); diff --git a/src/model/xqcommand.cpp b/src/model/xqcommand.cpp index 33fa559..c6081e2 100644 --- a/src/model/xqcommand.cpp +++ b/src/model/xqcommand.cpp @@ -114,7 +114,9 @@ void XQCommand::saveNodes( const QModelIndexList& list ) // knoten holen const XQNodePtr& contentNode = XQItem::xqItemFromIndex( entry ).contentNode(); // hier speichern wir den original knoten, nicht einen clone, wie im clipboard. - push_back( {entry.row(), contentNode->own_pos(), contentNode } ); + // obacht: bei einem Header is der content node null + if(contentNode) + push_back( {entry.row(), contentNode->own_pos(), contentNode } ); } } diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index 041d1f1..cd67d6e 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -127,12 +127,6 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const { - /* - for( const XQModelSection& section : _sections ) - { - qDebug() << " --- sectionByRow: " <attribute(c_ContentType); - qDebug() << " --- create Section: " << sectionKey << ": " << modelIndex.data().toString(); + //qDebug() << " --- create Section: " << sectionKey << ": " << modelIndex.data().toString(); XQModelSection section(modelIndex, sheetNode ); _sections.addAtKey( sectionKey, section); return sectionByKey(sectionKey); diff --git a/src/model/xqselectionmodel.cpp b/src/model/xqselectionmodel.cpp index 91144f7..bced9c2 100644 --- a/src/model/xqselectionmodel.cpp +++ b/src/model/xqselectionmodel.cpp @@ -35,28 +35,33 @@ XQSelectionModel::XQSelectionModel(QAbstractItemModel* model, QObject* parent) } -//! firz +//! jetzt die selektierten indices, wie die basisklasse, aber nur die innerhalt einer section. void XQSelectionModel::select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command) { - // step #0: fetch selected indices. + // step #0: die ursprüngliche selection bestimmen const QModelIndexList list = selection.indexes(); if (list.isEmpty() || selectedRows().isEmpty() ) return QItemSelectionModel::select(selection, command); - // fetch first index + // step 01: den ersten index bestimmen QModelIndex firstValid = list.first(); if (hasSelection() ) firstValid = selectedRows().first(); - //XQItem& firstItem = XQItem::xqItemFromIndex(firstValid); - //if( firstItem.isValid() ) + // step 02: finde das erste item gültigem content node. + XQNodePtr firstNode = XQItem::xqItemFromIndex(firstValid).contentNode(); + while( !firstNode) { + firstValid = firstValid.siblingAtRow( firstValid.row()+1); + firstNode = XQItem::xqItemFromIndex(firstValid).contentNode(); + } - XQNodePtr firstNode = XQItem::xqItemFromIndex(firstValid).contentNode(); + // step 03: selektiere nur knoten, die den gleichen tag_name haben, sich also + // in der selben section befinden + if( firstNode ) + { QItemSelection newSelection; - // __fixme! das crasht! - for (const QModelIndex& idx : list) { XQNodePtr nextNode = XQItem::xqItemFromIndex(idx).contentNode(); diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index f037628..cf55e79 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -39,6 +39,13 @@ void showItemList( const XQItemList& list) qDebug(); } +void showSelectionList( const QModelIndexList& list) +{ + for(const auto& entry : list ) + qDebug() << " --- SelectionList: " << entry.data().toString(); + qDebug(); +} + //! Konstruktor mit parent. @@ -252,6 +259,9 @@ void XQViewModel::onActionTriggered(QAction* action) QModelIndex currentIndex = treeTable()->currentIndex(); command->setOriginIndex(currentIndex); // store the row positions of the selected indices + + qDebug() << " --- Before saveNode: " << selectionList.isEmpty(); + showSelectionList(selectionList); command->saveNodes( selectionList );