diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-01 23:54:38 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-01 23:54:38 -0300 |
commit | e5ad47e459af1d937d26782ce8308dbd67ecec4b (patch) | |
tree | 0340be89b69de619623db519c7f8287636646ee0 | |
parent | 764a863082f9337156fc4bcf5c0ecc6ae3d149d6 (diff) | |
parent | 00d85313827af88ae5f35b2391ffa6964e81da49 (diff) | |
download | subsurface-e5ad47e459af1d937d26782ce8308dbd67ecec4b.tar.gz |
Merge branch 'Qt' into RenderStarsOnTable
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.cpp | 39 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.h | 30 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.ui | 109 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 31 | ||||
-rw-r--r-- | qt-ui/maintab.h | 3 | ||||
-rw-r--r-- | qt-ui/maintab.ui | 6 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 52 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 5 | ||||
-rw-r--r-- | qt-ui/mainwindow.ui | 13 | ||||
-rw-r--r-- | qt-ui/models.cpp | 97 | ||||
-rw-r--r-- | qt-ui/models.h | 11 |
12 files changed, 342 insertions, 56 deletions
@@ -31,6 +31,7 @@ EXTRA_FLAGS = $(QTCXXFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \ HEADERS = \ qt-ui/addcylinderdialog.h \ + qt-ui/addweightsystemdialog.h \ qt-ui/divelistview.h \ qt-ui/maintab.h \ qt-ui/mainwindow.h \ @@ -70,6 +71,7 @@ SOURCES = \ webservice.c \ qt-gui.cpp \ qt-ui/addcylinderdialog.cpp \ + qt-ui/addweightsystemdialog.cpp \ qt-ui/divelistview.cpp \ qt-ui/maintab.cpp \ qt-ui/mainwindow.cpp \ diff --git a/qt-ui/addweightsystemdialog.cpp b/qt-ui/addweightsystemdialog.cpp new file mode 100644 index 000000000..48a399de9 --- /dev/null +++ b/qt-ui/addweightsystemdialog.cpp @@ -0,0 +1,39 @@ +/* + * addweightsystemdialog.cpp + * + * classes for the add weightsystem dialog of Subsurface + * + */ +#include "addweightsystemdialog.h" +#include "ui_addweightsystemdialog.h" +#include <QComboBox> +#include <QDoubleSpinBox> +#include "../conversions.h" +#include "models.h" + +AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog()) +{ + ui->setupUi(this); + currentWeightsystem = NULL; +} + +void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws) +{ + currentWeightsystem = ws; + + ui->description->insert(QString(ws->description)); + if (get_units()->weight == units::KG) + ui->weight->setValue(ws->weight.grams / 1000); + else + ui->weight->setValue(grams_to_lbs(ws->weight.grams)); +} + +void AddWeightsystemDialog::updateWeightsystem() +{ + currentWeightsystem->description = strdup(ui->description->text().toUtf8().data()); + if (get_units()->weight == units::KG) + currentWeightsystem->weight.grams = ui->weight->value() * 1000; + else + currentWeightsystem->weight.grams = lbs_to_grams(ui->weight->value()); +} + diff --git a/qt-ui/addweightsystemdialog.h b/qt-ui/addweightsystemdialog.h new file mode 100644 index 000000000..e99dc08d8 --- /dev/null +++ b/qt-ui/addweightsystemdialog.h @@ -0,0 +1,30 @@ +/* + * addweightsystemdialog.h + * + * header file for the add weightsystem dialog of Subsurface + * + */ +#ifndef ADDWEIGHTSYSTEMDIALOG_H +#define ADDWEIGHTSYSTEMDIALOG_H + +#include <QDialog> +#include "../dive.h" + +namespace Ui{ + class AddWeightsystemDialog; +} + +class AddWeightsystemDialog : public QDialog{ + Q_OBJECT +public: + explicit AddWeightsystemDialog(QWidget* parent = 0); + void setWeightsystem(weightsystem_t *ws); + void updateWeightsystem(); + +private: + Ui::AddWeightsystemDialog *ui; + weightsystem_t *currentWeightsystem; +}; + + +#endif diff --git a/qt-ui/addweightsystemdialog.ui b/qt-ui/addweightsystemdialog.ui new file mode 100644 index 000000000..11e60d562 --- /dev/null +++ b/qt-ui/addweightsystemdialog.ui @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AddWeightsystemDialog</class> + <widget class="QDialog" name="AddWeightsystemDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>408</width> + <height>186</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" rowspan="2"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Weightsystem</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::ExpandingFieldsGrow</enum> + </property> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Description</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Weight</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QSpinBox" name="weight"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="inputMethodHints"> + <set>Qt::ImhFormattedNumbersOnly</set> + </property> + <property name="accelerated"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="description"/> + </item> + </layout> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>AddWeightsystemDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>269</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>260</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>AddWeightsystemDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>290</x> + <y>269</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>260</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 7d60db5c2..2467dd0d7 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -7,6 +7,7 @@ #include "maintab.h" #include "ui_maintab.h" #include "addcylinderdialog.h" +#include "addweightsystemdialog.h" #include <QLabel> @@ -61,6 +62,9 @@ void MainTab::clearStats() void MainTab::on_addCylinder_clicked() { + if (cylindersModel->rowCount() >= MAX_CYLINDERS) + return; + AddCylinderDialog dialog(this); cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t)); newCylinder->type.description = ""; @@ -83,6 +87,33 @@ void MainTab::on_delCylinder_clicked() { } +void MainTab::on_addWeight_clicked() +{ + if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) + return; + + AddWeightsystemDialog dialog(this); + weightsystem_t newWeightsystem; + newWeightsystem.description = ""; + newWeightsystem.weight.grams = 0; + + dialog.setWeightsystem(&newWeightsystem); + int result = dialog.exec(); + if (result == QDialog::Rejected) + return; + + dialog.updateWeightsystem(); + weightModel->add(&newWeightsystem); +} + +void MainTab::on_editWeight_clicked() +{ +} + +void MainTab::on_delWeight_clicked() +{ +} + void MainTab::reload() { cylindersModel->update(); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 44815fafc..cf83e0dfe 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -31,6 +31,9 @@ public Q_SLOTS: void on_addCylinder_clicked(); void on_editCylinder_clicked(); void on_delCylinder_clicked(); + void on_addWeight_clicked(); + void on_editWeight_clicked(); + void on_delWeight_clicked(); private: Ui::MainTab *ui; diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 7edbf5837..a99b0aed7 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -152,14 +152,14 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QPushButton" name="pushButton_4"> + <widget class="QPushButton" name="editWeight"> <property name="text"> <string>Edit</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="pushButton_5"> + <widget class="QPushButton" name="addWeight"> <property name="text"> <string>Add</string> </property> @@ -179,7 +179,7 @@ </spacer> </item> <item> - <widget class="QPushButton" name="pushButton_6"> + <widget class="QPushButton" name="delWeight"> <property name="text"> <string>Delete</string> </property> diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index f4538db22..9901e4186 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -12,6 +12,8 @@ #include <QtDebug> #include <QDateTime> #include <QSortFilterProxyModel> +#include <QSettings> +#include <QCloseEvent> #include "divelistview.h" #include "starwidget.h" @@ -31,6 +33,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->ListWidget->setModel(sortModel); setWindowIcon(QIcon(":subsurface-icon")); + readSettings(); } void MainWindow::on_actionNew_triggered() @@ -41,9 +44,8 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionOpen_triggered() { QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); - if (filename.isEmpty()) { + if (filename.isEmpty()) return; - } // Needed to convert to char* QByteArray fileNamePtr = filename.toLocal8Bit(); @@ -54,15 +56,13 @@ void MainWindow::on_actionOpen_triggered() parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); - if (error != NULL) - { + if (error != NULL) { QMessageBox::warning(this, "Error", error->message); g_error_free(error); error = NULL; } - //WARNING: Port This method to Qt - report_dives(FALSE, FALSE); + process_dives(FALSE, FALSE); ui->InfoWidget->reload(); @@ -84,15 +84,12 @@ void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionClose_triggered() { if (unsaved_changes() && (askSaveChanges() == FALSE)) - { return; - } /* free the dives and trips */ while (dive_table.nr) - { delete_single_dive(0); - } + mark_divelist_changed(FALSE); /* clear the selection and the statistics */ @@ -139,6 +136,8 @@ void MainWindow::on_actionPreferences_triggered() void MainWindow::on_actionQuit_triggered() { qDebug("actionQuit"); + if (unsaved_changes() && (askSaveChanges() == FALSE)) + return; } void MainWindow::on_actionDownloadDC_triggered() @@ -285,3 +284,36 @@ bool MainWindow::askSaveChanges() } return false; } + +void MainWindow::readSettings() +{ + QSettings settings("hohndel.org","subsurface"); + + settings.beginGroup("MainWindow"); + QSize sz = settings.value("size").value<QSize>(); + resize(sz); + ui->mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); + ui->infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); + settings.endGroup(); +} + +void MainWindow::writeSettings() +{ + QSettings settings("hohndel.org","subsurface"); + settings.beginGroup("MainWindow"); + settings.setValue("size",size()); + settings.setValue("mainSplitter", ui->mainSplitter->saveState()); + settings.setValue("infoProfileSplitter", ui->infoProfileSplitter->saveState()); + settings.endGroup(); + /* other groups here; avoid '/' and '\' in keys with setValue(...) please */ +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (unsaved_changes() && (askSaveChanges() == FALSE)) { + event->ignore(); + return; + } + event->accept(); + writeSettings(); +} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index fdb100c7a..eece91ade 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -66,12 +66,17 @@ private Q_SLOTS: void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); +protected: + void closeEvent(QCloseEvent *); + private: Ui::MainWindow *ui; DiveTripModel *model; QSortFilterProxyModel *sortModel; QString filter(); bool askSaveChanges(); + void readSettings(); + void writeSettings(); }; diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 3d3f0ec35..073476918 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -16,11 +16,11 @@ <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QSplitter" name="splitter_3"> + <widget class="QSplitter" name="mainSplitter"> <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <widget class="QSplitter" name="splitter_2"> + <widget class="QSplitter" name="infoProfileSplitter"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> @@ -34,13 +34,6 @@ </widget> </widget> </item> - <item> - <widget class="QSplitter" name="splitter"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> @@ -49,7 +42,7 @@ <x>0</x> <y>0</y> <width>763</width> - <height>25</height> + <height>20</height> </rect> </property> <widget class="QMenu" name="menuFile"> diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 7b9d8dc16..6d9bbad39 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -60,9 +60,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const if (!index.isValid() || index.row() >= MAX_CYLINDERS) { return ret; } - - struct dive *d = get_dive(selected_dive); - cylinder_t& cyl = d->cylinder[index.row()]; + cylinder_t& cyl = current_dive->cylinder[index.row()]; if (role == Qt::DisplayRole) { switch(index.column()) { @@ -94,67 +92,93 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const int CylindersModel::rowCount(const QModelIndex& parent) const { - return usedRows[currentDive]; + return usedRows[current_dive]; } void CylindersModel::add(cylinder_t* cyl) { - if (usedRows[currentDive] >= MAX_CYLINDERS) { + if (usedRows[current_dive] >= MAX_CYLINDERS) { free(cyl); + return; } - int row = usedRows[currentDive]; + int row = usedRows[current_dive]; - cylinder_t& cylinder = currentDive->cylinder[row]; + cylinder_t& cylinder = current_dive->cylinder[row]; cylinder.end.mbar = cyl->end.mbar; cylinder.start.mbar = cyl->start.mbar; beginInsertRows(QModelIndex(), row, row); - usedRows[currentDive]++; + usedRows[current_dive]++; endInsertRows(); } void CylindersModel::update() { - if (usedRows[currentDive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); endRemoveRows(); } - - currentDive = get_dive(selected_dive); - if (usedRows[currentDive] > 0) { - beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1); + if (usedRows[current_dive] > 0) { + beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1); endInsertRows(); } } void CylindersModel::clear() { - if (usedRows[currentDive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); - usedRows[currentDive] = 0; + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); + usedRows[current_dive] = 0; endRemoveRows(); } } void WeightModel::clear() { + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); + usedRows[current_dive] = 0; + endRemoveRows(); + } } int WeightModel::columnCount(const QModelIndex& parent) const { - return 0; + return 2; } QVariant WeightModel::data(const QModelIndex& index, int role) const { - return QVariant(); + QVariant ret; + if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) { + return ret; + } + weightsystem_t *ws = ¤t_dive->weightsystem[index.row()]; + + if (role == Qt::DisplayRole) { + switch(index.column()) { + case TYPE: + ret = QString(ws->description); + break; + case WEIGHT: + if (get_units()->weight == units::KG) { + int gr = ws->weight.grams % 1000; + int kg = ws->weight.grams / 1000; + ret = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100); + } else { + ret = QString("%1").arg((unsigned)(grams_to_lbs(ws->weight.grams) + 0.5)); + } + break; + } + } + return ret; } int WeightModel::rowCount(const QModelIndex& parent) const { - return rows; + return usedRows[current_dive]; } QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -164,19 +188,36 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r return ret; } - switch(section) { - case TYPE: - ret = tr("Type"); - break; - case WEIGHT: - ret = tr("Weight"); - break; + if (role == Qt::DisplayRole) { + switch(section) { + case TYPE: + ret = tr("Type"); + break; + case WEIGHT: + ret = tr("Weight"); + break; + } } return ret; } -void WeightModel::add(weight_t* weight) +void WeightModel::add(weightsystem_t* weight) { + if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) { + free(weight); + return; + } + + int row = usedRows[current_dive]; + + weightsystem_t *ws = ¤t_dive->weightsystem[row]; + + ws->description = weight->description; + ws->weight.grams = weight->weight.grams; + + beginInsertRows(QModelIndex(), row, row); + usedRows[current_dive]++; + endInsertRows(); } void WeightModel::update() diff --git a/qt-ui/models.h b/qt-ui/models.h index 7bc7578b8..52a3498df 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -50,28 +50,29 @@ public: void clear(); void update(); private: - dive *currentDive; - /* Since the dive doesn`t stores the number of cylinders that * it has ( max 8 ) and since I don`t want to make a * model-for-each-dive, let`s hack this here instead. */ - QMap<dive*, int> usedRows; + QMap<struct dive *, int> usedRows; }; /* Encapsulation of the Weight Model, that represents * the current weights on a dive. */ class WeightModel : public QAbstractTableModel { +Q_OBJECT +public: enum Column {TYPE, WEIGHT}; /*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; /*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const; /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const; - void add(weight_t *weight); + void add(weightsystem_t *weight); void clear(); void update(); private: - int rows; + /* Remember the number of rows in a dive */ + QMap<struct dive *, int> usedRows; }; /*! An AbstractItemModel for recording dive trip information such as a list of dives. |