From ba712c3b5420ed461b8b7a1fdd14849e622ae974 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 7 Apr 2013 15:20:43 -0700 Subject: Start creating the Qt UI This is based on several commits from Tomaz - mingled together and mildly extended by Dirk (mostly Makefile hacking). All Qt UI related stuff should eventually move into the qt-ui directory. So the Makefile rules for moc and uic have been adjusted accordingly. The MainWindow class has been moved into its own file in qt-ui (but just with a placeholder, the existing class has simply been ifdef'ed out in qt-gui.cpp for the moment). We still have a couple of Qt things in qt-gui.cpp in the main directory... all this needs to move into the qt-ui directory and be built with separate .h files. Right now we have the one-off Makefile rule to create the qt-gui.moc file from the qt-gui.cpp file. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 qt-ui/maintab.cpp (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp new file mode 100644 index 000000000..4569958c8 --- /dev/null +++ b/qt-ui/maintab.cpp @@ -0,0 +1,10 @@ +#include "maintab.h" +#include "ui_maintab.h" + +MainTab::MainTab(QWidget *parent) : QTabWidget(parent), + ui(new Ui::MainTab()) +{ + ui->setupUi(this); +} + +#include "maintab.moc" -- cgit v1.2.3-70-g09d2 From 99153de715955a9a80097c9951eaf096efeb5752 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Tue, 9 Apr 2013 19:34:26 +0400 Subject: Makefile: detect which files need moc and uic Add some magic rules to detect which files need to be processed by the moc or uic tools, as well as a way to manually specify exceptions. Signed-off-by: Alberto Mardegan Signed-off-by: Dirk Hohndel --- Makefile | 54 ++++++++++++++++++++++++++++++---------------------- qt-ui/maintab.cpp | 2 -- qt-ui/mainwindow.cpp | 2 -- 3 files changed, 31 insertions(+), 27 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index 28b7e0365..c89816de5 100644 --- a/Makefile +++ b/Makefile @@ -191,13 +191,24 @@ OBJS = main.o dive.o time.o profile.o info.o equipment.o divelist.o divelist-gtk qt-gui.o statistics.o file.o cochran.o device.o download-dialog.o prefs.o \ webservice.o sha1.o $(GPSOBJ) $(OSSUPPORT).o $(RESFILE) $(QTOBJS) -DEPS = $(wildcard .dep/*.dep) +# Add files to the following variables if the auto-detection based on the +# filename fails +OBJS_NEEDING_MOC = +OBJS_NEEDING_UIC = +HEADERS_NEEDING_MOC = + +# Add the objects for the header files which define QObject subclasses +HEADERS_NEEDING_MOC += $(shell grep -l -s 'Q_OBJECT' $(OBJS:.o=.h)) +MOC_OBJS = $(HEADERS_NEEDING_MOC:.h=.moc.o) +ALL_OBJS = $(OBJS) $(MOC_OBJS) + +DEPS = $(wildcard .dep/*.dep) all: $(NAME) -$(NAME): gen_version_file $(OBJS) $(MSGOBJS) $(INFOPLIST) - $(CXX) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS) +$(NAME): gen_version_file $(ALL_OBJS) $(MSGOBJS) $(INFOPLIST) + $(CXX) $(LDFLAGS) -o $(NAME) $(ALL_OBJS) $(LIBS) gen_version_file: ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING)) @@ -310,36 +321,33 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $ @mkdir -p .dep .dep/qt-ui @$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $< -# This rule is for running the moc on QObject subclasses defined in the .cpp -# files; remember to #include ".moc" at the end of the .cpp file, or -# you'll get linker errors ("undefined vtable for...") -# To activate this rule, you need another rule on the .o file, like: -# file.o: file.moc +# Detect which files require the moc or uic tools to be run +CPP_NEEDING_MOC = $(shell grep -l -s '^\#include \".*\.moc\"' $(OBJS:.o=.cpp)) +OBJS_NEEDING_MOC += $(CPP_NEEDING_MOC:.cpp=.o) -qt-ui/%.moc: qt-ui/%.h - @echo ' MOC' $< - @$(MOC) -i $(MOCFLAGS) $< -o $@ +CPP_NEEDING_UIC = $(shell grep -l -s '^\#include \"ui_.*\.h\"' $(OBJS:.o=.cpp)) +OBJS_NEEDING_UIC += $(CPP_NEEDING_UIC:.cpp=.o) -# this is just here for qt-gui.cpp -# should be removed once all the Qt UI code has been moved into qt-ui +# This rule is for running the moc on QObject subclasses defined in the .h +# files. +%.moc.cpp: %.h + @echo ' MOC' $< + @$(MOC) $(MOCFLAGS) $< -o $@ +# This rule is for running the moc on QObject subclasses defined in the .cpp +# files; remember to #include ".moc" at the end of the .cpp file, or +# you'll get linker errors ("undefined vtable for...") %.moc: %.cpp @echo ' MOC' $< @$(MOC) -i $(MOCFLAGS) $< -o $@ # This creates the ui headers. -# To activate this rule, you need to add the ui_*.h file to the .o file: -# file.o: ui_file.h - -qt-ui/ui_%.h: qt-ui/%.ui +ui_%.h: %.ui @echo ' UIC' $< @$(UIC) $< -o $@ -qt-gui.o: qt-gui.moc - -qt-ui/maintab.o: qt-ui/maintab.moc qt-ui/ui_maintab.h - -qt-ui/mainwindow.o: qt-ui/mainwindow.moc qt-ui/ui_mainwindow.h +$(OBJS_NEEDING_MOC): %.o: %.moc +$(OBJS_NEEDING_UIC): qt-ui/%.o: qt-ui/ui_%.h share/locale/%.UTF-8/LC_MESSAGES/subsurface.mo: po/%.po po/%.aliases mkdir -p $(dir $@) @@ -367,7 +375,7 @@ doc: $(MAKE) -C Documentation doc clean: - rm -f $(OBJS) *~ $(NAME) $(NAME).exe po/*~ po/subsurface-new.pot \ + rm -f $(ALL_OBJS) *~ $(NAME) $(NAME).exe po/*~ po/subsurface-new.pot \ $(VERSION_FILE) qt-ui/*.moc qt-ui/ui_*.h rm -rf share .dep diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4569958c8..c630965d2 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -6,5 +6,3 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), { ui->setupUi(this); } - -#include "maintab.moc" diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d3e5603be..03e14377f 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -13,5 +13,3 @@ void MainWindow::on_actionNew_triggered() { qDebug() << "actionNew"; } - -#include "mainwindow.moc" -- cgit v1.2.3-70-g09d2 From 92397a2bad3d1a2bc261dee67d230e3caa13b8d8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 13 Apr 2013 10:17:59 -0300 Subject: Started the real code on the Qt Interface. 1 - Open File already open files, it tries to not break the Gtk version, but some methods on the GTK version still need to be called inside Qt because the code is too tight-coupled. 2 - Close file already close files, same comments for the open file dialog applies here. 3 - The code for adding new cylinders in the cylinder dialog is done, already works and it's integrated with the system. There's a need to implement the edit and delete now, but it will be easyer since I'm starting to not get lost on the code. 4 - Some functions that were used to convert unities have been moved to convert.h ( can be changed later, put there because it's easyer to find something that converts in a convert.h =p ) because they were static functions that operated in the GTK version but I need those functions in the Qt version too. [Dirk Hohndel: lots and lots of whitespace and coding style changes] Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- Makefile | 6 +- conversions.h | 16 +++ equipment.c | 6 +- qt-gui.cpp | 8 ++ qt-ui/addcylinderdialog.cpp | 48 +++++++ qt-ui/addcylinderdialog.h | 24 ++++ qt-ui/addcylinderdialog.ui | 303 ++++++++++++++++++++++++++++++++++++++++++++ qt-ui/maintab.cpp | 68 +++++++++- qt-ui/maintab.h | 17 ++- qt-ui/maintab.ui | 12 +- qt-ui/mainwindow.cpp | 107 +++++++++++++++- qt-ui/mainwindow.h | 3 + qt-ui/models.cpp | 175 +++++++++++++++++++++++++ qt-ui/models.h | 44 +++++++ 14 files changed, 823 insertions(+), 14 deletions(-) create mode 100644 conversions.h create mode 100644 qt-ui/addcylinderdialog.cpp create mode 100644 qt-ui/addcylinderdialog.h create mode 100644 qt-ui/addcylinderdialog.ui create mode 100644 qt-ui/models.cpp create mode 100644 qt-ui/models.h (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index 9e8e69b2d..81e3648c9 100644 --- a/Makefile +++ b/Makefile @@ -177,13 +177,15 @@ ifneq ($(strip $(LIBXSLT)),) XSLT=-DXSLT='"$(XSLTDIR)"' endif -LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) $(EXTRALIBS) $(LIBZIP) -lpthread -lm $(LIBOSMGPSMAP) $(LIBSOUP) $(LIBWINSOCK) +LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) \ + $(EXTRALIBS) $(LIBZIP) -lpthread -lm $(LIBOSMGPSMAP) $(LIBSOUP) $(LIBWINSOCK) MSGLANGS=$(notdir $(wildcard po/*.po)) MSGOBJS=$(addprefix share/locale/,$(MSGLANGS:.po=.UTF-8/LC_MESSAGES/subsurface.mo)) -QTOBJS = qt-ui/maintab.o qt-ui/mainwindow.o qt-ui/plotareascene.o qt-ui/divelistview.o qt-ui/divetripmodel.o +QTOBJS = qt-ui/maintab.o qt-ui/mainwindow.o qt-ui/plotareascene.o qt-ui/divelistview.o \ + qt-ui/divetripmodel.o qt-ui/addcylinderdialog.o qt-ui/models.o OBJS = main.o dive.o time.o profile.o info.o equipment.o divelist.o divelist-gtk.o deco.o \ planner.o planner-gtk.o \ diff --git a/conversions.h b/conversions.h new file mode 100644 index 000000000..f59fcc96b --- /dev/null +++ b/conversions.h @@ -0,0 +1,16 @@ +/* + * conversions.h + * + * Helpers to convert between different units + * + */ +#ifdef __cplusplus +extern "C" { +#endif + +void convert_volume_pressure(int ml, int mbar, double *v, double *p); +int convert_pressure(int mbar, double *p); + +#ifdef __cplusplus +} +#endif diff --git a/equipment.c b/equipment.c index 2d90f7a52..a1d156f94 100644 --- a/equipment.c +++ b/equipment.c @@ -18,6 +18,7 @@ #include "display.h" #include "display-gtk.h" #include "divelist.h" +#include "conversions.h" static GtkListStore *cylinder_model, *weightsystem_model; @@ -70,7 +71,7 @@ struct ws_widget { }; /* we want bar - so let's not use our unit functions */ -static int convert_pressure(int mbar, double *p) +int convert_pressure(int mbar, double *p) { int decimals = 1; double pressure; @@ -86,7 +87,7 @@ static int convert_pressure(int mbar, double *p) return decimals; } -static void convert_volume_pressure(int ml, int mbar, double *v, double *p) +void convert_volume_pressure(int ml, int mbar, double *v, double *p) { double volume, pressure; @@ -724,6 +725,7 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl /* * Also, insert it into the model if it doesn't already exist */ + // WARNING: GTK-Specific Code. add_cylinder(cylinder, desc, ml, mbar); } diff --git a/qt-gui.cpp b/qt-gui.cpp index e667e97bf..745457763 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -126,6 +126,7 @@ static void on_info_bar_response(GtkWidget *widget, gint response, void report_error(GError* error) { + qDebug("Warning: Calling GTK-Specific Code."); if (error == NULL) { return; @@ -253,6 +254,8 @@ static void file_save(GtkWidget *w, gpointer data) static gboolean ask_save_changes() { + //WARNING: Porting to Qt + qDebug("This method is being ported to Qt, please, stop using it. "); GtkWidget *dialog, *label, *content; gboolean quit = TRUE; dialog = gtk_dialog_new_with_buttons(_("Save Changes?"), @@ -291,6 +294,7 @@ static gboolean ask_save_changes() static void file_close(GtkWidget *w, gpointer data) { + qDebug("Calling an already ported-to-qt Gtk method"); if (unsaved_changes()) if (ask_save_changes() == FALSE) return; @@ -319,8 +323,12 @@ static void file_close(GtkWidget *w, gpointer data) show_dive_info(NULL); } +//##################################################################### +//###### ALREAADY PORTED TO Qt. DELETE ME WHEN NOT MORE USERFUL. # +//##################################################################### static void file_open(GtkWidget *w, gpointer data) { + qDebug("Calling an already ported-to-qt Gtk method."); GtkWidget *dialog; GtkFileFilter *filter; const char *current_default; diff --git a/qt-ui/addcylinderdialog.cpp b/qt-ui/addcylinderdialog.cpp new file mode 100644 index 000000000..6f2294a25 --- /dev/null +++ b/qt-ui/addcylinderdialog.cpp @@ -0,0 +1,48 @@ +#include "addcylinderdialog.h" +#include "ui_addcylinderdialog.h" +#include +#include +#include "../conversions.h" + + +AddCylinderDialog::AddCylinderDialog(QWidget *parent) : ui(new Ui::AddCylinderDialog()) +{ + ui->setupUi(this); +} + +void AddCylinderDialog::setCylinder(cylinder_t *cylinder) +{ + double volume, pressure; + int index; + + currentCylinder = cylinder; + convert_volume_pressure(cylinder->type.size.mliter, cylinder->type.workingpressure.mbar, &volume, &pressure); + + index = ui->cylinderType->findText(QString(cylinder->type.description)); + ui->cylinderType->setCurrentIndex(index); + ui->size->setValue(volume); + ui->pressure->setValue(pressure); + + ui->o2percent->setValue(cylinder->gasmix.o2.permille / 10.0); + ui->hepercent->setValue(cylinder->gasmix.he.permille / 10.0); + + convert_pressure(cylinder->start.mbar, &pressure); + ui->start->setValue(pressure); + + convert_pressure(cylinder->end.mbar, &pressure); + ui->end->setValue(pressure); +} + +void AddCylinderDialog::updateCylinder() +{ + QByteArray description = ui->cylinderType->currentText().toLocal8Bit(); + + currentCylinder->type.description = description.data(); + currentCylinder->type.size.mliter = ui->size->value(); + currentCylinder->type.workingpressure.mbar = ui->pressure->value(); + currentCylinder->gasmix.o2.permille = ui->o2percent->value(); + currentCylinder->gasmix.he.permille = ui->hepercent->value(); + currentCylinder->start.mbar = ui->start->value(); + currentCylinder->end.mbar = ui->end->value(); +} + diff --git a/qt-ui/addcylinderdialog.h b/qt-ui/addcylinderdialog.h new file mode 100644 index 000000000..b32494c05 --- /dev/null +++ b/qt-ui/addcylinderdialog.h @@ -0,0 +1,24 @@ +#ifndef ADDCYLINDERDIALOG_H +#define ADDCYLINDERDIALOG_H + +#include +#include "../dive.h" + +namespace Ui{ + class AddCylinderDialog; +} + +class AddCylinderDialog : public QDialog{ + Q_OBJECT +public: + explicit AddCylinderDialog(QWidget* parent = 0); + void setCylinder(cylinder_t *cylinder); + void updateCylinder(); + +private: + Ui::AddCylinderDialog *ui; + cylinder_t *currentCylinder; +}; + + +#endif diff --git a/qt-ui/addcylinderdialog.ui b/qt-ui/addcylinderdialog.ui new file mode 100644 index 000000000..8bb0428b7 --- /dev/null +++ b/qt-ui/addcylinderdialog.ui @@ -0,0 +1,303 @@ + + + AddCylinderDialog + + + + 0 + 0 + 408 + 298 + + + + Dialog + + + + + + Cylinder + + + + QFormLayout::ExpandingFieldsGrow + + + + + Type + + + + + + + + 0 + 0 + + + + + + + + Size + + + + + + + + 0 + 0 + + + + + + + + Pressure + + + + + + + + 0 + 0 + + + + + + + + + + + Pressure + + + + + + Start + + + + + + + End + + + + + + + false + + + + 0 + 0 + + + + + + + + false + + + + 0 + 0 + + + + + + + + + + + + + + + + + + Gas Mix + + + + + + O2% + + + + + + + false + + + + 0 + 0 + + + + + + + + He% + + + + + + + false + + + + 0 + 0 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AddCylinderDialog + accept() + + + 248 + 269 + + + 157 + 260 + + + + + buttonBox + rejected() + AddCylinderDialog + reject() + + + 290 + 269 + + + 286 + 260 + + + + + checkBox + clicked(bool) + start + setEnabled(bool) + + + 216 + 46 + + + 280 + 66 + + + + + checkBox + clicked(bool) + end + setEnabled(bool) + + + 226 + 48 + + + 268 + 100 + + + + + checkBox_2 + clicked(bool) + o2percent + setEnabled(bool) + + + 214 + 165 + + + 260 + 190 + + + + + checkBox_2 + clicked(bool) + hepercent + setEnabled(bool) + + + 228 + 165 + + + 262 + 216 + + + + + diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index c630965d2..b957fd1c7 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -1,8 +1,74 @@ #include "maintab.h" #include "ui_maintab.h" +#include "addcylinderdialog.h" + +#include MainTab::MainTab(QWidget *parent) : QTabWidget(parent), - ui(new Ui::MainTab()) + ui(new Ui::MainTab()), + weightModel(new WeightModel()), + cylindersModel(new CylindersModel()) { ui->setupUi(this); + ui->cylinders->setModel(cylindersModel); + ui->weights->setModel(weightModel); +} + +void MainTab::clearEquipment() +{ +} + +void MainTab::clearInfo() +{ + QList labels; + labels << ui->sac << ui->otu << ui->oxygenhelium << ui->gasused + << ui->date << ui->divetime << ui->surfinterval + << ui->maxdepth << ui->avgdepth << ui->visibility + << ui->watertemperature << ui->airtemperature << ui->airpress; + + Q_FOREACH(QLabel *l, labels){ + l->setText(QString()); + } +} + +void MainTab::clearStats() +{ + QList labels; + labels << ui->maxdepth_2 << ui->mindepth << ui->avgdepth + << ui->maxsac << ui->minsac << ui->avgsac + << ui->dives << ui->maxtemp << ui->mintemp << ui->avgtemp + << ui->totaltime << ui->avgtime << ui->longestdive << ui->shortestdive; + + Q_FOREACH(QLabel *l, labels){ + l->setText(QString()); + } +} + +void MainTab::on_addCylinder_clicked() +{ + AddCylinderDialog dialog(this); + cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t)); + newCylinder->type.description = ""; + + dialog.setCylinder(newCylinder); + int result = dialog.exec(); + if (result == QDialog::Rejected){ + return; + } + + dialog.updateCylinder(); + cylindersModel->add(newCylinder); +} + +void MainTab::on_editCylinder_clicked() +{ +} + +void MainTab::on_delCylinder_clicked() +{ +} + +void MainTab::reload() +{ + cylindersModel->update(); } diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 40904ab12..0e9f285ac 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -2,6 +2,9 @@ #define MAINTAB_H #include +#include + +#include "models.h" namespace Ui { @@ -13,8 +16,20 @@ class MainTab : public QTabWidget Q_OBJECT public: MainTab(QWidget *parent); + void clearStats(); + void clearInfo(); + void clearEquipment(); + void reload(); + +public Q_SLOTS: + void on_addCylinder_clicked(); + void on_editCylinder_clicked(); + void on_delCylinder_clicked(); + private: Ui::MainTab *ui; + WeightModel *weightModel; + CylindersModel *cylindersModel; }; -#endif \ No newline at end of file +#endif diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 7432dc466..0f46d91a5 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -14,7 +14,7 @@ TabWidget - 0 + 2 @@ -390,19 +390,19 @@ - + - + Edit - + Add @@ -422,7 +422,7 @@ - + Delete @@ -438,7 +438,7 @@ - + diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 03f6b6ca6..fdc823d9c 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -2,11 +2,19 @@ #include "ui_mainwindow.h" #include +#include +#include #include #include "divelistview.h" #include "divetripmodel.h" +#include "glib.h" +#include "../dive.h" +#include "../divelist.h" +#include "../pref.h" + + MainWindow::MainWindow() : ui(new Ui::MainWindow()) { ui->setupUi(this); @@ -45,7 +53,31 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionOpen_triggered() { - qDebug("actionOpen"); + QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); + if (filename.isEmpty()){ + return; + } + + // Needed to convert to char* + QByteArray fileNamePtr = filename.toLocal8Bit(); + + on_actionClose_triggered(); + + GError *error = NULL; + parse_file(fileNamePtr.data(), &error); + set_filename(fileNamePtr.data(), TRUE); + + 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); + + ui->InfoWidget->reload(); } void MainWindow::on_actionSave_triggered() @@ -59,7 +91,37 @@ void MainWindow::on_actionSaveAs_triggered() } void MainWindow::on_actionClose_triggered() { - qDebug("actionClose"); + 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 */ + selected_dive = 0; + + //WARNING: Port this to Qt. + //process_selected_dives(); + + ui->InfoWidget->clearStats(); + ui->InfoWidget->clearInfo(); + ui->InfoWidget->clearEquipment(); + + clear_events(); + show_dive_stats(NULL); + + /* redraw the screen */ + //WARNING: Port this to Qt. + dive_list_update_dives(); + + // WARNING? Port this to Qt. + show_dive_info(NULL); } void MainWindow::on_actionImport_triggered() @@ -190,3 +252,44 @@ void MainWindow::on_actionUserManual_triggered() { qDebug("actionUserManual"); } + +QString MainWindow::filter() +{ + QString f; + f += "ALL ( *.xml *.XML *.uddf *.udcf *.UDFC *.jlb *.JLB "; +#ifdef LIBZIP + f += "*.sde *.SDE *.dld *.DLD "; +#endif +#ifdef SQLITE3 + f += "*.db"; +#endif + f += ");;"; + + f += "XML (*.xml *.XML);;"; + f += "UDDF (*.uddf);;"; + f += "UDCF (*.udcf *.UDCF);;"; + f += "JLB (*.jlb *.JLB);;"; + +#ifdef LIBZIP + f += "SDE (*.sde *.SDE);;"; + f += "DLD (*.dld *.DLD);;"; +#endif +#ifdef SQLITE3 + f += "DB (*.db)"; +#endif + + return f; +} + +bool MainWindow::askSaveChanges() +{ + QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?") + : tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); + + if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok){ + // WARNING: Port. + // file_save(NULL,NULL); + return true; + } + return false; +} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 662d07cc5..34acf2b67 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -62,6 +62,9 @@ private Q_SLOTS: private: Ui::MainWindow *ui; DiveTripModel *model; + QString filter(); + bool askSaveChanges(); + }; #endif diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp new file mode 100644 index 000000000..dac1c7215 --- /dev/null +++ b/qt-ui/models.cpp @@ -0,0 +1,175 @@ +#include "models.h" +#include "../dive.h" + +CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent) +{ +} + +QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + QVariant ret; + if (orientation == Qt::Vertical) { + return ret; + } + + if (role == Qt::DisplayRole) { + switch(section) { + case TYPE: + ret = tr("Type"); + break; + case SIZE: + ret = tr("Size"); + break; + case MAXPRESS: + ret = tr("MaxPress"); + break; + case START: + ret = tr("Start"); + break; + case END: + ret = tr("End"); + break; + case O2: + ret = tr("O2%"); + break; + case HE: + ret = tr("He%"); + break; + } + } + return ret; +} + +int CylindersModel::columnCount(const QModelIndex& parent) const +{ + return 7; +} + +QVariant CylindersModel::data(const QModelIndex& index, int role) const +{ + QVariant ret; + if (!index.isValid() || index.row() >= MAX_CYLINDERS) { + return ret; + } + + dive *d = get_dive(selected_dive); + cylinder_t& cyl = d->cylinder[index.row()]; + + if (role == Qt::DisplayRole) { + switch(index.column()) { + case TYPE: + ret = QString(cyl.type.description); + break; + case SIZE: + ret = cyl.type.size.mliter; + break; + case MAXPRESS: + ret = cyl.type.workingpressure.mbar; + break; + case START: + ret = cyl.start.mbar; + break; + case END: + ret = cyl.end.mbar; + break; + case O2: + ret = cyl.gasmix.o2.permille; + break; + case HE: + ret = cyl.gasmix.he.permille; + break; + } + } + return ret; +} + +int CylindersModel::rowCount(const QModelIndex& parent) const +{ + return usedRows[currentDive]; +} + +void CylindersModel::add(cylinder_t* cyl) +{ + if (usedRows[currentDive] >= MAX_CYLINDERS) { + free(cyl); + } + + int row = usedRows[currentDive]; + + cylinder_t& cylinder = currentDive->cylinder[row]; + + cylinder.end.mbar = cyl->end.mbar; + cylinder.start.mbar = cyl->start.mbar; + + beginInsertRows(QModelIndex(), row, row); + usedRows[currentDive]++; + endInsertRows(); +} + +void CylindersModel::update() +{ + if (usedRows[currentDive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); + endRemoveRows(); + } + + currentDive = get_dive(selected_dive); + if (usedRows[currentDive] > 0) { + beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1); + endInsertRows(); + } +} + +void CylindersModel::clear() +{ + if (usedRows[currentDive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); + usedRows[currentDive] = 0; + endRemoveRows(); + } +} + +void WeightModel::clear() +{ +} + +int WeightModel::columnCount(const QModelIndex& parent) const +{ + return 0; +} + +QVariant WeightModel::data(const QModelIndex& index, int role) const +{ + return QVariant(); +} + +int WeightModel::rowCount(const QModelIndex& parent) const +{ + return rows; +} + +QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + QVariant ret; + if (orientation == Qt::Vertical) { + return ret; + } + + switch(section){ + case TYPE: + ret = tr("Type"); + break; + case WEIGHT: + ret = tr("Weight"); + break; + } + return ret; +} + +void WeightModel::add(weight_t* weight) +{ +} + +void WeightModel::update() +{ +} diff --git a/qt-ui/models.h b/qt-ui/models.h new file mode 100644 index 000000000..0d0c7b41d --- /dev/null +++ b/qt-ui/models.h @@ -0,0 +1,44 @@ +#ifndef MODELS_H +#define MODELS_H + +#include +#include "../dive.h" + +class CylindersModel : public QAbstractTableModel { +Q_OBJECT +public: + enum {TYPE, SIZE, MAXPRESS, START, END, O2, HE}; + + explicit CylindersModel(QObject* parent = 0); + /*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(cylinder_t *cyl); + 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 usedRows; +}; + +class WeightModel : public QAbstractTableModel { + enum{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 clear(); + void update(); +private: + int rows; +}; + +#endif -- cgit v1.2.3-70-g09d2 From f5c958ad73db696e473aaa35e144f4c9d8ae24de Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 13 Apr 2013 20:44:02 -0700 Subject: Add Qtr_ macros that uses gettext in a tr() compatible manner This should wrap gettext nicely and replace the "_()" macros we use in C code. Also added comments to the top of all the new files. Suggested-by: Thiago Macieira Signed-off-by: Dirk Hohndel --- Makefile | 6 ++++-- qt-gui.cpp | 5 +++-- qt-ui/addcylinderdialog.cpp | 6 ++++++ qt-ui/addcylinderdialog.h | 6 ++++++ qt-ui/divelistview.cpp | 6 ++++++ qt-ui/divelistview.h | 6 ++++++ qt-ui/divetripmodel.cpp | 17 ++++++++++++----- qt-ui/divetripmodel.h | 6 ++++++ qt-ui/maintab.cpp | 7 +++++++ qt-ui/maintab.h | 6 ++++++ qt-ui/mainwindow.cpp | 15 +++++++++++---- qt-ui/mainwindow.h | 6 ++++++ qt-ui/models.cpp | 25 ++++++++++++++++--------- qt-ui/models.h | 6 ++++++ qt-ui/plotareascene.cpp | 6 ++++++ qt-ui/plotareascene.h | 6 ++++++ 16 files changed, 113 insertions(+), 22 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index 8bbd26fb7..e33d92053 100644 --- a/Makefile +++ b/Makefile @@ -110,8 +110,10 @@ else QT_MODULES = QtGui QT_CORE = QtCore endif + +# we need GLIB2CFLAGS for gettext +QTCXXFLAGS = $(shell $(PKGCONFIG) --cflags $(QT_MODULES)) $(GLIB2CFLAGS) LIBQT = $(shell $(PKGCONFIG) --libs $(QT_MODULES)) -QTCXXFLAGS = $(shell $(PKGCONFIG) --cflags $(QT_MODULES)) LIBGTK = $(shell $(PKGCONFIG) --libs gtk+-2.0 glib-2.0) LIBDIVECOMPUTERCFLAGS = $(LIBDIVECOMPUTERINCLUDES) @@ -303,7 +305,7 @@ $(INFOPLIST): $(INFOPLISTINPUT) # Transifex merge the translations update-po-files: - xgettext -o po/subsurface-new.pot -s -k_ -kN_ --keyword=C_:1c,2 --add-comments="++GETTEXT" *.c + xgettext -o po/subsurface-new.pot -s -k_ -kN_ -kQtr_ --keyword=C_:1c,2 --add-comments="++GETTEXT" *.c qt-ui/*.cpp tx push -s tx pull -af diff --git a/qt-gui.cpp b/qt-gui.cpp index 745457763..1621317c2 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -25,6 +25,7 @@ #include "version.h" #include "libdivecomputer.h" #include "qt-ui/mainwindow.h" +#include "qt-ui/common.h" #include #include @@ -1784,7 +1785,7 @@ void MainWindow::setCurrentFileName(const QString &fileName) if (fileName == m_currentFileName) return; m_currentFileName = fileName; - QString title = tr("Subsurface"); + QString title = Qtr_("Subsurface"); if (!m_currentFileName.isEmpty()) { QFileInfo fileInfo(m_currentFileName); title += " - " + fileInfo.fileName(); @@ -1797,7 +1798,7 @@ void MainWindow::on_actionOpen_triggered() QString defaultFileName = QString::fromUtf8(prefs.default_filename); QFileInfo fileInfo(defaultFileName); - QFileDialog dialog(this, tr("Open File"), fileInfo.path()); + QFileDialog dialog(this, Qtr_("Open File"), fileInfo.path()); dialog.setFileMode(QFileDialog::ExistingFile); dialog.selectFile(defaultFileName); dialog.setNameFilters(fileNameFilters()); diff --git a/qt-ui/addcylinderdialog.cpp b/qt-ui/addcylinderdialog.cpp index 6f2294a25..043f29907 100644 --- a/qt-ui/addcylinderdialog.cpp +++ b/qt-ui/addcylinderdialog.cpp @@ -1,3 +1,9 @@ +/* + * addcylinderdialog.cpp + * + * classes for the add cylinder dialog of Subsurface + * + */ #include "addcylinderdialog.h" #include "ui_addcylinderdialog.h" #include diff --git a/qt-ui/addcylinderdialog.h b/qt-ui/addcylinderdialog.h index b32494c05..652f7b362 100644 --- a/qt-ui/addcylinderdialog.h +++ b/qt-ui/addcylinderdialog.h @@ -1,3 +1,9 @@ +/* + * addcylinderdialog.h + * + * header file for the add cylinder dialog of Subsurface + * + */ #ifndef ADDCYLINDERDIALOG_H #define ADDCYLINDERDIALOG_H diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index eafbdd384..a8b1eff05 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -1,3 +1,9 @@ +/* + * divelistview.cpp + * + * classes for the divelist of Subsurface + * + */ #include "divelistview.h" DiveListView::DiveListView(QWidget *parent) : QTreeView(parent) diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 3ac123a14..be9774c5c 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -1,3 +1,9 @@ +/* + * divelistview.h + * + * header file for the dive list of Subsurface + * + */ #ifndef DIVELISTVIEW_H #define DIVELISTVIEW_H diff --git a/qt-ui/divetripmodel.cpp b/qt-ui/divetripmodel.cpp index a03603bcf..0a2944d8b 100644 --- a/qt-ui/divetripmodel.cpp +++ b/qt-ui/divetripmodel.cpp @@ -1,3 +1,10 @@ +/* + * divetripmodel.cpp + * + * classes for the dive trip list in Subsurface + */ + +#include "common.h" #include "divetripmodel.h" @@ -63,15 +70,15 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == DIVE_NUMBER) { - return tr("Dive number"); + return Qtr_("Dive number"); } else if (section == DIVE_DATE_TIME) { - return tr("Date"); + return Qtr_("Date"); } else if (section == DIVE_DURATION) { - return tr("Duration"); + return Qtr_("Duration"); } else if (section == DIVE_DEPTH) { - return tr("Depth"); + return Qtr_("Depth"); } else if (section == DIVE_LOCATION) { - return tr("Location"); + return Qtr_("Location"); } } return QVariant(); diff --git a/qt-ui/divetripmodel.h b/qt-ui/divetripmodel.h index 8c8a829e2..ad1815798 100644 --- a/qt-ui/divetripmodel.h +++ b/qt-ui/divetripmodel.h @@ -1,3 +1,9 @@ +/* + * divetripmodel.h + * + * header file for the divetrip model of Subsurface + * + */ #ifndef DIVETRIPMODEL_H #define DIVETRIPMODEL_H diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index b957fd1c7..72d8dfebc 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -1,3 +1,10 @@ +/* + * maintab.cpp + * + * classes for the "notebook" area of the main window of Subsurface + * + */ +#include "common.h" #include "maintab.h" #include "ui_maintab.h" #include "addcylinderdialog.h" diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 0e9f285ac..44815fafc 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -1,3 +1,9 @@ +/* + * maintab.h + * + * header file for the main tab of Subsurface + * + */ #ifndef MAINTAB_H #define MAINTAB_H diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index fdc823d9c..d1cde044a 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -1,3 +1,10 @@ +/* + * mainwindow.cpp + * + * classes for the main UI window in Subsurface + */ + +#include "common.h" #include "mainwindow.h" #include "ui_mainwindow.h" @@ -53,7 +60,7 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionOpen_triggered() { - QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); + QString filename = QFileDialog::getOpenFileName(this, Qtr_("Open File"), QDir::homePath(), filter()); if (filename.isEmpty()){ return; } @@ -283,10 +290,10 @@ QString MainWindow::filter() bool MainWindow::askSaveChanges() { - QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?") - : tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); + QString message = ! existing_filename ? Qtr_("You have unsaved changes\nWould you like to save those before closing the datafile?") + : Qtr_("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); - if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok){ + if (QMessageBox::question(this, Qtr_("Save Changes?"), message) == QMessageBox::Ok){ // WARNING: Port. // file_save(NULL,NULL); return true; diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 34acf2b67..43ebde7f5 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -1,3 +1,9 @@ +/* + * mainwindow.h + * + * header file for the main window of Subsurface + * + */ #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index dac1c7215..a341c0c70 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1,3 +1,10 @@ +/* + * models.cpp + * + * classes for the equipment models of Subsurface + * + */ +#include "common.h" #include "models.h" #include "../dive.h" @@ -15,25 +22,25 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in if (role == Qt::DisplayRole) { switch(section) { case TYPE: - ret = tr("Type"); + ret = Qtr_("Type"); break; case SIZE: - ret = tr("Size"); + ret = Qtr_("Size"); break; case MAXPRESS: - ret = tr("MaxPress"); + ret = Qtr_("MaxPress"); break; case START: - ret = tr("Start"); + ret = Qtr_("Start"); break; case END: - ret = tr("End"); + ret = Qtr_("End"); break; case O2: - ret = tr("O2%"); + ret = Qtr_("O2%"); break; case HE: - ret = tr("He%"); + ret = Qtr_("He%"); break; } } @@ -157,10 +164,10 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r switch(section){ case TYPE: - ret = tr("Type"); + ret = Qtr_("Type"); break; case WEIGHT: - ret = tr("Weight"); + ret = Qtr_("Weight"); break; } return ret; diff --git a/qt-ui/models.h b/qt-ui/models.h index 0d0c7b41d..697096f92 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -1,3 +1,9 @@ +/* + * models.h + * + * header file for the equipment models of Subsurface + * + */ #ifndef MODELS_H #define MODELS_H diff --git a/qt-ui/plotareascene.cpp b/qt-ui/plotareascene.cpp index e69de29bb..a728040f5 100644 --- a/qt-ui/plotareascene.cpp +++ b/qt-ui/plotareascene.cpp @@ -0,0 +1,6 @@ +/* + * plotareascene.cpp + * + * classes for profile plot area scene of Subsurface + * + */ diff --git a/qt-ui/plotareascene.h b/qt-ui/plotareascene.h index e69de29bb..a5b07d1be 100644 --- a/qt-ui/plotareascene.h +++ b/qt-ui/plotareascene.h @@ -0,0 +1,6 @@ +/* + * plotareascene.h + * + * header file for the profile plot area scene of Subsurface + * + */ -- cgit v1.2.3-70-g09d2 From f913eacbd95ddd9ef52dcbd29995ac2b7fc17476 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 14 Apr 2013 10:56:51 -0300 Subject: Fixed the C++ code Style to conform the C style that was previously agreed upon. Removed the use of operator<<() in a bunch of lines to do direct calls this way the code will not scare non-c++ hearted people. :) s Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 72d8dfebc..dd5f7cfdd 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -27,28 +27,37 @@ void MainTab::clearEquipment() void MainTab::clearInfo() { - QList labels; - labels << ui->sac << ui->otu << ui->oxygenhelium << ui->gasused - << ui->date << ui->divetime << ui->surfinterval - << ui->maxdepth << ui->avgdepth << ui->visibility - << ui->watertemperature << ui->airtemperature << ui->airpress; - - Q_FOREACH(QLabel *l, labels){ - l->setText(QString()); - } + ui->sac->setText(QString()); + ui->otu->setText(QString()); + ui->oxygenhelium->setText(QString()); + ui->gasused->setText(QString()); + ui->date->setText(QString()); + ui->divetime->setText(QString()); + ui->surfinterval->setText(QString()); + ui->maxdepth->setText(QString()); + ui->avgdepth->setText(QString()); + ui->visibility->setText(QString()); + ui->watertemperature->setText(QString()); + ui->airtemperature->setText(QString()); + ui->airpress->setText(QString()); } void MainTab::clearStats() { - QList labels; - labels << ui->maxdepth_2 << ui->mindepth << ui->avgdepth - << ui->maxsac << ui->minsac << ui->avgsac - << ui->dives << ui->maxtemp << ui->mintemp << ui->avgtemp - << ui->totaltime << ui->avgtime << ui->longestdive << ui->shortestdive; - - Q_FOREACH(QLabel *l, labels){ - l->setText(QString()); - } + ui->maxdepth_2->setText(QString()); + ui->mindepth->setText(QString()); + ui->avgdepth->setText(QString()); + ui->maxsac->setText(QString()); + ui->minsac->setText(QString()); + ui->avgsac->setText(QString()); + ui->dives->setText(QString()); + ui->maxtemp->setText(QString()); + ui->mintemp->setText(QString()); + ui->avgtemp->setText(QString()); + ui->totaltime->setText(QString()); + ui->avgtime->setText(QString()); + ui->longestdive->setText(QString()); + ui->shortestdive->setText(QString()); } void MainTab::on_addCylinder_clicked() -- cgit v1.2.3-70-g09d2 From d8e11439ad27063b0dad05b2f8f0f4cd7f3e7de1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 14 Apr 2013 06:44:29 -0700 Subject: Undoing the last Qtr_ hack The Qtr_ hack isn't needed as in commit 720fc15b2dcd ("Introduce QApplication") had already made sure that we are using gettext. I didn't revert the two commits as I wanted to keep the added header comments and fix the tooling in the Makefile as well. Signed-off-by: Dirk Hohndel --- Makefile | 2 +- qt-gui.cpp | 5 ++--- qt-ui/common.h | 20 -------------------- qt-ui/divetripmodel.cpp | 12 +++++------- qt-ui/maintab.cpp | 1 - qt-ui/mainwindow.cpp | 10 ++++------ qt-ui/models.cpp | 19 +++++++++---------- 7 files changed, 21 insertions(+), 48 deletions(-) delete mode 100644 qt-ui/common.h (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index e33d92053..7778d2aa8 100644 --- a/Makefile +++ b/Makefile @@ -305,7 +305,7 @@ $(INFOPLIST): $(INFOPLISTINPUT) # Transifex merge the translations update-po-files: - xgettext -o po/subsurface-new.pot -s -k_ -kN_ -kQtr_ --keyword=C_:1c,2 --add-comments="++GETTEXT" *.c qt-ui/*.cpp + xgettext -o po/subsurface-new.pot -s -k_ -kN_ -ktr --keyword=C_:1c,2 --add-comments="++GETTEXT" *.c qt-ui/*.cpp tx push -s tx pull -af diff --git a/qt-gui.cpp b/qt-gui.cpp index 1621317c2..745457763 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -25,7 +25,6 @@ #include "version.h" #include "libdivecomputer.h" #include "qt-ui/mainwindow.h" -#include "qt-ui/common.h" #include #include @@ -1785,7 +1784,7 @@ void MainWindow::setCurrentFileName(const QString &fileName) if (fileName == m_currentFileName) return; m_currentFileName = fileName; - QString title = Qtr_("Subsurface"); + QString title = tr("Subsurface"); if (!m_currentFileName.isEmpty()) { QFileInfo fileInfo(m_currentFileName); title += " - " + fileInfo.fileName(); @@ -1798,7 +1797,7 @@ void MainWindow::on_actionOpen_triggered() QString defaultFileName = QString::fromUtf8(prefs.default_filename); QFileInfo fileInfo(defaultFileName); - QFileDialog dialog(this, Qtr_("Open File"), fileInfo.path()); + QFileDialog dialog(this, tr("Open File"), fileInfo.path()); dialog.setFileMode(QFileDialog::ExistingFile); dialog.selectFile(defaultFileName); dialog.setNameFilters(fileNameFilters()); diff --git a/qt-ui/common.h b/qt-ui/common.h deleted file mode 100644 index 6e00c80ed..000000000 --- a/qt-ui/common.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * common.h - * - * shared by all Qt/C++ code - * - */ - -#ifndef COMMON_H -#define COMMON_H - -#include -#include - -/* use this instead of tr() for translated string literals */ -inline QString Qtr_(const char *str) -{ - return QString::fromUtf8(gettext(str)); -} - -#endif diff --git a/qt-ui/divetripmodel.cpp b/qt-ui/divetripmodel.cpp index 0a2944d8b..5082494a0 100644 --- a/qt-ui/divetripmodel.cpp +++ b/qt-ui/divetripmodel.cpp @@ -3,8 +3,6 @@ * * classes for the dive trip list in Subsurface */ - -#include "common.h" #include "divetripmodel.h" @@ -70,15 +68,15 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == DIVE_NUMBER) { - return Qtr_("Dive number"); + return tr("Dive number"); } else if (section == DIVE_DATE_TIME) { - return Qtr_("Date"); + return tr("Date"); } else if (section == DIVE_DURATION) { - return Qtr_("Duration"); + return tr("Duration"); } else if (section == DIVE_DEPTH) { - return Qtr_("Depth"); + return tr("Depth"); } else if (section == DIVE_LOCATION) { - return Qtr_("Location"); + return tr("Location"); } } return QVariant(); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 72d8dfebc..53926cb25 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -4,7 +4,6 @@ * classes for the "notebook" area of the main window of Subsurface * */ -#include "common.h" #include "maintab.h" #include "ui_maintab.h" #include "addcylinderdialog.h" diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d1cde044a..577b7fb67 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -3,8 +3,6 @@ * * classes for the main UI window in Subsurface */ - -#include "common.h" #include "mainwindow.h" #include "ui_mainwindow.h" @@ -60,7 +58,7 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionOpen_triggered() { - QString filename = QFileDialog::getOpenFileName(this, Qtr_("Open File"), QDir::homePath(), filter()); + QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); if (filename.isEmpty()){ return; } @@ -290,10 +288,10 @@ QString MainWindow::filter() bool MainWindow::askSaveChanges() { - QString message = ! existing_filename ? Qtr_("You have unsaved changes\nWould you like to save those before closing the datafile?") - : Qtr_("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); + QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?") + : tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); - if (QMessageBox::question(this, Qtr_("Save Changes?"), message) == QMessageBox::Ok){ + if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok){ // WARNING: Port. // file_save(NULL,NULL); return true; diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index a341c0c70..64fa6bac3 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -4,7 +4,6 @@ * classes for the equipment models of Subsurface * */ -#include "common.h" #include "models.h" #include "../dive.h" @@ -22,25 +21,25 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in if (role == Qt::DisplayRole) { switch(section) { case TYPE: - ret = Qtr_("Type"); + ret = tr("Type"); break; case SIZE: - ret = Qtr_("Size"); + ret = tr("Size"); break; case MAXPRESS: - ret = Qtr_("MaxPress"); + ret = tr("MaxPress"); break; case START: - ret = Qtr_("Start"); + ret = tr("Start"); break; case END: - ret = Qtr_("End"); + ret = tr("End"); break; case O2: - ret = Qtr_("O2%"); + ret = tr("O2%"); break; case HE: - ret = Qtr_("He%"); + ret = tr("He%"); break; } } @@ -164,10 +163,10 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r switch(section){ case TYPE: - ret = Qtr_("Type"); + ret = tr("Type"); break; case WEIGHT: - ret = Qtr_("Weight"); + ret = tr("Weight"); break; } return ret; -- cgit v1.2.3-70-g09d2 From 04e59a0e1cdb32c5091fc4bc0d692f00821ab849 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 May 2013 14:30:34 -0700 Subject: Hook up adding a weightsystem Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 17 +++++++++++++++++ qt-ui/maintab.h | 3 +++ qt-ui/maintab.ui | 6 +++--- qt-ui/models.cpp | 16 +++++++++------- qt-ui/models.h | 2 ++ 5 files changed, 34 insertions(+), 10 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 7d60db5c2..f8c69ed9c 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -83,6 +83,23 @@ void MainTab::on_delCylinder_clicked() { } +void MainTab::on_addWeight_clicked() +{ + /* this needs a dialog - right now we just fill in a dummy */ + weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t)); + newWeightsystem->description = "Just testing"; + newWeightsystem->weight.grams = 15000; + 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 @@ - + Edit - + Add @@ -179,7 +179,7 @@ - + Delete diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 4583c36cd..6756002e2 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -186,13 +186,15 @@ 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; } diff --git a/qt-ui/models.h b/qt-ui/models.h index 46da9e51b..9a4602f18 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -56,6 +56,8 @@ private: /* 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; -- cgit v1.2.3-70-g09d2 From 482bea84c2f218f515b3b16556197379623a8028 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 May 2013 14:49:17 -0700 Subject: Don't add cylinders and weightsystems past the MAX We actually should disable the 'Add' button, I guess. Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 6 ++++++ qt-ui/models.cpp | 2 ++ 2 files changed, 8 insertions(+) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index f8c69ed9c..4174ce5dd 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -61,6 +61,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 = ""; @@ -85,6 +88,9 @@ void MainTab::on_delCylinder_clicked() void MainTab::on_addWeight_clicked() { + if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) + return; + /* this needs a dialog - right now we just fill in a dummy */ weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t)); newWeightsystem->description = "Just testing"; diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 6756002e2..f1bb8d137 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -98,6 +98,7 @@ void CylindersModel::add(cylinder_t* cyl) { if (usedRows[current_dive] >= MAX_CYLINDERS) { free(cyl); + return; } int row = usedRows[current_dive]; @@ -203,6 +204,7 @@ void WeightModel::add(weightsystem_t* weight) { if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) { free(weight); + return; } int row = usedRows[current_dive]; -- cgit v1.2.3-70-g09d2 From f45618f0c7ce5af85e0f69aab49ef20a1663bca1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 May 2013 15:37:41 -0700 Subject: Create Add Weightsystem dialog My first attempt to create a Qt dialog and to hook it up with the program. Unsurprisingly this doesn't quite work as expected (i.e., the values I enter aren't populated in the model), but it's a start... Signed-off-by: Dirk Hohndel --- Makefile | 2 + qt-ui/addweightsystemdialog.cpp | 38 ++++++++++++++ qt-ui/addweightsystemdialog.h | 30 +++++++++++ qt-ui/addweightsystemdialog.ui | 109 ++++++++++++++++++++++++++++++++++++++++ qt-ui/maintab.cpp | 14 ++++-- 5 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 qt-ui/addweightsystemdialog.cpp create mode 100644 qt-ui/addweightsystemdialog.h create mode 100644 qt-ui/addweightsystemdialog.ui (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index aac1759bc..1bb080363 100644 --- a/Makefile +++ b/Makefile @@ -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..6ac1c02f9 --- /dev/null +++ b/qt-ui/addweightsystemdialog.cpp @@ -0,0 +1,38 @@ +/* + * addweightsystemdialog.cpp + * + * classes for the add weightsystem dialog of Subsurface + * + */ +#include "addweightsystemdialog.h" +#include "ui_addweightsystemdialog.h" +#include +#include +#include "../conversions.h" +#include "models.h" + +AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog()) +{ + ui->setupUi(this); +} + +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 +#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 @@ + + + AddWeightsystemDialog + + + + 0 + 0 + 408 + 186 + + + + Dialog + + + + + + Weightsystem + + + + QFormLayout::ExpandingFieldsGrow + + + + + Description + + + + + + + Weight + + + + + + + + 0 + 0 + + + + Qt::ImhFormattedNumbersOnly + + + true + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AddWeightsystemDialog + accept() + + + 248 + 269 + + + 157 + 260 + + + + + buttonBox + rejected() + AddWeightsystemDialog + reject() + + + 290 + 269 + + + 286 + 260 + + + + + diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4174ce5dd..f26a72a8a 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 @@ -91,10 +92,17 @@ void MainTab::on_addWeight_clicked() if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) return; - /* this needs a dialog - right now we just fill in a dummy */ + AddWeightsystemDialog dialog(this); weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t)); - newWeightsystem->description = "Just testing"; - newWeightsystem->weight.grams = 15000; + newWeightsystem->description = ""; + newWeightsystem->weight.grams = 0; + + dialog.setWeightsystem(newWeightsystem); + int result = dialog.exec(); + if (result == QDialog::Rejected) + return; + + dialog.updateWeightsystem(); weightModel->add(newWeightsystem); } -- cgit v1.2.3-70-g09d2 From 00d85313827af88ae5f35b2391ffa6964e81da49 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 May 2013 16:23:20 -0700 Subject: Fix a couple of small problems in add weightsystem The constructor letf the currentWeightsytem variable uninitialized. Instead of creating the memory leak by malloc-ing the newWeightsystem in the on_addWeight_clicked() function use a local variable instead and pass its address around. Signed-off-by: Dirk Hohndel --- qt-ui/addweightsystemdialog.cpp | 1 + qt-ui/maintab.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/addweightsystemdialog.cpp b/qt-ui/addweightsystemdialog.cpp index 6ac1c02f9..48a399de9 100644 --- a/qt-ui/addweightsystemdialog.cpp +++ b/qt-ui/addweightsystemdialog.cpp @@ -14,6 +14,7 @@ AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog()) { ui->setupUi(this); + currentWeightsystem = NULL; } void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index f26a72a8a..2467dd0d7 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -93,17 +93,17 @@ void MainTab::on_addWeight_clicked() return; AddWeightsystemDialog dialog(this); - weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t)); - newWeightsystem->description = ""; - newWeightsystem->weight.grams = 0; + weightsystem_t newWeightsystem; + newWeightsystem.description = ""; + newWeightsystem.weight.grams = 0; - dialog.setWeightsystem(newWeightsystem); + dialog.setWeightsystem(&newWeightsystem); int result = dialog.exec(); if (result == QDialog::Rejected) return; dialog.updateWeightsystem(); - weightModel->add(newWeightsystem); + weightModel->add(&newWeightsystem); } void MainTab::on_editWeight_clicked() -- cgit v1.2.3-70-g09d2 From 8577410fcd94f3c3109b8b3cf4932a9e0d11fc80 Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Fri, 3 May 2013 08:19:00 +0100 Subject: Reformat dive info page in tab widget Clean up the formatting. Distinguish between headings and value labels. Tidy up text appearance (remove trailing ':') Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 26 +++---- qt-ui/maintab.ui | 200 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 132 insertions(+), 94 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 2467dd0d7..d72df965c 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -27,19 +27,19 @@ void MainTab::clearEquipment() void MainTab::clearInfo() { - ui->sac->setText(QString()); - ui->otu->setText(QString()); - ui->oxygenhelium->setText(QString()); - ui->gasused->setText(QString()); - ui->date->setText(QString()); - ui->divetime->setText(QString()); - ui->surfinterval->setText(QString()); - ui->maxdepth->setText(QString()); - ui->avgdepth->setText(QString()); - ui->visibility->setText(QString()); - ui->watertemperature->setText(QString()); - ui->airtemperature->setText(QString()); - ui->airpress->setText(QString()); + ui->sacText->setText(QString()); + ui->otuText->setText(QString()); + ui->oxygenHeliumText->setText(QString()); + ui->gasUsedText->setText(QString()); + ui->dateText->setText(QString()); + ui->diveTimeText->setText(QString()); + ui->surfaceIntervalText->setText(QString()); + ui->maximumDepthText->setText(QString()); + ui->averageDepthText->setText(QString()); + ui->visibilityText->setText(QString()); + ui->waterTemperatureText->setText(QString()); + ui->airTemperatureText->setText(QString()); + ui->airPressureText->setText(QString()); } void MainTab::clearStats() diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index a99b0aed7..82019e6c3 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -7,14 +7,14 @@ 0 0 400 - 320 + 325 TabWidget - 0 + 2 @@ -199,9 +199,31 @@ - + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 10 + + + 15 + + + 10 + - + 75 @@ -209,12 +231,12 @@ - SAC: + SAC - + 75 @@ -222,12 +244,12 @@ - OTU: + OTU - + 75 @@ -235,12 +257,12 @@ - 0²/He: + 0²/He - + 75 @@ -248,33 +270,33 @@ - Gas Used: + Gas Used - + TextLabel - + TextLabel - + TextLabel - + TextLabel @@ -283,38 +305,28 @@ - - + + + Qt::Vertical + + + + 20 + 40 + + + + + + + 10 - - - - - 75 - true - - - - Dive Time: - - - - - - - - 75 - true - - - - Surf Interv: - - - - - + + 15 + + + 75 @@ -322,26 +334,26 @@ - Avg Depth: + Date - - + + TextLabel - + TextLabel - - + + 75 @@ -349,12 +361,12 @@ - Air Press: + Visibility - - + + 75 @@ -362,26 +374,33 @@ - Max Depth: + Water Temp. - - + + TextLabel - + TextLabel - - + + + + TextLabel + + + + + 75 @@ -389,19 +408,25 @@ - Air Temp: + Air Pressure - - + + + + + 75 + true + + - TextLabel + Ave. Depth - - + + 75 @@ -409,12 +434,12 @@ - Visibility: + Max. Depth - - + + 75 @@ -422,40 +447,53 @@ - Water Temp: + Air Temp. - + TextLabel - - + + TextLabel - - + + TextLabel - - + + TextLabel - - + + + + + 75 + true + + + + Interval + + + + + 75 @@ -463,7 +501,7 @@ - Date: + Dive Time @@ -477,7 +515,7 @@ 20 - 112 + 40 -- cgit v1.2.3-70-g09d2 From f07614fb2f55644a6124b0e837d2776afadee113 Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Mon, 6 May 2013 08:30:40 +0100 Subject: Reformat statistics tab in MainTab tab widget Rename various labels and text into clear pairs and reflect changes into .cpp file. To avoid clashes with names on other tabs use '..All..' to emphasise that this page deals with an aggregate across the selected dives. Re-format the statistics tab. Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 28 ++++++------ qt-ui/maintab.ui | 125 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 91 insertions(+), 62 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index d72df965c..8d196a872 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -44,20 +44,20 @@ void MainTab::clearInfo() void MainTab::clearStats() { - ui->maxdepth_2->setText(QString()); - ui->mindepth->setText(QString()); - ui->avgdepth->setText(QString()); - ui->maxsac->setText(QString()); - ui->minsac->setText(QString()); - ui->avgsac->setText(QString()); - ui->dives->setText(QString()); - ui->maxtemp->setText(QString()); - ui->mintemp->setText(QString()); - ui->avgtemp->setText(QString()); - ui->totaltime->setText(QString()); - ui->avgtime->setText(QString()); - ui->longestdive->setText(QString()); - ui->shortestdive->setText(QString()); + ui->maximumDepthAllText->setText(QString()); + ui->minimumDepthAllText->setText(QString()); + ui->averageDepthAllText->setText(QString()); + ui->maximumSacAllText->setText(QString()); + ui->minimumSacAllText->setText(QString()); + ui->averageSacAllText->setText(QString()); + ui->divesAllText->setText(QString()); + ui->maximumTemperatureAllText->setText(QString()); + ui->minimumTemperatureAllText->setText(QString()); + ui->averageTemperatureAllText->setText(QString()); + ui->totalTimeAllText->setText(QString()); + ui->averageTimeAllText->setText(QString()); + ui->longestAllText->setText(QString()); + ui->shortestAllText->setText(QString()); } void MainTab::on_addCylinder_clicked() diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 82019e6c3..5ec104638 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -14,7 +14,7 @@ TabWidget - 2 + 0 @@ -528,12 +528,28 @@ - - + + + Qt::Vertical + + + + 20 + 20 + + + + + + + 10 + + 15 + - + 75 @@ -541,12 +557,12 @@ - Max Depth + Max. Depth - + 75 @@ -554,12 +570,12 @@ - Min Depth + Min. Depth - + 75 @@ -567,33 +583,33 @@ - Avg Depth + Ave. Depth - + TextLabel - + TextLabel - + TextLabel - + 75 @@ -601,12 +617,12 @@ - Max SAC + Max. SAC - + 75 @@ -614,12 +630,12 @@ - Min SAC + Min. SAC - + 75 @@ -627,26 +643,26 @@ - Avg SAC + Ave. SAC - + TextLabel - + TextLabel - + TextLabel @@ -655,15 +671,28 @@ - - + + + Qt::Vertical + + + + 20 + 20 + + + + + + + 10 - - 0 + + 15 - + 75 @@ -679,7 +708,7 @@ - + 75 @@ -687,12 +716,12 @@ - Max Temp + Max. Temp. - + 75 @@ -700,12 +729,12 @@ - Min Temp + Min. Temp. - + 75 @@ -713,40 +742,40 @@ - Avg Temp + Ave. Temp. - + TextLabel - + TextLabel - + TextLabel - + TextLabel - + 75 @@ -759,7 +788,7 @@ - + 75 @@ -767,12 +796,12 @@ - Avg Time + Ave. Time - + 75 @@ -780,12 +809,12 @@ - Longest Dive + Longest - + 75 @@ -793,33 +822,33 @@ - Shortest Dive + Shortest - + TextLabel - + TextLabel - + TextLabel - + TextLabel @@ -835,7 +864,7 @@ 20 - 85 + 20 -- cgit v1.2.3-70-g09d2 From 06eab74a72c67f5b1dac3cd92bdaa91a15ae8eac Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 6 May 2013 13:23:14 -0300 Subject: Added the code to populate the tabs when a dive is selected. So, this is what happens now: Every tab should be populated from updateDiveInfo method, it will be called whenever a new dive is selected I'm already populating the 'notes' box to show how it can be done. If you are unsure what's the name of anything, open the file maintab.ui on the designer, click on the item and check its objectName, the access is ui->objectName from here on. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 16 ++++++++++++++++ qt-ui/maintab.h | 2 ++ qt-ui/mainwindow.cpp | 1 + 3 files changed, 19 insertions(+) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 8d196a872..84f29e6e8 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -60,6 +60,22 @@ void MainTab::clearStats() ui->shortestAllText->setText(QString()); } +void MainTab::updateDiveInfo(int dive) +{ + // So, this is what happens now: + // Every tab should be populated from this method, + // it will be called whenever a new dive is selected + // I'm already populating the 'notes' box + // to show how it can be done. + // If you are unsure what's the name of anything, + // open the file maintab.ui on the designer + // click on the item and check its objectName, + // the access is ui->objectName from here on. + + struct dive *d = get_dive(dive); + ui->notes->setText(d->notes); +} + void MainTab::on_addCylinder_clicked() { if (cylindersModel->rowCount() >= MAX_CYLINDERS) diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index cf83e0dfe..e09781362 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -35,6 +35,8 @@ public Q_SLOTS: void on_editWeight_clicked(); void on_delWeight_clicked(); + void updateDiveInfo(int dive); + private: Ui::MainTab *ui; WeightModel *weightModel; diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index f29c82588..e8fe80460 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -94,6 +94,7 @@ void MainWindow::dive_selection_changed(const QItemSelection& newSelection, cons select_dive(get_divenr(d)); } ui->ProfileWidget->plot(get_dive(selected_dive)); + ui->InfoWidget->updateDiveInfo(selected_dive); } void MainWindow::on_actionSave_triggered() -- cgit v1.2.3-70-g09d2 From b3fce3497cc6cd801afae01f713b56b1d8e883b8 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 6 May 2013 10:16:16 -0700 Subject: Fill Dive Notes widget Make sure we clear things out if no dive is selected. Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 16 +++++++++++++++- qt-ui/maintab.ui | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 84f29e6e8..df6ee69eb 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -60,6 +60,12 @@ void MainTab::clearStats() ui->shortestAllText->setText(QString()); } +#define UPDATE_TEXT(d, field) \ + if (!d || !d->field) \ + ui->field->setText(""); \ + else \ + ui->field->setText(d->field) + void MainTab::updateDiveInfo(int dive) { // So, this is what happens now: @@ -73,7 +79,15 @@ void MainTab::updateDiveInfo(int dive) // the access is ui->objectName from here on. struct dive *d = get_dive(dive); - ui->notes->setText(d->notes); + UPDATE_TEXT(d, notes); + UPDATE_TEXT(d, location); + UPDATE_TEXT(d, suit); + UPDATE_TEXT(d, divemaster); + UPDATE_TEXT(d, buddy); + if (d) + ui->rating->setCurrentStars(d->rating); + else + ui->rating->setCurrentStars(0); } void MainTab::on_addCylinder_clicked() diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 5ec104638..70f88caec 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -79,7 +79,7 @@ - + -- cgit v1.2.3-70-g09d2 From b75a89aa868d39be29d2bb220a6e0c50d5a2b0ac Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 6 May 2013 20:36:37 -0700 Subject: Start populating the maintab Dive Info widget Establish some useful helpers and use them when updating the values. One of the helpers (from statistics.c) puzzlingly doesn't link - so that's ifdefed out. Also had to re-arrange the settings reading code (it came too late) and to extract the expanding code of the top dive from the settings reading code (as it had no business being there to begin with). Signed-off-by: Dirk Hohndel --- Makefile | 1 + qt-gui.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qt-ui/maintab.cpp | 23 +++++++++++++++++++++- qt-ui/mainwindow.cpp | 14 ++++++-------- qt-ui/models.cpp | 1 + statistics.c | 15 +++++++++++++++ statistics.h | 1 + 7 files changed, 100 insertions(+), 9 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/Makefile b/Makefile index 338f81a7c..add90b308 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ SOURCES = \ profile.c \ save-xml.c \ sha1.c \ + statistics.c \ time.c \ qt-gui.cpp \ qt-ui/addcylinderdialog.cpp \ diff --git a/qt-gui.cpp b/qt-gui.cpp index a4801f760..1e2c86e69 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -133,5 +133,59 @@ void set_dc_nickname(struct dive *dive) /* needs Qt implementation */ } +QString get_depth_string(depth_t depth, bool showunit) +{ + if (prefs.units.length == units::METERS) { + double meters = depth.mm / 1000.0; + return QString("%1%2").arg(meters, 0, 'f', meters >= 20.0 ? 0 : 1 ).arg(showunit ? _("m") : ""); + } else { + double feet = mm_to_feet(depth.mm); + return QString("%1%2").arg(feet, 0, 'f', 1). arg(showunit ? _("ft") : ""); + } +} + +QString get_weight_string(weight_t weight, bool showunit) +{ + if (prefs.units.weight == units::KG) { + double kg = weight.grams / 1000.0; + return QString("%1%2").arg(kg, 0, 'f', kg >= 20.0 ? 0 : 1 ).arg(showunit ? _("kg") : ""); + } else { + double lbs = grams_to_lbs(weight.grams); + return QString("%1%2").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1 ).arg(showunit ? _("lbs") : ""); + } +} + +QString get_temperature_string(temperature_t temp, bool showunit) +{ + if (prefs.units.temperature == units::CELSIUS) { + double celsius = mkelvin_to_C(temp.mkelvin); + return QString("%1%2").arg(celsius, 0, 'f', 1).arg(showunit ? _("C") : ""); + } else { + double fahrenheit = mkelvin_to_F(temp.mkelvin); + return QString("%1%2").arg(fahrenheit, 0, 'f', 1).arg(showunit ? _("F") : ""); + } +} + +QString get_volume_string(volume_t volume, bool showunit) +{ + if (prefs.units.volume == units::LITER) { + double liter = volume.mliter / 1000.0; + return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? _("l") : ""); + } else { + double cuft = ml_to_cuft(volume.mliter); + return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? _("cuft") : ""); + } +} + +QString get_pressure_string(pressure_t pressure, bool showunit) +{ + if (prefs.units.pressure == units::BAR) { + double bar = pressure.mbar / 1000.0; + return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? _("bar") : ""); + } else { + double psi = mbar_to_PSI(pressure.mbar); + return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? _("psi") : ""); + } +} #include "qt-gui.moc" diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index df6ee69eb..5f668b2be 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -8,6 +8,8 @@ #include "ui_maintab.h" #include "addcylinderdialog.h" #include "addweightsystemdialog.h" +#include "../helpers.h" +#include "../statistics.h" #include @@ -66,6 +68,7 @@ void MainTab::clearStats() else \ ui->field->setText(d->field) + void MainTab::updateDiveInfo(int dive) { // So, this is what happens now: @@ -77,7 +80,7 @@ void MainTab::updateDiveInfo(int dive) // open the file maintab.ui on the designer // click on the item and check its objectName, // the access is ui->objectName from here on. - + volume_t sacVal; struct dive *d = get_dive(dive); UPDATE_TEXT(d, notes); UPDATE_TEXT(d, location); @@ -88,6 +91,24 @@ void MainTab::updateDiveInfo(int dive) ui->rating->setCurrentStars(d->rating); else ui->rating->setCurrentStars(0); + ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); + ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); + sacVal.mliter = d ? d->sac : 0; + ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); + ui->otuText->setText(QString("%1").arg( d ? d->otu : 0)); + ui->waterTemperatureText->setText(d ? get_temperature_string(d->watertemp, TRUE) : ""); + ui->airTemperatureText->setText(d ? get_temperature_string(d->airtemp, TRUE) : ""); + if (d && d->surface_pressure.mbar) + /* this is ALWAYS displayed in mbar */ + ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); + else + ui->airPressureText->setText(QString("")); +#if 0 /* this fails to link, even though the function is defined in statistics.c / statistics.h */ + if (d) + ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE)); + else +#endif + ui->gasUsedText->setText(""); } void MainTab::on_addCylinder_clicked() diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index e8fe80460..56ae64b0c 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -32,14 +32,17 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), sortModel(new QSortFilterProxyModel()) { ui->setupUi(this); + readSettings(); sortModel->setSourceModel(model); ui->ListWidget->setModel(sortModel); setWindowIcon(QIcon(":subsurface-icon")); - connect(ui->ListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(dive_selection_changed(QItemSelection,QItemSelection))); - - readSettings(); + QModelIndex firstDiveOrTrip = sortModel->index(0,0); + if (sortModel->index(0,0, firstDiveOrTrip).isValid()) + ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); + else + ui->ListWidget->setCurrentIndex(firstDiveOrTrip); } void MainWindow::on_actionNew_triggered() @@ -343,11 +346,6 @@ void MainWindow::readSettings() } ui->ListWidget->collapseAll(); ui->ListWidget->expand(sortModel->index(0,0)); - QModelIndex firstDiveOrTrip = sortModel->index(0,0); - if (sortModel->index(0,0, firstDiveOrTrip).isValid()) - ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); - else - ui->ListWidget->setCurrentIndex(firstDiveOrTrip); settings.endGroup(); settings.beginGroup("Units"); GET_UNIT(v, "feet", length, units::METERS, units::FEET); diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index eb4d8974b..9a6edce98 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -677,6 +677,7 @@ void DiveTripModel::setupModelData() while (--i >= 0) { struct dive* dive = get_dive(i); + update_cylinder_related_info(dive); dive_trip_t* trip = dive->divetrip; DiveItem* diveItem = new DiveItem(); diff --git a/statistics.c b/statistics.c index 7532e346e..bee5837d6 100644 --- a/statistics.c +++ b/statistics.c @@ -267,3 +267,18 @@ void get_selected_dives_text(char *buffer, int size) } } +volume_t get_gas_used(struct dive *dive) +{ + int idx; + volume_t gas_used = { 0 }; + for (idx = 0; idx < MAX_CYLINDERS; idx++) { + cylinder_t *cyl = &dive->cylinder[idx]; + pressure_t start, end; + + start = cyl->start.mbar ? cyl->start : cyl->sample_start; + end = cyl->end.mbar ?cyl->sample_end : cyl->sample_end; + if (start.mbar && end.mbar) + gas_used.mliter += gas_volume(cyl, start) - gas_volume(cyl, end); + } + return gas_used; +} diff --git a/statistics.h b/statistics.h index d2709ee93..95f2957e8 100644 --- a/statistics.h +++ b/statistics.h @@ -31,3 +31,4 @@ extern char *get_time_string(int seconds, int maxdays); extern char *get_minutes(int seconds); extern void process_all_dives(struct dive *dive, struct dive **prev_dive); extern void get_selected_dives_text(char *buffer, int size); +extern volume_t get_gas_used(struct dive *dive); -- cgit v1.2.3-70-g09d2 From 5e4f06e6ad2da553ac7b47bf6837d8053b888f6f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 May 2013 20:55:28 -0700 Subject: Enable the code that was #if 0'ed out Linking error is fixed. Signed-off-by: Thiago Macieira Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 5f668b2be..89501fc07 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -103,11 +103,9 @@ void MainTab::updateDiveInfo(int dive) ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); else ui->airPressureText->setText(QString("")); -#if 0 /* this fails to link, even though the function is defined in statistics.c / statistics.h */ if (d) ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE)); else -#endif ui->gasUsedText->setText(""); } -- cgit v1.2.3-70-g09d2 From 661aa67e89ad7710f90482b074715c4d1448860a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 8 May 2013 10:51:15 -0700 Subject: Avoid potential crash if no dive is selected I missed to spots where we would unconditionally dereference the dive pointer. Reported-by: Henrik Brautaset Aronsen Reported-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 89501fc07..078d59ca9 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -91,8 +91,8 @@ void MainTab::updateDiveInfo(int dive) ui->rating->setCurrentStars(d->rating); else ui->rating->setCurrentStars(0); - ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); - ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); + ui->maximumDepthText->setText(d ? get_depth_string(d->maxdepth, TRUE) : ""); + ui->averageDepthText->setText(d ? get_depth_string(d->meandepth, TRUE) : ""); sacVal.mliter = d ? d->sac : 0; ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); ui->otuText->setText(QString("%1").arg( d ? d->otu : 0)); -- cgit v1.2.3-70-g09d2 From b5d5b05140eac7a8031cdb15e7c31f659a6f2da6 Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Wed, 8 May 2013 12:08:00 -0700 Subject: Fix crash on right click dive trip A null pointer dereference occured after right click on a dive trip because updateDiveInfo was called with dive == -1 causing get_dive(int) to return null. Wrap to avoid crash and clear dive info widget text labels. [Dirk Hohndel: this is different from the fix I had committed earlier; I decided to combine the ideas, clean this one up a bit more and this is the result] Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 078d59ca9..4e7f6b3a1 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -87,26 +87,39 @@ void MainTab::updateDiveInfo(int dive) UPDATE_TEXT(d, suit); UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, buddy); - if (d) + if (d) { ui->rating->setCurrentStars(d->rating); - else - ui->rating->setCurrentStars(0); - ui->maximumDepthText->setText(d ? get_depth_string(d->maxdepth, TRUE) : ""); - ui->averageDepthText->setText(d ? get_depth_string(d->meandepth, TRUE) : ""); - sacVal.mliter = d ? d->sac : 0; - ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); - ui->otuText->setText(QString("%1").arg( d ? d->otu : 0)); - ui->waterTemperatureText->setText(d ? get_temperature_string(d->watertemp, TRUE) : ""); - ui->airTemperatureText->setText(d ? get_temperature_string(d->airtemp, TRUE) : ""); - if (d && d->surface_pressure.mbar) - /* this is ALWAYS displayed in mbar */ - ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); - else - ui->airPressureText->setText(QString("")); - if (d) + ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); + ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); + ui->otuText->setText(QString("%1").arg(d->otu)); + ui->waterTemperatureText->setText(get_temperature_string(d->watertemp, TRUE)); + ui->airTemperatureText->setText(get_temperature_string(d->airtemp, TRUE)); ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE)); - else - ui->gasUsedText->setText(""); + if ((sacVal.mliter = d->sac) > 0) + ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); + else + ui->sacText->setText(QString()); + if (d->surface_pressure.mbar) + /* this is ALWAYS displayed in mbar */ + ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); + else + ui->airPressureText->setText(QString()); + } else { + ui->rating->setCurrentStars(0); + ui->sacText->setText(QString()); + ui->otuText->setText(QString()); + ui->oxygenHeliumText->setText(QString()); + ui->dateText->setText(QString()); + ui->diveTimeText->setText(QString()); + ui->surfaceIntervalText->setText(QString()); + ui->maximumDepthText->setText(QString()); + ui->averageDepthText->setText(QString()); + ui->visibilityText->setText(QString()); + ui->waterTemperatureText->setText(QString()); + ui->airTemperatureText->setText(QString()); + ui->gasUsedText->setText(QString()); + ui->airPressureText->setText(QString()); + } } void MainTab::on_addCylinder_clicked() -- cgit v1.2.3-70-g09d2 From 7f9fbd229568a85109860c18dd18e1e9928e351f Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Thu, 9 May 2013 08:32:27 +0100 Subject: Horizontally align labels on info widget page. Left aligning text values looked wrong. Use Qobject cast to filter labels from any other qobjects around and set alignment. Doing this via Qt Designer would be tedious. Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4e7f6b3a1..e1ac7c275 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -21,6 +21,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui->setupUi(this); ui->cylinders->setModel(cylindersModel); ui->weights->setModel(weightModel); + + /* example of where code is more concise than Qt designer */ + QList infoTabWidgets = ui->infoTab->children(); + Q_FOREACH( QObject* obj, infoTabWidgets ){ + QLabel* label = qobject_cast(obj); + if (label) + label->setAlignment(Qt::AlignHCenter); + } } void MainTab::clearEquipment() -- cgit v1.2.3-70-g09d2 From 97a044d41f67757de1e5bd0694f6502af1be4f4c Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Fri, 10 May 2013 23:56:05 +0100 Subject: Tweaks to maintab Align statistics tab labels as per infotab. Amend helper function to show degree symbol for temp measurements. Change order of member initialisation list to match order of decl (ProfileGraphicsView::ProfileGraphicsView) Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- profile.c | 2 +- qt-gui.cpp | 6 ++++-- qt-ui/maintab.cpp | 14 ++++++++++++++ qt-ui/profilegraphics.cpp | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/profile.c b/profile.c index ed5d01850..276641bb2 100644 --- a/profile.c +++ b/profile.c @@ -263,7 +263,7 @@ int get_cylinder_pressure_range(struct graphics_context *gc) return FALSE; while (gc->pi.endtempcoord <= SCALEY(gc, gc->pi.minpressure - (gc->topy) * 0.1)) - gc->bottomy -= gc->topy * 0.1; + gc->bottomy -= gc->topy * 0.1 * gc->maxy/abs(gc->maxy); return TRUE; } diff --git a/qt-gui.cpp b/qt-gui.cpp index d70e00379..e3a8ad5aa 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -171,10 +171,12 @@ QString get_temperature_string(temperature_t temp, bool showunit) { if (prefs.units.temperature == units::CELSIUS) { double celsius = mkelvin_to_C(temp.mkelvin); - return QString("%1%2").arg(celsius, 0, 'f', 1).arg(showunit ? _("C") : ""); + return QString("%1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "") + .arg(showunit ? _("C") : ""); } else { double fahrenheit = mkelvin_to_F(temp.mkelvin); - return QString("%1%2").arg(fahrenheit, 0, 'f', 1).arg(showunit ? _("F") : ""); + return QString("%1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE): "") + .arg(showunit ? _("F") : ""); } } diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e1ac7c275..edacf45a4 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -29,6 +29,12 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), if (label) label->setAlignment(Qt::AlignHCenter); } + QList statisticsTabWidgets = ui->statisticsTab->children(); + Q_FOREACH( QObject* obj, statisticsTabWidgets ){ + QLabel* label = qobject_cast(obj); + if (label) + label->setAlignment(Qt::AlignHCenter); + } } void MainTab::clearEquipment() @@ -95,6 +101,7 @@ void MainTab::updateDiveInfo(int dive) UPDATE_TEXT(d, suit); UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, buddy); + /* infoTab */ if (d) { ui->rating->setCurrentStars(d->rating); ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); @@ -128,6 +135,13 @@ void MainTab::updateDiveInfo(int dive) ui->gasUsedText->setText(QString()); ui->airPressureText->setText(QString()); } + /* statisticsTab*/ + /* we can access the stats_selection struct but how to we ensure the relevant dives are selected + * if we don't use the gtk widget to drive this? + * Maybe call process_selected_dives? Or re-write to query our Qt list view. + */ + qDebug("max temp %u",stats_selection.max_temp); + qDebug("min temp %u",stats_selection.min_temp); } void MainTab::on_addCylinder_clicked() diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 6e699fe51..c6a2669ef 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -114,7 +114,7 @@ extern struct ev_select *ev_namelist; extern int evn_allocated; extern int evn_used; -ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) , dive(0), toolTip(0) +ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0) { gc.printer = false; setScene(new QGraphicsScene()); -- cgit v1.2.3-70-g09d2 From 61373eaccf506d022e3c31715b31c2b9432b6f49 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 13 May 2013 15:28:17 -0300 Subject: Fix segfault on mouseOver at the Profile with an invalid dive selected ( trip ) Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 4 ++-- qt-ui/mainwindow.cpp | 5 +++++ qt-ui/mainwindow.h | 2 ++ qt-ui/profilegraphics.cpp | 12 +++++++----- 4 files changed, 16 insertions(+), 7 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index edacf45a4..a43ae563d 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -140,8 +140,8 @@ void MainTab::updateDiveInfo(int dive) * if we don't use the gtk widget to drive this? * Maybe call process_selected_dives? Or re-write to query our Qt list view. */ - qDebug("max temp %u",stats_selection.max_temp); - qDebug("min temp %u",stats_selection.min_temp); +// qDebug("max temp %u",stats_selection.max_temp); +// qDebug("min temp %u",stats_selection.min_temp); } void MainTab::on_addCylinder_clicked() diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 3ba4e6881..3766e2187 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -43,6 +43,8 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); else ui->ListWidget->setCurrentIndex(firstDiveOrTrip); + +#if 0 QAction *actionNextDive = new QAction(this); addAction(actionNextDive); actionNextDive->setShortcut(Qt::Key_Down); @@ -51,6 +53,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), addAction(actionPreviousDive); actionPreviousDive->setShortcut(Qt::Key_Up); connect(actionPreviousDive, SIGNAL(triggered()), this, SLOT(previousDive_triggered())); +#endif } void MainWindow::redrawProfile() @@ -58,6 +61,7 @@ void MainWindow::redrawProfile() ui->ProfileWidget->plot(get_dive(selected_dive)); } +#if 0 void MainWindow::nextDive_triggered() { // Get the current Selection: @@ -147,6 +151,7 @@ void MainWindow::previousDive_triggered() } } } +#endif void MainWindow::on_actionNew_triggered() { diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 8c07d048c..124f70f33 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -69,9 +69,11 @@ private Q_SLOTS: void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); +#if 0 /* keyboard actions */ void nextDive_triggered(); void previousDive_triggered(); +#endif void dive_selection_changed(const QItemSelection& newSelection, const QItemSelection& oldSelection); diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 751d685e5..571214f6f 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -214,15 +214,13 @@ void ProfileGraphicsView::plot(struct dive *d) resetTransform(); zoomLevel = 0; dive = d; + toolTip = 0; } - if(!isVisible()){ + if(!isVisible() || !dive){ return; } - if(!dive) - return; - scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50); QSettings s; @@ -1278,8 +1276,12 @@ void ToolTipItem::collapse() void ToolTipItem::expand() { - QRectF nextRectangle; + if (!title){ + return; + } + + QRectF nextRectangle; double width = 0, height = title->boundingRect().height() + SPACING; Q_FOREACH(ToolTip t, toolTips) { if (t.second->boundingRect().width() > width) -- cgit v1.2.3-70-g09d2 From a6d9f274454c09b39d79a6300de85b4c99722770 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 13 May 2013 15:28:55 -0300 Subject: Change setText(QString()) to clear() Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 84 +++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a43ae563d..d8a966ae1 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -43,37 +43,37 @@ void MainTab::clearEquipment() void MainTab::clearInfo() { - ui->sacText->setText(QString()); - ui->otuText->setText(QString()); - ui->oxygenHeliumText->setText(QString()); - ui->gasUsedText->setText(QString()); - ui->dateText->setText(QString()); - ui->diveTimeText->setText(QString()); - ui->surfaceIntervalText->setText(QString()); - ui->maximumDepthText->setText(QString()); - ui->averageDepthText->setText(QString()); - ui->visibilityText->setText(QString()); - ui->waterTemperatureText->setText(QString()); - ui->airTemperatureText->setText(QString()); - ui->airPressureText->setText(QString()); + ui->sacText->clear(); + ui->otuText->clear(); + ui->oxygenHeliumText->clear(); + ui->gasUsedText->clear(); + ui->dateText->clear(); + ui->diveTimeText->clear(); + ui->surfaceIntervalText->clear(); + ui->maximumDepthText->clear(); + ui->averageDepthText->clear(); + ui->visibilityText->clear(); + ui->waterTemperatureText->clear(); + ui->airTemperatureText->clear(); + ui->airPressureText->clear(); } void MainTab::clearStats() { - ui->maximumDepthAllText->setText(QString()); - ui->minimumDepthAllText->setText(QString()); - ui->averageDepthAllText->setText(QString()); - ui->maximumSacAllText->setText(QString()); - ui->minimumSacAllText->setText(QString()); - ui->averageSacAllText->setText(QString()); - ui->divesAllText->setText(QString()); - ui->maximumTemperatureAllText->setText(QString()); - ui->minimumTemperatureAllText->setText(QString()); - ui->averageTemperatureAllText->setText(QString()); - ui->totalTimeAllText->setText(QString()); - ui->averageTimeAllText->setText(QString()); - ui->longestAllText->setText(QString()); - ui->shortestAllText->setText(QString()); + ui->maximumDepthAllText->clear(); + ui->minimumDepthAllText->clear(); + ui->averageDepthAllText->clear(); + ui->maximumSacAllText->clear(); + ui->minimumSacAllText->clear(); + ui->averageSacAllText->clear(); + ui->divesAllText->clear(); + ui->maximumTemperatureAllText->clear(); + ui->minimumTemperatureAllText->clear(); + ui->averageTemperatureAllText->clear(); + ui->totalTimeAllText->clear(); + ui->averageTimeAllText->clear(); + ui->longestAllText->clear(); + ui->shortestAllText->clear(); } #define UPDATE_TEXT(d, field) \ @@ -113,27 +113,27 @@ void MainTab::updateDiveInfo(int dive) if ((sacVal.mliter = d->sac) > 0) ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); else - ui->sacText->setText(QString()); + ui->sacText->clear(); if (d->surface_pressure.mbar) /* this is ALWAYS displayed in mbar */ ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); else - ui->airPressureText->setText(QString()); + ui->airPressureText->clear(); } else { ui->rating->setCurrentStars(0); - ui->sacText->setText(QString()); - ui->otuText->setText(QString()); - ui->oxygenHeliumText->setText(QString()); - ui->dateText->setText(QString()); - ui->diveTimeText->setText(QString()); - ui->surfaceIntervalText->setText(QString()); - ui->maximumDepthText->setText(QString()); - ui->averageDepthText->setText(QString()); - ui->visibilityText->setText(QString()); - ui->waterTemperatureText->setText(QString()); - ui->airTemperatureText->setText(QString()); - ui->gasUsedText->setText(QString()); - ui->airPressureText->setText(QString()); + ui->sacText->clear(); + ui->otuText->clear(); + ui->oxygenHeliumText->clear(); + ui->dateText->clear(); + ui->diveTimeText->clear(); + ui->surfaceIntervalText->clear(); + ui->maximumDepthText->clear(); + ui->averageDepthText->clear(); + ui->visibilityText->clear(); + ui->waterTemperatureText->clear(); + ui->airTemperatureText->clear(); + ui->gasUsedText->clear(); + ui->airPressureText->clear(); } /* statisticsTab*/ /* we can access the stats_selection struct but how to we ensure the relevant dives are selected -- cgit v1.2.3-70-g09d2 From f9598f062cf8684dd92ac56530c3758e3b1a6d9d Mon Sep 17 00:00:00 2001 From: Henrik Brautaset Aronsen Date: Tue, 14 May 2013 09:28:30 +0200 Subject: Clean up some typos Cosmetic commit to clean up some of the annoying typos in qt-ui Signed-off-by: Henrik Brautaset Aronsen Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 6 +++--- qt-ui/maintab.cpp | 4 ++-- qt-ui/models.cpp | 16 ++++++++-------- qt-ui/models.h | 10 +++++----- qt-ui/profilegraphics.cpp | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index a209118e0..d192d84aa 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -61,9 +61,9 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS Q_FOREACH(const QModelIndex& index, deselected.indexes()) { const QAbstractItemModel *model = index.model(); struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value(); - if (!dive) { // is's a trip! + if (!dive) { // it's a trip! if (model->rowCount(index)) { - expand(index); // leave this - even if it looks like it shouldn't be here. looks like I'v found a Qt bug. + expand(index); // leave this - even if it looks like it shouldn't be here. looks like I've found a Qt bug. // the subselection is removed, but the painting is not. this cleans the area. } } else if (!parents.contains(index.parent())) { @@ -74,7 +74,7 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS Q_FOREACH(const QModelIndex& index, selected.indexes()) { const QAbstractItemModel *model = index.model(); struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value(); - if (!dive) { // is's a trip! + if (!dive) { // it's a trip! if (model->rowCount(index)) { QItemSelection selection; selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0)); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index d8a966ae1..70cb3caea 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -90,7 +90,7 @@ void MainTab::updateDiveInfo(int dive) // it will be called whenever a new dive is selected // I'm already populating the 'notes' box // to show how it can be done. - // If you are unsure what's the name of anything, + // If you are unsure about the name of something, // open the file maintab.ui on the designer // click on the item and check its objectName, // the access is ui->objectName from here on. @@ -136,7 +136,7 @@ void MainTab::updateDiveInfo(int dive) ui->airPressureText->clear(); } /* statisticsTab*/ - /* we can access the stats_selection struct but how to we ensure the relevant dives are selected + /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected * if we don't use the gtk widget to drive this? * Maybe call process_selected_dives? Or re-write to query our Qt list view. */ diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 68ab402cd..0b933aeb1 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -336,13 +336,13 @@ void TankInfoModel::update() TreeItemDT::~TreeItemDT() { - qDeleteAll(childs); + qDeleteAll(children); } int TreeItemDT::row() const { if (parent) - return parent->childs.indexOf(const_cast(this)); + return parent->children.indexOf(const_cast(this)); return 0; } @@ -637,7 +637,7 @@ const TreeItemDT* parentItem = (!parent.isValid()) ? rootItem : static_cast(parent.internalPointer()); - TreeItemDT* childItem = parentItem->childs[row]; + TreeItemDT* childItem = parentItem->children[row]; return (childItem) ? createIndex(row, column, childItem) : QModelIndex(); } @@ -665,7 +665,7 @@ int DiveTripModel::rowCount(const QModelIndex& parent) const else parentItem = static_cast(parent.internalPointer()); - int amount = parentItem->childs.count(); + int amount = parentItem->children.count(); return amount; } @@ -684,19 +684,19 @@ void DiveTripModel::setupModelData() if (!trip) { diveItem->parent = rootItem; - rootItem->childs.push_back(diveItem); + rootItem->children.push_back(diveItem); continue; } if (!trips.keys().contains(trip)) { TripItem* tripItem = new TripItem(); tripItem->trip = trip; tripItem->parent = rootItem; - tripItem->childs.push_back(diveItem); + tripItem->children.push_back(diveItem); trips[trip] = tripItem; - rootItem->childs.push_back(tripItem); + rootItem->children.push_back(tripItem); continue; } TripItem* tripItem = trips[trip]; - tripItem->childs.push_back(diveItem); + tripItem->children.push_back(diveItem); } } diff --git a/qt-ui/models.h b/qt-ui/models.h index 307cdf5c3..ac533fd71 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -14,7 +14,7 @@ #include "../divelist.h" /* Encapsulates the tank_info global variable - * to show on Qt`s Model View System.*/ + * to show on Qt's Model View System.*/ class TankInfoModel : public QAbstractTableModel { Q_OBJECT public: @@ -50,9 +50,9 @@ public: void clear(); void update(); private: - /* 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. */ + /* 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 usedRows; }; @@ -94,7 +94,7 @@ public: virtual QVariant data ( int column, int role ) const; int row() const; - QList childs; + QList children; TreeItemDT *parent; }; diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 571214f6f..8f25f1932 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -663,7 +663,7 @@ void ProfileGraphicsView::plot_temperature_text() /* don't print a temperature * if it's been less than 5min and less than a 2K change OR * if it's been less than 2min OR if the change from the - * last print is less than .4K (and therefore less than 1F */ + * last print is less than .4K (and therefore less than 1F) */ if (((sec < last + 300) && (abs(mkelvin - last_printed_temp) < 2000)) || (sec < last + 120) || (abs(mkelvin - last_printed_temp) < 400)) @@ -806,7 +806,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev) int i, depth = 0; struct plot_info *pi = &gc.pi; - /* is plotting this event disabled? */ + /* is plotting of this event disabled? */ if (ev->name) { for (i = 0; i < evn_used; i++) { if (! strcmp(ev->name, ev_namelist[i].ev_name)) { -- cgit v1.2.3-70-g09d2