fixed selection crashes.
This commit is contained in:
@@ -91,26 +91,26 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content
|
|||||||
|
|
||||||
void XQChildModel::initContextMenu()
|
void XQChildModel::initContextMenu()
|
||||||
{
|
{
|
||||||
|
|
||||||
_sections.dump();
|
|
||||||
|
|
||||||
// __fixme! add a menu title
|
// __fixme! add a menu title
|
||||||
_contextMenu->clear();
|
_contextMenu->clear();
|
||||||
|
|
||||||
const QModelIndex& curIdx = _treeTable->currentIndex();
|
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( "icn11Dummy", "Undo", XQCommand::cmdUndo, _undoStack->canUndo() );
|
||||||
_contextMenu->addAction( "icn17Dummy", "Redo", XQCommand::cmdRedo, _undoStack->canRedo() );
|
_contextMenu->addAction( "icn17Dummy", "Redo", XQCommand::cmdRedo, _undoStack->canRedo() );
|
||||||
|
|
||||||
_contextMenu->addAction( "icn58Dummy", "Cut", XQCommand::cmdCut, hasSel );
|
// editieren nur wenns kein header ist.
|
||||||
_contextMenu->addAction( "icn61Dummy", "Paste", XQCommand::cmdPaste, canPaste );
|
if ( !xqItemFromIndex(curIdx).isHeaderStyle() )
|
||||||
_contextMenu->addAction( "icn55Dummy", "Copy", XQCommand::cmdCopy, hasSel );
|
{
|
||||||
//_contextMenu->addAction( "icn35Dummy", "Move", XQCommand::cmdMove, hasSel );
|
bool hasSel = curIdx.isValid() && _treeTable->selectionModel()->hasSelection();
|
||||||
_contextMenu->addAction( "icn70Dummy", "New", XQCommand::cmdNew, hasSel );
|
bool canPaste = _clipBoard.canPaste( curIdx );
|
||||||
_contextMenu->addAction( "icn50Dummy", "Delete", XQCommand::cmdDelete, hasSel );
|
|
||||||
|
|
||||||
|
_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 <name>' entry
|
// __fixme! set 'toggle section <name>' entry
|
||||||
//contextMenu.actions().first()->setText("<name>");
|
//contextMenu.actions().first()->setText("<name>");
|
||||||
_contextMenu->addAction( "icn29Dummy", "Hide Section", XQCommand::cmdToggleSection, true );
|
_contextMenu->addAction( "icn29Dummy", "Hide Section", XQCommand::cmdToggleSection, true );
|
||||||
|
@@ -114,7 +114,9 @@ void XQCommand::saveNodes( const QModelIndexList& list )
|
|||||||
// knoten holen
|
// knoten holen
|
||||||
const XQNodePtr& contentNode = XQItem::xqItemFromIndex( entry ).contentNode();
|
const XQNodePtr& contentNode = XQItem::xqItemFromIndex( entry ).contentNode();
|
||||||
// hier speichern wir den original knoten, nicht einen clone, wie im clipboard.
|
// 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 } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -127,12 +127,6 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey
|
|||||||
|
|
||||||
const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const
|
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
|
// wir gehen rückwärts, weil wir da nur einen vergleich brauchen
|
||||||
// und uns den test mit lastRow() sparen können.
|
// 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 XQModelSection& XQSectionManager::createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode)
|
||||||
{
|
{
|
||||||
const QString& sectionKey = sheetNode->attribute(c_ContentType);
|
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 );
|
XQModelSection section(modelIndex, sheetNode );
|
||||||
_sections.addAtKey( sectionKey, section);
|
_sections.addAtKey( sectionKey, section);
|
||||||
return sectionByKey(sectionKey);
|
return sectionByKey(sectionKey);
|
||||||
|
@@ -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)
|
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();
|
const QModelIndexList list = selection.indexes();
|
||||||
if (list.isEmpty() || selectedRows().isEmpty() )
|
if (list.isEmpty() || selectedRows().isEmpty() )
|
||||||
return QItemSelectionModel::select(selection, command);
|
return QItemSelectionModel::select(selection, command);
|
||||||
|
|
||||||
// fetch first index
|
// step 01: den ersten index bestimmen
|
||||||
QModelIndex firstValid = list.first();
|
QModelIndex firstValid = list.first();
|
||||||
if (hasSelection() )
|
if (hasSelection() )
|
||||||
firstValid = selectedRows().first();
|
firstValid = selectedRows().first();
|
||||||
|
|
||||||
//XQItem& firstItem = XQItem::xqItemFromIndex(firstValid);
|
// step 02: finde das erste item gültigem content node.
|
||||||
//if( firstItem.isValid() )
|
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;
|
QItemSelection newSelection;
|
||||||
// __fixme! das crasht!
|
|
||||||
|
|
||||||
for (const QModelIndex& idx : list)
|
for (const QModelIndex& idx : list)
|
||||||
{
|
{
|
||||||
XQNodePtr nextNode = XQItem::xqItemFromIndex(idx).contentNode();
|
XQNodePtr nextNode = XQItem::xqItemFromIndex(idx).contentNode();
|
||||||
|
@@ -39,6 +39,13 @@ void showItemList( const XQItemList& list)
|
|||||||
qDebug();
|
qDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showSelectionList( const QModelIndexList& list)
|
||||||
|
{
|
||||||
|
for(const auto& entry : list )
|
||||||
|
qDebug() << " --- SelectionList: " << entry.data().toString();
|
||||||
|
qDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Konstruktor mit parent.
|
//! Konstruktor mit parent.
|
||||||
|
|
||||||
@@ -252,6 +259,9 @@ void XQViewModel::onActionTriggered(QAction* action)
|
|||||||
QModelIndex currentIndex = treeTable()->currentIndex();
|
QModelIndex currentIndex = treeTable()->currentIndex();
|
||||||
command->setOriginIndex(currentIndex);
|
command->setOriginIndex(currentIndex);
|
||||||
// store the row positions of the selected indices
|
// store the row positions of the selected indices
|
||||||
|
|
||||||
|
qDebug() << " --- Before saveNode: " << selectionList.isEmpty();
|
||||||
|
showSelectionList(selectionList);
|
||||||
command->saveNodes( selectionList );
|
command->saveNodes( selectionList );
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user