fixed selection crashes.

This commit is contained in:
2025-09-06 16:06:47 +02:00
parent 89c671295f
commit 0fe15d6043
5 changed files with 39 additions and 28 deletions

View File

@@ -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 } );
}
}

View File

@@ -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: " <<section.startIndex().data().toString() << ": " << lastRow(section);
}
*/
// wir gehen rückwärts, weil wir da nur einen vergleich brauchen
// und uns den test mit lastRow() sparen können.
@@ -151,7 +145,7 @@ const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const
const XQModelSection& XQSectionManager::createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode)
{
const QString& sectionKey = sheetNode->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);

View File

@@ -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();

View File

@@ -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 );