diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/mainwindow.cpp | 12 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 3 | ||||
-rw-r--r-- | qt-ui/mainwindow.ui | 37 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 12 | ||||
-rw-r--r-- | qt-ui/models.h | 6 |
6 files changed, 34 insertions, 39 deletions
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; |