mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
More work on bug 111, Sorting works as it should.
Sorting is now working as it should, changing from table to tree, keeping the selection from table to tree ( but there's a regression on tree to table conversion, I'll try to fix it in the following commit. ). this commit also cleans a lot of boilerplate code that I wrote to bypass a graphics bug, that I seem to have correctly fixed in this version. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
f46a2d56bc
commit
9cc04c1ca6
2 changed files with 33 additions and 63 deletions
|
@ -32,24 +32,31 @@ void DiveListView::headerClicked(int i )
|
||||||
QItemSelection oldSelection = selectionModel()->selection();
|
QItemSelection oldSelection = selectionModel()->selection();
|
||||||
QList<struct dive*> currentSelectedDives;
|
QList<struct dive*> currentSelectedDives;
|
||||||
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
|
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
|
||||||
|
if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
|
||||||
|
continue;
|
||||||
|
|
||||||
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
||||||
if (d){ // can also be a trip, so test.
|
if (d){
|
||||||
currentSelectedDives.push_back(d);
|
currentSelectedDives.push_back(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST);
|
// clear the model, repopulate with new indexes.
|
||||||
|
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
|
||||||
selectionModel()->clearSelection();
|
selectionModel()->clearSelection();
|
||||||
Q_FOREACH(struct dive *d, currentSelectedDives){
|
|
||||||
QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::DIVE_ROLE, QVariant::fromValue<void*>(d), 1, Qt::MatchRecursive);
|
|
||||||
selectionModel()->select(match.first(), QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// repopulat the selections.
|
||||||
|
Q_FOREACH(struct dive *d, currentSelectedDives){
|
||||||
|
QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::NR, d->number, 1, Qt::MatchRecursive);
|
||||||
|
QModelIndex idx = match.first();
|
||||||
|
selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort.
|
||||||
sortByColumn(i);
|
sortByColumn(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::reload(DiveTripModel::Layout layout)
|
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
{
|
{
|
||||||
header()->setClickable(true);
|
header()->setClickable(true);
|
||||||
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
||||||
|
@ -58,10 +65,15 @@ void DiveListView::reload(DiveTripModel::Layout layout)
|
||||||
QAbstractItemModel *oldModel = m->sourceModel();
|
QAbstractItemModel *oldModel = m->sourceModel();
|
||||||
if (oldModel)
|
if (oldModel)
|
||||||
oldModel->deleteLater();
|
oldModel->deleteLater();
|
||||||
|
|
||||||
DiveTripModel *tripModel = new DiveTripModel(this);
|
DiveTripModel *tripModel = new DiveTripModel(this);
|
||||||
tripModel->setLayout(layout);
|
tripModel->setLayout(layout);
|
||||||
|
|
||||||
m->setSourceModel(tripModel);
|
m->setSourceModel(tripModel);
|
||||||
|
|
||||||
|
if(!forceSort)
|
||||||
|
return;
|
||||||
|
|
||||||
sortByColumn(0, Qt::DescendingOrder);
|
sortByColumn(0, Qt::DescendingOrder);
|
||||||
QModelIndex firstDiveOrTrip = m->index(0,0);
|
QModelIndex firstDiveOrTrip = m->index(0,0);
|
||||||
if (firstDiveOrTrip.isValid()) {
|
if (firstDiveOrTrip.isValid()) {
|
||||||
|
@ -112,37 +124,6 @@ void DiveListView::toggleColumnVisibilityByIndex()
|
||||||
setColumnHidden(action->property("index").toInt(), !action->isChecked());
|
setColumnHidden(action->property("index").toInt(), !action->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
|
|
||||||
{
|
|
||||||
//if (mouseClickSelection)
|
|
||||||
QTreeView::setSelection(rect, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiveListView::mousePressEvent(QMouseEvent* event)
|
|
||||||
{
|
|
||||||
mouseClickSelection = true;
|
|
||||||
QTreeView::mousePressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiveListView::mouseReleaseEvent(QMouseEvent* event)
|
|
||||||
{
|
|
||||||
mouseClickSelection = false;
|
|
||||||
QTreeView::mouseReleaseEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiveListView::keyPressEvent(QKeyEvent* event)
|
|
||||||
{
|
|
||||||
if (event->modifiers())
|
|
||||||
mouseClickSelection = true;
|
|
||||||
QTreeView::keyPressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiveListView::keyReleaseEvent(QKeyEvent* event)
|
|
||||||
{
|
|
||||||
mouseClickSelection = false;
|
|
||||||
QWidget::keyReleaseEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
|
void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
{
|
{
|
||||||
if (!current.isValid())
|
if (!current.isValid())
|
||||||
|
@ -163,21 +144,16 @@ void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex&
|
||||||
|
|
||||||
void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
||||||
{
|
{
|
||||||
QList<QModelIndex> parents;
|
QItemSelection newSelected = selected.size() ? selected : selectionModel()->selection();
|
||||||
Q_FOREACH(const QModelIndex& index, deselected.indexes()) {
|
QItemSelection newDeselected = deselected;
|
||||||
const QAbstractItemModel *model = index.model();
|
|
||||||
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
|
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||||
if (!dive) { // it's a trip!
|
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||||
if (model->rowCount(index)) {
|
|
||||||
expand(index); // leave this - even if it looks like it shouldn't be here. looks like I've found a Qt bug.
|
Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
|
||||||
// the subselection is removed, but the painting is not. this cleans the area.
|
if(index.column() != 0)
|
||||||
}
|
continue;
|
||||||
} else if (!parents.contains(index.parent())) {
|
|
||||||
parents.push_back(index.parent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_FOREACH(const QModelIndex& index, selected.indexes()) {
|
|
||||||
const QAbstractItemModel *model = index.model();
|
const QAbstractItemModel *model = index.model();
|
||||||
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
|
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
|
||||||
if (!dive) { // it's a trip!
|
if (!dive) { // it's a trip!
|
||||||
|
@ -190,11 +166,10 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
||||||
expand(index);
|
expand(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!parents.contains(index.parent())) {
|
|
||||||
parents.push_back(index.parent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_FOREACH(const QModelIndex& index, parents)
|
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||||
expand(index);
|
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||||
|
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,7 @@ public:
|
||||||
DiveListView(QWidget *parent = 0);
|
DiveListView(QWidget *parent = 0);
|
||||||
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||||
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
|
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void reload(DiveTripModel::Layout layout = DiveTripModel::TREE, bool forceSort = true);
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
|
||||||
void keyPressEvent(QKeyEvent* event);
|
|
||||||
void keyReleaseEvent(QKeyEvent*);
|
|
||||||
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
|
|
||||||
void reload(DiveTripModel::Layout layout = DiveTripModel::TREE);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void toggleColumnVisibilityByIndex();
|
void toggleColumnVisibilityByIndex();
|
||||||
|
|
Loading…
Add table
Reference in a new issue