summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-09-02 16:21:08 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-09-02 16:21:08 -0300
commit5666f6573e70c3b472703bddeba240c202fe00de (patch)
tree9daf3d645e24099753fe3f258e96f2b9af41ae4d
parent430e7ab132d1c9d9d370a89e85385b11fb2e045c (diff)
downloadsubsurface-5666f6573e70c3b472703bddeba240c202fe00de.tar.gz
Code Cleanup: Merged the three TableViews shared code
Merged the shared code for the three table views into one code, this way less code is needed if we need to construct another tableview in the future. I still need to clean some of the models too. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--Makefile2
-rw-r--r--qt-ui/diveplanner.cpp58
-rw-r--r--qt-ui/diveplanner.h5
-rw-r--r--qt-ui/diveplanner.ui39
-rw-r--r--qt-ui/maintab.cpp138
-rw-r--r--qt-ui/maintab.h10
-rw-r--r--qt-ui/maintab.ui78
-rw-r--r--qt-ui/mainwindow.cpp2
8 files changed, 93 insertions, 239 deletions
diff --git a/Makefile b/Makefile
index ef86c93a0..6728a89d2 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,7 @@ HEADERS = \
qt-ui/printoptions.h \
qt-ui/printlayout.h \
qt-ui/completionmodels.h \
+ qt-ui/tableview.h
SOURCES = \
@@ -102,6 +103,7 @@ SOURCES = \
qt-ui/printoptions.cpp \
qt-ui/printlayout.cpp \
qt-ui/completionmodels.cpp \
+ qt-ui/tableview.cpp \
$(RESFILE)
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index e7c1b1962..092683a4b 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -4,6 +4,7 @@
#include "modeldelegates.h"
#include "ui_diveplanner.h"
#include "mainwindow.h"
+#include "tableview.h"
#include "../dive.h"
#include "../divelist.h"
@@ -17,6 +18,7 @@
#include <QListView>
#include <QModelIndex>
#include <QSettings>
+#include <QTableView>
#define TIME_INITIAL_MAX 30
@@ -827,10 +829,10 @@ void Button::mousePressEvent(QGraphicsSceneMouseEvent* event)
DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f), ui(new Ui::DivePlanner())
{
ui->setupUi(this);
- ui->tablePoints->setModel(DivePlannerPointsModel::instance());
- ui->tablePoints->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
-
- connect(ui->tablePoints, SIGNAL(clicked(QModelIndex)), plannerModel, SLOT(removePoint(const QModelIndex)));
+ ui->tableWidget->setTitle(tr("Dive Planner Points"));
+ ui->tableWidget->setModel(DivePlannerPointsModel::instance());
+ ui->tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
+ connect(ui->tableWidget->view(), SIGNAL(clicked(QModelIndex)), plannerModel, SLOT(removePoint(const QModelIndex)));
connect(ui->startTime, SIGNAL(timeChanged(QTime)), this, SLOT(startTimeChanged(QTime)));
connect(ui->ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
connect(ui->bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));
@@ -839,46 +841,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
connect(ui->lowGF, SIGNAL(textChanged(QString)), this, SLOT(gflowChanged(QString)));
connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString)));
connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool)));
-
- QFile cssFile(":table-css");
- cssFile.open(QIODevice::ReadOnly);
- QTextStream reader(&cssFile);
- QString css = reader.readAll();
-
- ui->tablePoints->setStyleSheet(css);
- QFontMetrics metrics(defaultModelFont());
-
- ui->tablePoints->horizontalHeader()->setResizeMode(DivePlannerPointsModel::REMOVE, QHeaderView::Fixed);
- ui->tablePoints->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
- initialUiSetup();
}
-void DivePlannerWidget::hideEvent(QHideEvent* event)
-{
- QSettings s;
- s.beginGroup("DivePlanner");
- s.beginGroup("PointTables");
- for (int i = 0; i < CylindersModel::COLUMNS; i++) {
- s.setValue(QString("colwidth%1").arg(i), ui->tablePoints->columnWidth(i));
- }
- s.endGroup();
- s.sync();
-}
-
-void DivePlannerWidget::initialUiSetup()
-{
- QSettings s;
- s.beginGroup("DivePlanner");
- s.beginGroup("PointTables");
- for (int i = 0; i < CylindersModel::COLUMNS; i++) {
- QVariant width = s.value(QString("colwidth%1").arg(i));
- if (width.isValid())
- ui->tablePoints->setColumnWidth(i, width.toInt());
- else
- ui->tablePoints->resizeColumnToContents(i);
- }
- s.endGroup();
-}
void DivePlannerWidget::startTimeChanged(const QTime& time)
{
plannerModel->setStartTime(time);
@@ -930,11 +894,14 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
case GAS: return strForAir(p);
}
}
- if (role == Qt::DecorationRole){
+ else if (role == Qt::DecorationRole){
switch(index.column()){
case REMOVE : return QIcon(":trash");
}
}
+ else if (role == Qt::FontRole){
+ return defaultModelFont();
+ }
return QVariant();
}
@@ -971,6 +938,9 @@ QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orienta
case CCSETPOINT: return tr("CC Set Point");
}
}
+ else if (role == Qt::FontRole){
+ return defaultModelFont();
+ }
return QVariant();
}
@@ -1074,7 +1044,7 @@ divedatapoint DivePlannerPointsModel::at(int row)
return divepoints.at(row);
}
-void DivePlannerPointsModel::removePoint(const QModelIndex& index)
+void DivePlannerPointsModel::remove(const QModelIndex& index)
{
if (index.column() != REMOVE)
return;
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 0aea77788..ccce6b16f 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -48,7 +48,7 @@ public slots:
void setStartTime(const QTime& t);
void setLastStop6m(bool value);
void createPlan();
- void removePoint(const QModelIndex& index);
+ void remove(const QModelIndex& index);
private:
explicit DivePlannerPointsModel(QObject* parent = 0);
@@ -189,7 +189,6 @@ private:
class DivePlannerWidget : public QWidget {
Q_OBJECT
- void initialUiSetup();
public:
explicit DivePlannerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
@@ -201,8 +200,6 @@ public slots:
void gflowChanged(const QString& gflow);
void gfhighChanged(const QString& gfhigh);
void lastStopChanged(bool checked);
-protected:
- virtual void hideEvent(QHideEvent* );
private:
Ui::DivePlanner *ui;
};
diff --git a/qt-ui/diveplanner.ui b/qt-ui/diveplanner.ui
index d2d52172b..1bcd912a4 100644
--- a/qt-ui/diveplanner.ui
+++ b/qt-ui/diveplanner.ui
@@ -37,6 +37,9 @@
<item row="3" column="1">
<widget class="QLineEdit" name="decoStopSAC"/>
</item>
+ <item row="5" column="0">
+ <widget class="QLineEdit" name="lowGF"/>
+ </item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
@@ -44,9 +47,6 @@
</property>
</widget>
</item>
- <item row="5" column="0">
- <widget class="QLineEdit" name="lowGF"/>
- </item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
@@ -54,6 +54,9 @@
</property>
</widget>
</item>
+ <item row="3" column="0">
+ <widget class="QLineEdit" name="bottomSAC"/>
+ </item>
<item row="4" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
@@ -61,6 +64,9 @@
</property>
</widget>
</item>
+ <item row="5" column="1">
+ <widget class="QLineEdit" name="highGF"/>
+ </item>
<item row="2" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
@@ -68,12 +74,6 @@
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QLineEdit" name="bottomSAC"/>
- </item>
- <item row="5" column="1">
- <widget class="QLineEdit" name="highGF"/>
- </item>
<item row="6" column="0">
<widget class="QCheckBox" name="lastStop">
<property name="text">
@@ -81,9 +81,6 @@
</property>
</widget>
</item>
- <item row="7" column="0" colspan="2">
- <widget class="QTableView" name="tablePoints"/>
- </item>
<item row="8" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
@@ -91,8 +88,26 @@
</property>
</widget>
</item>
+ <item row="7" column="0" colspan="2">
+ <widget class="TableView" name="tableWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>TableView</class>
+ <extends>QWidget</extends>
+ <header>tableview.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 8a0e2f93c..30c071d55 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -18,8 +18,7 @@
#include <QCompleter>
#include <QDebug>
#include <QSet>
-#include <QTextStream>
-#include <QFile>
+#include <QTableView>
#include <QSettings>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
@@ -66,37 +65,19 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
if (label)
label->setAlignment(Qt::AlignHCenter);
}
+ ui->cylinders->setTitle(tr("Cylinders"));
+ ui->cylinders->setBtnToolTip(tr("Add Cylinder"));
+ connect(ui->cylinders, SIGNAL(addButtonClicked()), this, SLOT(addCylinder_clicked()));
- /*Thid couldn't be done on the ui file because element
- is floating, instead of being fixed on the layout. */
- QIcon plusIcon(":plus");
- addCylinder = new QPushButton(plusIcon, QString(), ui->cylindersGroup);
- addCylinder->setFlat(true);
- addCylinder->setToolTip(tr("Add Cylinder"));
- connect(addCylinder, SIGNAL(clicked(bool)), this, SLOT(addCylinder_clicked()));
- addCylinder->setEnabled(false);
- addWeight = new QPushButton(plusIcon, QString(), ui->weightGroup);
- addWeight->setFlat(true);
- addWeight->setToolTip(tr("Add Weight System"));
- connect(addWeight, SIGNAL(clicked(bool)), this, SLOT(addWeight_clicked()));
- addWeight->setEnabled(false);
-
- connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex)));
- connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex)));
- connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
- connect(ui->weights, SIGNAL(clicked(QModelIndex)), this, SLOT(editWeigthWidget(QModelIndex)));
-
- QFontMetrics metrics(defaultModelFont());
-
- ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
- ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
- ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
-
- ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
- ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
- ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
-
- connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
+ ui->weights->setTitle(tr("Weights"));
+ ui->weights->setBtnToolTip(tr("Add Weight System"));
+ connect(ui->weights, SIGNAL(addButtonClicked()), this, SLOT(addWeight_clicked()));
+
+ connect(ui->cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex)));
+ connect(ui->weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeigthWidget(QModelIndex)));
+
+ ui->cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
+ ui->weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
completers.buddy = new QCompleter(BuddyCompletionModel::instance(), ui->buddy);
completers.divemaster = new QCompleter(DiveMasterCompletionModel::instance(), ui->divemaster);
@@ -106,44 +87,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui->divemaster->setCompleter(completers.divemaster);
ui->location->setCompleter(completers.location);
ui->suit->setCompleter(completers.suit);
-
- QFile cssFile(":table-css");
- cssFile.open(QIODevice::ReadOnly);
- QTextStream reader(&cssFile);
- QString css = reader.readAll();
-
- ui->cylinders->setStyleSheet(css);
- ui->weights->setStyleSheet(css);
- initialUiSetup();
-}
-
-// We need to manually position the 'plus' on cylinder and weight.
-void MainTab::resizeEvent(QResizeEvent* event)
-{
- equipmentPlusUpdate();
- QTabWidget::resizeEvent(event);
-}
-
-void MainTab::showEvent(QShowEvent* event)
-{
- QTabWidget::showEvent(event);
- equipmentPlusUpdate();
-}
-
-void MainTab::tabChanged(int idx)
-{
- /* if the current tab has become of index 1 (i.e. the equipment tab) call update
- * for the plus signs */
- if (idx == 1)
- equipmentPlusUpdate();
-}
-
-void MainTab::equipmentPlusUpdate()
-{
- if (ui->cylindersGroup->isVisible())
- addCylinder->setGeometry(ui->cylindersGroup->contentsRect().width() - 30, 2, 24,24);
- if (ui->weightGroup->isVisible())
- addWeight->setGeometry(ui->weightGroup->contentsRect().width() - 30, 2, 24,24);
}
void MainTab::enableEdition()
@@ -199,13 +142,12 @@ void MainTab::clearStats()
ui->timeLimits->clear();
}
-#define UPDATE_TEXT(d, field) \
+#define UPDATE_TEXT(d, field) \
if (!d || !d->field) \
ui->field->setText(""); \
- else \
+ else \
ui->field->setText(d->field)
-
void MainTab::updateDiveInfo(int dive)
{
// This method updates ALL tabs whenever a new dive or trip is
@@ -315,8 +257,6 @@ void MainTab::updateDiveInfo(int dive)
ui->timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0));
cylindersModel->setDive(d);
weightModel->setDive(d);
- addCylinder->setEnabled(true);
- addWeight->setEnabled(true);
} else {
/* make the fields read-only */
ui->location->setReadOnly(true);
@@ -343,8 +283,6 @@ void MainTab::updateDiveInfo(int dive)
ui->airPressureText->clear();
cylindersModel->clear();
weightModel->clear();
- addCylinder->setEnabled(false);
- addWeight->setEnabled(false);
ui->depthLimits->clear();
ui->sacLimits->clear();
ui->divesAllText->clear();
@@ -530,56 +468,14 @@ void MainTab::on_visibility_valueChanged(int value)
currentDive->visibility = value;
}
-void MainTab::hideEvent(QHideEvent* event)
-{
- QSettings s;
- s.beginGroup("MainTab");
- s.beginGroup("Cylinders");
- for (int i = 0; i < CylindersModel::COLUMNS; i++) {
- s.setValue(QString("colwidth%1").arg(i), ui->cylinders->columnWidth(i));
- }
- s.endGroup();
- s.beginGroup("Weights");
- for (int i = 0; i < WeightModel::COLUMNS; i++) {
- s.setValue(QString("colwidth%1").arg(i), ui->weights->columnWidth(i));
- }
- s.endGroup();
- s.sync();
-}
-
-void MainTab::initialUiSetup()
-{
- QSettings s;
- s.beginGroup("MainTab");
- s.beginGroup("Cylinders");
- for (int i = 0; i < CylindersModel::COLUMNS; i++) {
- QVariant width = s.value(QString("colwidth%1").arg(i));
- if (width.isValid())
- ui->cylinders->setColumnWidth(i, width.toInt());
- else
- ui->cylinders->resizeColumnToContents(i);
- }
- s.endGroup();
- s.beginGroup("Weights");
- for (int i = 0; i < WeightModel::COLUMNS; i++) {
- QVariant width = s.value(QString("colwidth%1").arg(i));
- if (width.isValid())
- ui->weights->setColumnWidth(i, width.toInt());
- else
- ui->weights->resizeColumnToContents(i);
- }
- s.endGroup();
- reload();
-}
-
void MainTab::editCylinderWidget(const QModelIndex& index)
{
- if (index.column() != CylindersModel::REMOVE)
+ if (index.isValid() && index.column() != CylindersModel::REMOVE)
ui->cylinders->edit(index);
}
void MainTab::editWeigthWidget(const QModelIndex& index)
{
- if (index.column() != WeightModel::REMOVE)
+ if (index.isValid() && index.column() != WeightModel::REMOVE)
ui->weights->edit(index);
}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 8c398a77d..c423bc619 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -45,16 +45,9 @@ public:
void clearInfo();
void clearEquipment();
void reload();
-
bool eventFilter(QObject* , QEvent*);
- virtual void resizeEvent(QResizeEvent*);
- virtual void showEvent(QShowEvent*);
- virtual void hideEvent(QHideEvent* );
-
void initialUiSetup();
void equipmentPlusUpdate();
-
-
public slots:
void addCylinder_clicked();
void addWeight_clicked();
@@ -68,7 +61,6 @@ public slots:
void on_notes_textChanged();
void on_rating_valueChanged(int value);
void on_visibility_valueChanged(int value);
- void tabChanged(int idx);
void editCylinderWidget(const QModelIndex& index);
void editWeigthWidget(const QModelIndex& index);
@@ -78,8 +70,6 @@ private:
CylindersModel *cylindersModel;
NotesBackup notesBackup;
struct dive* currentDive;
- QPushButton *addCylinder;
- QPushButton *addWeight;
enum { NONE, DIVE, TRIP } editMode;
Completers completers;
void enableEdition();
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index 77ad352ce..a1f5a718a 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -14,7 +14,7 @@
<string>TabWidget</string>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>1</number>
</property>
<widget class="QWidget" name="notesTab">
<attribute name="title">
@@ -147,53 +147,33 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
- <widget class="QSplitter" name="splitter_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <widget class="QGroupBox" name="cylindersGroup">
- <property name="title">
- <string>Cylinders</string>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
</property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QTableView" name="cylinders">
- <property name="styleSheet">
- <string notr="true"/>
- </property>
- <property name="alternatingRowColors">
- <bool>true</bool>
- </property>
- <property name="showGrid">
- <bool>false</bool>
- </property>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QGroupBox" name="weightGroup">
- <property name="title">
- <string>Weight</string>
+ <property name="bottomMargin">
+ <number>0</number>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QTableView" name="weights">
- <property name="styleSheet">
- <string notr="true"/>
- </property>
- <property name="showGrid">
- <bool>false</bool>
- </property>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
- </widget>
- </item>
- </layout>
- </widget>
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="TableView" name="cylinders" native="true"/>
+ <widget class="TableView" name="weights" native="true"/>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
</layout>
@@ -546,6 +526,12 @@
<header>simplewidgets.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>TableView</class>
+ <extends>QWidget</extends>
+ <header>tableview.h</header>
+ <container>1</container>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 4726899e5..245f4b347 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -326,8 +326,6 @@ void MainWindow::on_mainSplitter_splitterMoved(int pos, int idx)
void MainWindow::on_infoProfileSplitter_splitterMoved(int pos, int idx)
{
- /* always update the floating plus sign icons in the equipment tab */
- ui->InfoWidget->equipmentPlusUpdate();
redrawProfile();
}