summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-28 16:56:58 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-28 16:56:58 -0300
commitc6f84de37c33ef66f479d1adcffea6eab903c674 (patch)
tree8693cfa163a2ece07d281b8a860c650469990a12 /qt-ui
parent8394828806baf050fa833402c969139d52dc221d (diff)
downloadsubsurface-c6f84de37c33ef66f479d1adcffea6eab903c674.tar.gz
Adds the code to make the dive list behave like tree or list
This code adds the possibility to make the DiveList behave like a Tree or a List, depending on what layout is set. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divelistview.cpp6
-rw-r--r--qt-ui/models.cpp27
-rw-r--r--qt-ui/models.h5
3 files changed, 35 insertions, 3 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 4957e3374..d53fce5f5 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -22,6 +22,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
setModel(model);
+ setSortingEnabled(false);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
}
@@ -31,7 +32,10 @@ void DiveListView::reload()
QAbstractItemModel *oldModel = m->sourceModel();
if (oldModel)
oldModel->deleteLater();
- m->setSourceModel(new DiveTripModel(this));
+ DiveTripModel *tripModel = new DiveTripModel(this);
+ tripModel->setLayout(DiveTripModel::LIST);
+
+ m->setSourceModel(tripModel);
sortByColumn(0, Qt::DescendingOrder);
QModelIndex firstDiveOrTrip = m->index(0,0);
if (firstDiveOrTrip.isValid()) {
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 38ef8938c..98a84d7f9 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1003,7 +1003,6 @@ DiveTripModel::DiveTripModel(QObject* parent) :
QAbstractItemModel(parent)
{
rootItem = new TreeItemDT();
- setupModelData();
}
DiveTripModel::~DiveTripModel()
@@ -1096,6 +1095,11 @@ void DiveTripModel::setupModelData()
{
int i = dive_table.nr;
+ if (rowCount()){
+ beginRemoveRows(QModelIndex(), 0, rowCount()-1);
+ endRemoveRows();
+ }
+
while (--i >= 0) {
struct dive* dive = get_dive(i);
update_cylinder_related_info(dive);
@@ -1104,11 +1108,14 @@ void DiveTripModel::setupModelData()
DiveItem* diveItem = new DiveItem();
diveItem->dive = dive;
- if (!trip) {
+ if (!trip || currentLayout == LIST) {
diveItem->parent = rootItem;
rootItem->children.push_back(diveItem);
continue;
}
+ if (currentLayout == LIST)
+ continue;
+
if (!trips.keys().contains(trip)) {
TripItem* tripItem = new TripItem();
tripItem->trip = trip;
@@ -1121,4 +1128,20 @@ void DiveTripModel::setupModelData()
TripItem* tripItem = trips[trip];
tripItem->children.push_back(diveItem);
}
+
+ if (rowCount()){
+ beginInsertRows(QModelIndex(), 0, rowCount()-1);
+ endInsertRows();
+ }
+}
+
+DiveTripModel::Layout DiveTripModel::layout() const
+{
+ return currentLayout;
+}
+
+void DiveTripModel::setLayout(DiveTripModel::Layout layout)
+{
+ currentLayout = layout;
+ setupModelData();
}
diff --git a/qt-ui/models.h b/qt-ui/models.h
index f51566c1b..b4eb8d953 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -144,6 +144,8 @@ class DiveTripModel : public QAbstractItemModel
Q_OBJECT
public:
+ enum Layout{TREE, LIST};
+
DiveTripModel(QObject *parent = 0);
~DiveTripModel();
@@ -155,11 +157,14 @@ public:
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
/*reimp*/ QModelIndex parent(const QModelIndex &child) const;
+ Layout layout() const;
+ void setLayout(Layout layout);
private:
void setupModelData();
TreeItemDT *rootItem;
QMap<dive_trip_t*, TripItem*> trips;
+ Layout currentLayout;
};
#endif