Added code to Select a dive, fixed minor annoyances.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-05-02 20:32:57 -03:00 committed by Dirk Hohndel
parent 82b1b04920
commit 696c9ccacd
8 changed files with 45 additions and 39 deletions

9
dive.c
View file

@ -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;

2
dive.h
View file

@ -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;

View file

@ -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");

View file

@ -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 *);

View file

@ -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>

View file

@ -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;

View file

@ -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;
}

View file

@ -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;