66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
/***************************************************************************
|
|
|
|
source::worx xtree
|
|
Copyright © 2024-2025 c.holzheuer
|
|
christoph.holzheuer@gmail.com
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#include <xqselectionmodel.h>
|
|
#include <xqitem.h>
|
|
|
|
XQSelectionModel::XQSelectionModel(QAbstractItemModel* model)
|
|
: QItemSelectionModel(model)
|
|
{
|
|
|
|
}
|
|
|
|
XQSelectionModel::XQSelectionModel(QAbstractItemModel* model, QObject* parent)
|
|
: QItemSelectionModel(model, parent)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQSelectionModel::select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command)
|
|
{
|
|
// step #0: fetch selected indices.
|
|
QModelIndexList list = selection.indexes();
|
|
if (list.isEmpty() || selectedRows().isEmpty() )
|
|
return QItemSelectionModel::select(selection, command);
|
|
|
|
// fetch first index
|
|
QModelIndex firstValid = list.first();
|
|
if (hasSelection() )
|
|
firstValid = selectedRows().first();
|
|
|
|
//XQItem& firstItem = XQItem::xqItemFromIndex(firstValid);
|
|
//if( firstItem.isValid() )
|
|
{
|
|
|
|
XQNodePtr firstNode = XQItem::xqItemFromIndex(firstValid).contentNode();
|
|
QItemSelection newSelection;
|
|
// __fixme! das crasht!
|
|
|
|
for (const QModelIndex& idx : list)
|
|
{
|
|
XQNodePtr nextNode = XQItem::xqItemFromIndex(idx).contentNode();
|
|
if (!nextNode || idx.data().toString().isEmpty() || nextNode->tag_name() != firstNode->tag_name() )
|
|
break;
|
|
newSelection.select(idx, idx);
|
|
}
|
|
return QItemSelectionModel::select(newSelection, command);
|
|
}
|
|
|
|
|
|
QItemSelectionModel::select(selection, command);
|
|
|
|
}
|