On Mon, Mar 10, 2014 at 2:43 PM, Dirk Hohndel <[email protected]> wrote:
>
> On Mon, 2014-03-10 at 14:02 -0500, Lakshman wrote:
> > > I'm still mulling over your other patch. I don't like it in the normal
> > > 'view' of Subsurface because it's redundant information (if there is a
> > > temperature, it's shown with a unit). But in edit and add mode I think
> > > it's a great improvement.
> >
> > You are right, when in normal view it is redundant. When I started I
> > kept in mind it for 'edit and add' mode, and ignored the normal mode.
> > I think to change it I need to go through the code to see, what
> > variable signals the edit and add mode and update accordingly. I will
> > be on it. Please guide me if I am going in a wrong direction.
>
> This is the easiest way to tell if you are in 'display' mode or in
> 'edit' or 'add' mode:
>
> if (DivePlannerPointsModel::instance()->currentMode() != 
> DivePlannerPointsModel::NOTHING)
>         // I'm in edit or add mode

Thanks for the tip Dirk. I experimented with this option, later
realized that, when 'acceptChanges()' or 'rejectChanges()' functions
are called, Mode in DivePlannerPointsModel is changing to 'NOTHING',
and it remains in the same state even if the user starts editing the
file. I tried "isEditing()" function too, whose state doesnot change,
then I realized this may not be what I am looking for. However the
hint to me is that, whenever user starts editing or stops,
"displayMessage" and "hideMessage" are triggered, so I used them for
the time being and the attached patch is written on this basis and
works correctly, i.e. units are not shown when it is not required.

Regarding making the update clean, i.e. not depending on
"displayMessage" and "hideMessage" methods, I need to go through the
stages and modifications made to Mode in DivePlannerPointsModel, which
is being changed at multiple places. I will work in this direction
too, in case you feel cleaning is needed immediately. Can you please
let me know your opinion.

>
> Thanks for your continued enthusiasm.
>
> /D
>

Thank you,
Lakshman
From e630d81ee550b489399c3cda5e76a594b3f1db74 Mon Sep 17 00:00:00 2001
From: Lakshman Anumolu <[email protected]>
Date: Sun, 9 Mar 2014 01:07:40 -0600
Subject: [PATCH] 	Feature to show units with labels.

	Currently when user wants to add a new dive information,
	the ways to know what unit system is being used are

	 - Through preferences panel.
	 - Save the dive information, which displays units in
	   the text field.

	This patch provides an option to the user to show current
	unit system by displaying the unit on the side of the label
	when the user is editing the fields.

	This feature can be enabled or disabled by using the new
	checkbox option i.e. `Show units in text labels` included
	in `preferences->units` section.

Signed-off-by: Lakshman Anumolu <[email protected]>
---
 pref.h                |  1 +
 qt-ui/maintab.cpp     | 13 +++++++++++++
 qt-ui/maintab.h       |  1 +
 qt-ui/preferences.cpp |  3 +++
 qt-ui/preferences.ui  | 16 +++++++++++++++-
 subsurfacestartup.c   |  3 ++-
 6 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/pref.h b/pref.h
index dd895f0..a5d90a9 100644
--- a/pref.h
+++ b/pref.h
@@ -40,6 +40,7 @@ struct preferences {
 	short show_sac;
 	bool display_unused_tanks;
 	bool zoomed_plot;
+	bool text_label_with_units;
 };
 enum unit_system_values {
 	METRIC,
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 068d703..45483f1 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -201,6 +201,7 @@ void MainTab::hideMessage()
 	ui.diveEquipmentMessage->animatedHide();
 	ui.diveInfoMessage->animatedHide();
 	ui.diveStatisticsMessage->animatedHide();
+	updateTextLabels();
 }
 
 void MainTab::closeMessage()
@@ -222,6 +223,18 @@ void MainTab::displayMessage(QString str)
 	ui.diveInfoMessage->animatedShow();
 	ui.diveStatisticsMessage->setText(str);
 	ui.diveStatisticsMessage->animatedShow();
+	updateTextLabels(true);
+}
+
+void MainTab::updateTextLabels(bool showUnits)
+{
+	if (showUnits && prefs.text_label_with_units) {
+		ui.airTempLabel->setText(QApplication::translate("MainTab", "Air temp [%1]").arg(get_temp_unit()));
+		ui.waterTempLabel->setText(QApplication::translate("MainTab", "Water temp [%1]").arg(get_temp_unit()));
+	} else {
+		ui.airTempLabel->setText(QApplication::translate("MainTab", "Air temp", 0, QApplication::UnicodeUTF8));
+		ui.waterTempLabel->setText(QApplication::translate("MainTab", "Water temp", 0, QApplication::UnicodeUTF8));
+	}
 }
 
 void MainTab::enableEdition(EditMode newEditMode)
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 946b673..9da1e89 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -94,6 +94,7 @@ slots:
 	void displayMessage(QString str);
 	void enableEdition(EditMode newEditMode = NONE);
 	void toggleTriggeredColumn();
+	void updateTextLabels(bool showUnits = false);
 
 private:
 	Ui::MainTab ui;
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index 2c72ceb..0312385 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -75,6 +75,7 @@ void PreferencesDialog::setUiFromPrefs()
 	ui.cuft->setChecked(prefs.units.volume == units::CUFT);
 	ui.kg->setChecked(prefs.units.weight == units::KG);
 	ui.lbs->setChecked(prefs.units.weight == units::LBS);
+	ui.text_label_with_units->setChecked(prefs.text_label_with_units);
 
 	ui.font->setCurrentFont(QString(prefs.divelist_font));
 	ui.fontsize->setValue(prefs.font_size);
@@ -190,6 +191,7 @@ void PreferencesDialog::syncSettings()
 	s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER);
 	s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG);
 	s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
+	SB("text_label_with_units", ui.text_label_with_units);
 	s.endGroup();
 	// Defaults
 	s.beginGroup("GeneralSettings");
@@ -244,6 +246,7 @@ void PreferencesDialog::loadSettings()
 		GET_UNIT("weight", weight, units::LBS, units::KG);
 	}
 	GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
+	GET_BOOL("text_label_with_units", text_label_with_units);
 	s.endGroup();
 	s.beginGroup("TecDetails");
 	GET_BOOL("po2graph", pp_graphs.po2);
diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui
index 988c548..115e935 100644
--- a/qt-ui/preferences.ui
+++ b/qt-ui/preferences.ui
@@ -478,7 +478,21 @@
             </widget>
            </item>
           </layout>
-         </item>
+	 </item>
+	 <item>
+	  <layout class="QHBoxLayout" name="text_label_with_units_hbox">
+	   <item>
+	    <widget class="QCheckBox" name="text_label_with_units">
+	     <property name="enabled">
+	      <bool>true</bool>
+	     </property>
+	     <property name="text">
+	      <string>Show units in text labels</string>
+	     </property>
+	    </widget>
+	   </item>
+	  </layout>
+	 </item>
          <item>
           <spacer name="verticalSpacer">
            <property name="orientation">
diff --git a/subsurfacestartup.c b/subsurfacestartup.c
index efdcb9a..3f410af 100644
--- a/subsurfacestartup.c
+++ b/subsurfacestartup.c
@@ -29,7 +29,8 @@ struct preferences default_prefs = {
 	.font_size = -1,
 	.display_invalid_dives = false,
 	.show_sac = false,
-	.display_unused_tanks = false
+	.display_unused_tanks = false,
+	.text_label_with_units = false
 };
 
 struct units *get_units()
-- 
1.8.3.2

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to