aboutsummaryrefslogtreecommitdiff
path: root/mapman/src/groupview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mapman/src/groupview.cpp')
-rw-r--r--mapman/src/groupview.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/mapman/src/groupview.cpp b/mapman/src/groupview.cpp
index 32917d4..721917f 100644
--- a/mapman/src/groupview.cpp
+++ b/mapman/src/groupview.cpp
@@ -6,6 +6,7 @@
#include <QTableView>
#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
#include <QPushButton>
#include <QLineEdit>
#include <QSpinBox>
@@ -17,7 +18,6 @@
#include <QSpacerItem>
#include <QHeaderView>
#include <QMessageBox>
-#include <qmessagebox.h>
group_view::group_view() : QMdiSubWindow()
{
@@ -27,8 +27,11 @@ group_view::group_view() : QMdiSubWindow()
auto l1 = new QVBoxLayout();
leftpane->setLayout(l1);
tv = new QTableView();
- m = new QStandardItemModel();
- tv->setModel(m);
+ m = new QStandardItemModel(this);
+ mf = new QSortFilterProxyModel(this);
+ mf->setSourceModel(m);
+ mf->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
+ tv->setModel(mf);
tv->setColumnHidden(3, true);
tv->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
tv->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
@@ -38,7 +41,7 @@ group_view::group_view() : QMdiSubWindow()
bool dirty = oldidx.isValid() && this->dirty;
if (oldidx.isValid())
{
- int64_t oldgid = m->item(oldidx.row(), 3)->data(Qt::ItemDataRole::DisplayRole).toLongLong();
+ int64_t oldgid = mf->data(oldidx.siblingAtColumn(3), Qt::ItemDataRole::DisplayRole).toLongLong();
auto oldgroup = l->get_group(oldgid);
dirty |= tetitle->text() != QString::fromStdString(oldgroup.title);
dirty |= teauthor->text() != QString::fromStdString(oldgroup.author);
@@ -63,8 +66,11 @@ group_view::group_view() : QMdiSubWindow()
auto l2 = new QHBoxLayout();
pbadd = new QPushButton("+");
pbrem = new QPushButton("-");
+ tefilter = new QLineEdit();
+ tefilter->setPlaceholderText("Filter");
connect(pbadd, &QPushButton::pressed, this, &group_view::add_group);
connect(pbrem, &QPushButton::pressed, this, &group_view::rem_group);
+ l2->addWidget(tefilter);
l2->addWidget(pbadd);
l2->addWidget(pbrem);
l1->addLayout(l2);
@@ -110,6 +116,7 @@ group_view::group_view() : QMdiSubWindow()
sp->setCollapsible(1, false);
l = nullptr;
dirty = false;
+ connect(tefilter, &QLineEdit::textChanged, mf, &QSortFilterProxyModel::setFilterFixedString);
this->setWindowTitle("Map art listings");
this->setAttribute(Qt::WA_DeleteOnClose, false);
}
@@ -143,7 +150,7 @@ void group_view::rem_group()
{
if (!tv->currentIndex().isValid())
return;
- int64_t curgid = m->item(tv->currentIndex().row(), 3)->data(Qt::ItemDataRole::DisplayRole).toLongLong();
+ int64_t curgid = mf->data(tv->currentIndex().siblingAtColumn(3), Qt::ItemDataRole::DisplayRole).toLongLong();
l->remove_group(curgid);
refresh_list();
}
@@ -152,7 +159,7 @@ void group_view::update_fields()
{
if (!tv->currentIndex().isValid())
return;
- int64_t curgid = m->item(tv->currentIndex().row(), 3)->data(Qt::ItemDataRole::DisplayRole).toLongLong();
+ int64_t curgid = mf->data(tv->currentIndex().siblingAtColumn(3), Qt::ItemDataRole::DisplayRole).toLongLong();
current_group = l->get_group(curgid);
auto &g = current_group;
tetitle->setText(QString::fromStdString(g.title));
@@ -179,7 +186,7 @@ void group_view::update_library()
{
if (!tv->currentIndex().isValid())
return;
- int64_t curgid = m->item(tv->currentIndex().row(), 3)->data(Qt::ItemDataRole::DisplayRole).toLongLong();
+ int64_t curgid = mf->data(tv->currentIndex().siblingAtColumn(3), Qt::ItemDataRole::DisplayRole).toLongLong();
auto &g = current_group;
g.title = tetitle->text().toStdString();
g.author = teauthor->text().toStdString();
@@ -193,8 +200,11 @@ void group_view::update_library()
void group_view::refresh_list()
{
int64_t curgid = -1;
- if (tv->currentIndex().isValid())
- curgid = m->item(tv->currentIndex().row(), 3)->data(Qt::ItemDataRole::DisplayRole).toLongLong();
+ if (tv->currentIndex().isValid() && tv->currentIndex().siblingAtColumn(3).isValid())
+ {
+ auto idx = tv->currentIndex().siblingAtColumn(3);
+ curgid = mf->data(idx, Qt::ItemDataRole::DisplayRole).toLongLong();
+ }
m->clear();
m->setHorizontalHeaderLabels({"Title", "Author(s)", "Dimension", "id"});
tv->setColumnHidden(3, true);