summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/tab-widgets/TabDiveComputer.cpp11
-rw-r--r--desktop-widgets/tab-widgets/TabDiveComputer.h6
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp14
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h5
-rw-r--r--desktop-widgets/tableview.cpp7
5 files changed, 27 insertions, 16 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveComputer.cpp b/desktop-widgets/tab-widgets/TabDiveComputer.cpp
index 104bee0c6..d4b0f5cce 100644
--- a/desktop-widgets/tab-widgets/TabDiveComputer.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveComputer.cpp
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: GPL-2.0
#include "TabDiveComputer.h"
#include "ui_TabDiveExtraInfo.h"
+#include "qt-models/divecomputermodel.h"
TabDiveComputer::TabDiveComputer(QWidget *parent) : TabBase(parent)
{
ui.setupUi(this);
- sortedModel.setSourceModel(&model);
- ui.devices->setModel(&sortedModel);
+
+ DiveComputerModel *model = new DiveComputerModel(this);
+ sortedModel = new DiveComputerSortedModel(this);
+
+ sortedModel->setSourceModel(model);
+ ui.devices->setModel(sortedModel);
ui.devices->view()->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.devices->view()->setSelectionMode(QAbstractItemView::SingleSelection);
ui.devices->view()->setSortingEnabled(true);
@@ -29,5 +34,5 @@ void TabDiveComputer::tableClicked(const QModelIndex &index)
return;
if (index.column() == DiveComputerModel::REMOVE)
- sortedModel.remove(index);
+ sortedModel->remove(index);
}
diff --git a/desktop-widgets/tab-widgets/TabDiveComputer.h b/desktop-widgets/tab-widgets/TabDiveComputer.h
index bdbb9097c..f5f6900c3 100644
--- a/desktop-widgets/tab-widgets/TabDiveComputer.h
+++ b/desktop-widgets/tab-widgets/TabDiveComputer.h
@@ -4,7 +4,8 @@
#include "TabBase.h"
#include "ui_TabDiveComputer.h"
-#include "qt-models/divecomputermodel.h"
+
+class DiveComputerSortedModel;
class TabDiveComputer : public TabBase {
Q_OBJECT
@@ -16,8 +17,7 @@ public slots:
void tableClicked(const QModelIndex &index);
private:
Ui::TabDiveComputer ui;
- DiveComputerModel model;
- DiveComputerSortedModel sortedModel;
+ DiveComputerSortedModel *sortedModel;
};
#endif
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp
index 87bed8f92..60f82a0ae 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp
@@ -12,8 +12,10 @@
TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent)
{
ui.setupUi(this);
+
+ model = new DiveSiteSortedModel(this);
ui.diveSites->setTitle(tr("Dive sites"));
- ui.diveSites->setModel(&model);
+ ui.diveSites->setModel(model);
// Default: sort by name
ui.diveSites->view()->sortByColumn(LocationInformationModel::NAME, Qt::AscendingOrder);
ui.diveSites->view()->setSortingEnabled(true);
@@ -44,7 +46,7 @@ void TabDiveSite::clear()
void TabDiveSite::diveSiteClicked(const QModelIndex &index)
{
- struct dive_site *ds = model.getDiveSite(index);
+ struct dive_site *ds = model->getDiveSite(index);
if (!ds)
return;
switch (index.column()) {
@@ -80,7 +82,7 @@ void TabDiveSite::diveSiteAdded(struct dive_site *, int idx)
if (idx < 0)
return;
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, LocationInformationModel::NAME);
- QModelIndex localIdx = model.mapFromSource(globalIdx);
+ QModelIndex localIdx = model->mapFromSource(globalIdx);
ui.diveSites->view()->setCurrentIndex(localIdx);
ui.diveSites->view()->edit(localIdx);
}
@@ -91,7 +93,7 @@ void TabDiveSite::diveSiteChanged(struct dive_site *ds, int field)
if (idx < 0)
return;
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, field);
- QModelIndex localIdx = model.mapFromSource(globalIdx);
+ QModelIndex localIdx = model->mapFromSource(globalIdx);
ui.diveSites->view()->scrollTo(localIdx);
}
@@ -102,7 +104,7 @@ void TabDiveSite::on_purgeUnused_clicked()
void TabDiveSite::on_filterText_textChanged(const QString &text)
{
- model.setFilter(text);
+ model->setFilter(text);
}
QVector<dive_site *> TabDiveSite::selectedDiveSites()
@@ -111,7 +113,7 @@ QVector<dive_site *> TabDiveSite::selectedDiveSites()
QVector<dive_site *> sites;
sites.reserve(indices.size());
for (const QModelIndex &idx: indices) {
- struct dive_site *ds = model.getDiveSite(idx);
+ struct dive_site *ds = model->getDiveSite(idx);
sites.append(ds);
}
return sites;
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.h b/desktop-widgets/tab-widgets/TabDiveSite.h
index c5d69eecc..d123dc28e 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.h
+++ b/desktop-widgets/tab-widgets/TabDiveSite.h
@@ -4,7 +4,8 @@
#include "TabBase.h"
#include "ui_TabDiveSite.h"
-#include "qt-models/divelocationmodel.h"
+
+class DiveSiteSortedModel;
class TabDiveSite : public TabBase {
Q_OBJECT
@@ -22,7 +23,7 @@ private slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private:
Ui::TabDiveSite ui;
- DiveSiteSortedModel model;
+ DiveSiteSortedModel *model;
QVector<dive_site *> selectedDiveSites();
void hideEvent(QHideEvent *) override;
void showEvent(QShowEvent *) override;
diff --git a/desktop-widgets/tableview.cpp b/desktop-widgets/tableview.cpp
index 2a6a2d535..c5dbd453e 100644
--- a/desktop-widgets/tableview.cpp
+++ b/desktop-widgets/tableview.cpp
@@ -81,11 +81,14 @@ TableView::~TableView()
s.remove("");
} else if (ui.tableView->model()) {
for (int i = 0; i < ui.tableView->model()->columnCount(); i++) {
- if (ui.tableView->columnWidth(i) == defaultColumnWidth(i))
+ if (ui.tableView->columnWidth(i) == defaultColumnWidth(i)) {
s.remove(QString("colwidth%1").arg(i));
- else
+ } else {
s.setValue(QString("colwidth%1").arg(i), ui.tableView->columnWidth(i));
+ }
}
+ } else {
+ qWarning("TableView %s without model", qPrintable(objectName()));
}
s.endGroup();
}