[PATCH v2] Switch some columns to right alignment in divelist

Anton Lundin glance at acc.umu.se
Thu Sep 11 13:59:52 PDT 2014


Some columns in the dive list makes more sense to have right aligned
than left aligned. This switches the numeric columns to right alignment
so they is more easily compared visually.

But, we keep the NR-column left-aligned because we use its left
indentation as dive-in-a-trip marker.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 qt-ui/models.cpp | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 5266130..ce0f864 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1063,6 +1063,34 @@ static int nitrox_sort_value(struct dive *dive)
 	return he * 1000 + o2;
 }
 
+static QVariant dive_table_alignment(int column)
+{
+	QVariant retVal;
+	switch (column) {
+	case DiveTripModel::DEPTH:
+	case DiveTripModel::DURATION:
+	case DiveTripModel::TEMPERATURE:
+	case DiveTripModel::TOTALWEIGHT:
+	case DiveTripModel::SAC:
+	case DiveTripModel::OTU:
+	case DiveTripModel::MAXCNS:
+		// Right align numeric columns
+		retVal = int(Qt::AlignRight | Qt::AlignVCenter);
+		break;
+	// NR needs to be left aligned becase its the indent marker for trips too
+	case DiveTripModel::NR:
+	case DiveTripModel::DATE:
+	case DiveTripModel::RATING:
+	case DiveTripModel::SUIT:
+	case DiveTripModel::CYLINDER:
+	case DiveTripModel::GAS:
+	case DiveTripModel::LOCATION:
+		retVal = int(Qt::AlignLeft | Qt::AlignVCenter);
+		break;
+	}
+	return retVal;
+}
+
 QVariant DiveItem::data(int column, int role) const
 {
 	QVariant retVal;
@@ -1070,7 +1098,7 @@ QVariant DiveItem::data(int column, int role) const
 
 	switch (role) {
 	case Qt::TextAlignmentRole:
-		retVal = int(Qt::AlignLeft | Qt::AlignVCenter);
+		retVal = dive_table_alignment(column);
 		break;
 	case DiveTripModel::SORT_ROLE:
 		Q_ASSERT(dive != NULL);
@@ -1306,6 +1334,9 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
 		return ret;
 
 	switch (role) {
+	case Qt::TextAlignmentRole:
+		ret = dive_table_alignment(section);
+		break;
 	case Qt::FontRole:
 		ret = defaultModelFont();
 		break;
-- 
1.9.1



More information about the subsurface mailing list