summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-02 14:05:53 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-02 14:49:56 -0700
commitc4e2c322a3f6505880b9330e577129e0110ed2ba (patch)
tree3405495f6788522929f251e0e6ffdd74fedd3c4c /qt-ui
parentf9c97ff97d072d6a4cb934a50427dc69382281e0 (diff)
downloadsubsurface-c4e2c322a3f6505880b9330e577129e0110ed2ba.tar.gz
Set better column widths in the dive list
This code seems rather crude to me. I'm sure this could be done better. This also makes the column alignment work again. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/mainwindow.cpp34
-rw-r--r--qt-ui/models.cpp11
2 files changed, 39 insertions, 6 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 9901e4186..8bf03531f 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -14,6 +14,8 @@
#include <QSortFilterProxyModel>
#include <QSettings>
#include <QCloseEvent>
+#include <QApplication>
+#include <QFontMetrics>
#include "divelistview.h"
#include "starwidget.h"
@@ -32,6 +34,38 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
sortModel->setSourceModel(model);
ui->ListWidget->setModel(sortModel);
+ /* figure out appropriate widths for the columns. The strings chosen
+ * are somewhat random (but at least we're trying to allow them to be
+ * localized so they are somewhat universal) */
+ QFontMetrics fm(QApplication::font());
+ int pixelsWide = fm.width(tr("Trip Wed, Mar 29, 2000 (100 dives)"));
+ ui->ListWidget->setColumnWidth(TreeItemDT::DATE, pixelsWide);
+
+ /* all the columns that have usually up to four numbers plus maybe
+ * a decimal separator */
+ pixelsWide = fm.width("000.0");
+ ui->ListWidget->setColumnWidth(TreeItemDT::DEPTH, pixelsWide);
+ ui->ListWidget->setColumnWidth(TreeItemDT::TEMPERATURE, pixelsWide);
+ ui->ListWidget->setColumnWidth(TreeItemDT::TOTALWEIGHT, pixelsWide);
+ ui->ListWidget->setColumnWidth(TreeItemDT::SAC, pixelsWide);
+ ui->ListWidget->setColumnWidth(TreeItemDT::OTU, pixelsWide);
+
+ /* this one is likely dominated by the header (need extra pixels) */
+ pixelsWide = fm.width(tr("maxCNS")) + 10;
+ ui->ListWidget->setColumnWidth(TreeItemDT::MAXCNS, pixelsWide);
+
+ /* the rest we try to cover with reasonable sample text again */
+ pixelsWide = fm.width(" 123456");
+ ui->ListWidget->setColumnWidth(TreeItemDT::NR, pixelsWide);
+ pixelsWide = fm.width("00:00:00");
+ ui->ListWidget->setColumnWidth(TreeItemDT::DURATION, pixelsWide);
+ pixelsWide = fm.width(tr("twin HP119"));
+ ui->ListWidget->setColumnWidth(TreeItemDT::CYLINDER, pixelsWide);
+ pixelsWide = fm.width("888888");
+ ui->ListWidget->setColumnWidth(TreeItemDT::NITROX, pixelsWide);
+ pixelsWide = fm.width(tr("7mm wet, farmer johns and jacket"));
+ ui->ListWidget->setColumnWidth(TreeItemDT::SUIT, pixelsWide);
+
setWindowIcon(QIcon(":subsurface-icon"));
readSettings();
}
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 68f575ec8..5c7fc7a8b 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -434,7 +434,8 @@ QVariant DiveItem::data(int column, int role) const
{
QVariant retVal;
- if (role == Qt::TextAlignmentRole) {
+ switch (role) {
+ case Qt::TextAlignmentRole:
switch (column) {
case DATE: /* fall through */
case SUIT: /* fall through */
@@ -445,9 +446,8 @@ QVariant DiveItem::data(int column, int role) const
retVal = Qt::AlignRight;
break;
}
- }
-
- if (role == Qt::DisplayRole) {
+ break;
+ case Qt::DisplayRole:
switch (column) {
case NR:
retVal = dive->number;
@@ -492,6 +492,7 @@ QVariant DiveItem::data(int column, int role) const
retVal = dive->rating;
break;
}
+ break;
}
return retVal;
}
@@ -598,8 +599,6 @@ QVariant DiveTripModel::data(const QModelIndex& index, int role) const
if (!index.isValid())
return QVariant();
- if (role != Qt::DisplayRole)
- return QVariant();
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());