aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c9
-rw-r--r--dive.h2
-rw-r--r--qt-ui/mainwindow.cpp12
-rw-r--r--qt-ui/mainwindow.h3
-rw-r--r--qt-ui/mainwindow.ui37
-rw-r--r--qt-ui/modeldelegates.cpp3
-rw-r--r--qt-ui/models.cpp12
-rw-r--r--qt-ui/models.h6
8 files changed, 45 insertions, 39 deletions
diff --git a/dive.c b/dive.c
index 34025d68c..2c2307e41 100644
--- a/dive.c
+++ b/dive.c
@@ -1810,6 +1810,15 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
return res;
}
+int get_index_for_dive(struct dive *dive) {
+ int i;
+ struct dive *d;
+ for_each_dive(i, d)
+ if (d == dive)
+ return i;
+ return -1;
+}
+
struct dive *find_dive_including(timestamp_t when)
{
int i;
diff --git a/dive.h b/dive.h
index f2153587f..c13cac0aa 100644
--- a/dive.h
+++ b/dive.h
@@ -350,6 +350,8 @@ struct dive {
struct divecomputer dc;
};
+extern int get_index_for_dive(struct dive *dive);
+
static inline int dive_has_gps_location(struct dive *dive)
{
return dive->latitude.udeg || dive->longitude.udeg;
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 9901e4186..ae2794e3c 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -23,6 +23,7 @@
#include "../divelist.h"
#include "../pref.h"
#include "modeldelegates.h"
+#include "models.h"
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
model(new DiveTripModel(this)),
@@ -31,11 +32,22 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
ui->setupUi(this);
sortModel->setSourceModel(model);
ui->ListWidget->setModel(sortModel);
+ connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex)));
setWindowIcon(QIcon(":subsurface-icon"));
readSettings();
}
+void MainWindow::diveSelected(const QModelIndex& index)
+{
+ struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
+
+ if (dive)
+ selected_dive = get_index_for_dive(dive);
+
+ // Here should be the code to update the other widgets.
+}
+
void MainWindow::on_actionNew_triggered()
{
qDebug("actionNew");
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index eece91ade..e94cb5b7c 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -8,6 +8,7 @@
#define MAINWINDOW_H
#include <QMainWindow>
+#include <QModelIndex>
class QSortFilterProxyModel;
class DiveTripModel;
@@ -66,6 +67,8 @@ private Q_SLOTS:
void on_actionAboutSubsurface_triggered();
void on_actionUserManual_triggered();
+ void diveSelected(const QModelIndex& index);
+
protected:
void closeEvent(QCloseEvent *);
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index 1d31f1cd3..fe97d98b4 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -57,45 +57,14 @@
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);
}
-
-/*
- QTreeView::branch {
- background: palette(base);
- }
-
- QTreeView::branch:has-siblings:!adjoins-item {
- background: cyan;
- }
-
- QTreeView::branch:has-siblings:adjoins-item {
- background: red;
- }
-
- QTreeView::branch:!has-children:!has-siblings:adjoins-item {
- background: blue;
- }
-
- QTreeView::branch:closed:has-children:has-siblings {
- background: pink;
- }
-
- QTreeView::branch:has-children:!has-siblings:closed {
- background: gray;
- }
-
- QTreeView::branch:open:has-children:has-siblings {
- background: magenta;
- }
-
- QTreeView::branch:open:has-children:!has-siblings {
- background: green;
- }
-*/
</string>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 0b3231583..33c1717e6 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -22,10 +22,11 @@ StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);
+
if (!index.isValid())
return;
- QVariant value = index.model()->data(index, Qt::DisplayRole);
+ QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE);
if (!value.isValid())
return;
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 061ffe418..bdc3a7576 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -490,11 +490,17 @@ QVariant DiveItem::data(int column, int role) const
case LOCATION:
retVal = QString(dive->location);
break;
- case RATING:
- retVal = dive->rating;
- break;
}
}
+
+ if(role == STAR_ROLE){
+ retVal = dive->rating;
+ }
+
+ if(role == DIVE_ROLE){
+ retVal = QVariant::fromValue<void*>(dive);
+ }
+
return retVal;
}
diff --git a/qt-ui/models.h b/qt-ui/models.h
index d063874d3..307cdf5c3 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -82,7 +82,11 @@ private:
struct TreeItemDT {
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
public:
- enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
+ enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT,
+ SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, DIVE, COLUMNS };
+
+ enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE};
+
virtual ~TreeItemDT();
int columnCount() const {
return COLUMNS;