mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
82b1b04920
commit
696c9ccacd
8 changed files with 45 additions and 39 deletions
9
dive.c
9
dive.c
|
@ -1810,6 +1810,15 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
|
||||||
return res;
|
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)
|
struct dive *find_dive_including(timestamp_t when)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
2
dive.h
2
dive.h
|
@ -350,6 +350,8 @@ struct dive {
|
||||||
struct divecomputer dc;
|
struct divecomputer dc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int get_index_for_dive(struct dive *dive);
|
||||||
|
|
||||||
static inline int dive_has_gps_location(struct dive *dive)
|
static inline int dive_has_gps_location(struct dive *dive)
|
||||||
{
|
{
|
||||||
return dive->latitude.udeg || dive->longitude.udeg;
|
return dive->latitude.udeg || dive->longitude.udeg;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
#include "../pref.h"
|
#include "../pref.h"
|
||||||
#include "modeldelegates.h"
|
#include "modeldelegates.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
model(new DiveTripModel(this)),
|
model(new DiveTripModel(this)),
|
||||||
|
@ -31,11 +32,22 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
sortModel->setSourceModel(model);
|
sortModel->setSourceModel(model);
|
||||||
ui->ListWidget->setModel(sortModel);
|
ui->ListWidget->setModel(sortModel);
|
||||||
|
connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex)));
|
||||||
|
|
||||||
setWindowIcon(QIcon(":subsurface-icon"));
|
setWindowIcon(QIcon(":subsurface-icon"));
|
||||||
readSettings();
|
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()
|
void MainWindow::on_actionNew_triggered()
|
||||||
{
|
{
|
||||||
qDebug("actionNew");
|
qDebug("actionNew");
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
class DiveTripModel;
|
class DiveTripModel;
|
||||||
|
@ -66,6 +67,8 @@ private Q_SLOTS:
|
||||||
void on_actionAboutSubsurface_triggered();
|
void on_actionAboutSubsurface_triggered();
|
||||||
void on_actionUserManual_triggered();
|
void on_actionUserManual_triggered();
|
||||||
|
|
||||||
|
void diveSelected(const QModelIndex& index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
|
|
|
@ -57,45 +57,14 @@
|
||||||
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);
|
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>
|
</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
<property name="rootIsDecorated">
|
<property name="rootIsDecorated">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -22,10 +22,11 @@ StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
|
||||||
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QVariant value = index.model()->data(index, Qt::DisplayRole);
|
QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE);
|
||||||
|
|
||||||
if (!value.isValid())
|
if (!value.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -490,11 +490,17 @@ QVariant DiveItem::data(int column, int role) const
|
||||||
case LOCATION:
|
case LOCATION:
|
||||||
retVal = QString(dive->location);
|
retVal = QString(dive->location);
|
||||||
break;
|
break;
|
||||||
case RATING:
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(role == STAR_ROLE){
|
||||||
retVal = dive->rating;
|
retVal = dive->rating;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(role == DIVE_ROLE){
|
||||||
|
retVal = QVariant::fromValue<void*>(dive);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,11 @@ private:
|
||||||
struct TreeItemDT {
|
struct TreeItemDT {
|
||||||
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
|
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
|
||||||
public:
|
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();
|
virtual ~TreeItemDT();
|
||||||
int columnCount() const {
|
int columnCount() const {
|
||||||
return COLUMNS;
|
return COLUMNS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue