Sunday Patches.
Dirk Hohndel
dirk at hohndel.org
Sun Jun 16 18:17:55 PDT 2013
Very nice.
I still don't get good column widths by default. Something is odd there.
But if I adjust the columns then things look quite nice.
Progress. Not perfect, yet, but progress.
/D
On Sun, 2013-06-16 at 17:54 -0300, Tomaz Canabrava wrote:
> Dirk, Linus:
>
> This fixes a few annoyances that Linus described - Not all of them, but this
> should make the app way more usable for editing Cylinders and Weigths.
>
> Test there and tell me what's wrong so I can continue.
>
> There'ss still the 'multi dive edition' missing. But I'm trying to concentrate
> on the Dive Plan ( and failing miserably )
>
>
> Tomaz
>
>
> The following changes since commit 84d4a2dae069a2e728cea8d7a4506921b558603f:
>
> Partially fix dive downloading (2013-06-15 17:03:23 -0700)
>
> are available in the git repository at:
>
> https://github.com/tcanabrava/subsurface moreLinusFixes
>
> for you to fetch changes up to c917b29701470398b51aa5ad9541275825d912fd:
>
> Save / Restore the sizes of the columns in Cylinders / Weigth widgets
> (2013-06-16 14:36:23 -0300)
>
> ----------------------------------------------------------------
> Tomaz Canabrava (7):
> Create a 'ComboBoxDelegate' to concentrate the comboboxness of
> delegates.
> Made all models have the same font.
> Better handling of default sizes on the Cylinder and Weight widgets
> Make the columns have a sane default width for 'type'
> Remove the Vertical Header on Cylinder and Weigth edit
> Removed the grid lines of the table views.
> Save / Restore the sizes of the columns in Cylinders / Weigth widgets
>
> qt-ui/maintab.cpp | 53
> ++++++++++++++++++++++++++++++++++++++++++++++++++---
> qt-ui/maintab.h | 4 ++++
> qt-ui/maintab.ui | 48
> ++++++++++++++++++++++++++++++++++++++++++++++--
> qt-ui/modeldelegates.cpp | 62
> ++++++++++++++++++++++++++------------------------------------
> qt-ui/modeldelegates.h | 17 ++++++++++++-----
> qt-ui/models.cpp | 157
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------
> qt-ui/models.h | 7 ++++++-
> 7 files changed, 246 insertions(+), 102 deletions(-)
>
> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
> index ea1687a..c6b49da 100644
> --- a/qt-ui/maintab.cpp
> +++ b/qt-ui/maintab.cpp
> @@ -16,6 +16,7 @@
> #include <QLabel>
> #include <QDebug>
> #include <QSet>
> +#include <QSettings>
>
> MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
> ui(new Ui::MainTab()),
> @@ -79,13 +80,17 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
> connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders-
>
> >model(), SLOT(remove(QModelIndex)));
> connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights-
>
> >model(), SLOT(remove(QModelIndex)));
>
> - ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
> - ui->cylinders->horizontalHeader()-
>
> >setResizeMode(QHeaderView::ResizeToContents);
> + QFontMetrics metrics(defaultModelFont());
> + QFontMetrics metrics2(font());
> +
> ui->cylinders->horizontalHeader()-
>
> >setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
> + ui->cylinders->verticalHeader()->setDefaultSectionSize(
> metrics.height() +8 );
> ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new
> TankInfoDelegate());
> - ui->weights->setColumnWidth(WeightModel::REMOVE, 24);
> +
> ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE ,
> QHeaderView::Fixed);
> + ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height()
> +8 );
> ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new
> WSInfoDelegate());
> + initialUiSetup();
> }
>
> // We need to manually position the 'plus' on cylinder and weight.
> @@ -474,3 +479,45 @@ void MainTab::on_visibility_valueChanged(int value)
> return;
> currentDive->visibility = value;
> }
> +
> +void MainTab::hideEvent(QHideEvent* event)
> +{
> + QSettings s;
> + s.beginGroup("MainTab");
> + s.beginGroup("Cylinders");
> + for (int i = 0; i < CylindersModel::COLUMNS; i++) {
> + s.setValue(QString("colwidth%1").arg(i), ui->cylinders-
>
> >columnWidth(i));
> + }
> + s.endGroup();
> + s.beginGroup("Weights");
> + for (int i = 0; i < WeightModel::COLUMNS; i++) {
> + s.setValue(QString("colwidth%1").arg(i), ui->weights-
>
> >columnWidth(i));
> + }
> + s.endGroup();
> + s.sync();
> +}
> +
> +void MainTab::initialUiSetup()
> +{
> + QSettings s;
> + s.beginGroup("MainTab");
> + s.beginGroup("Cylinders");
> + for (int i = 0; i < CylindersModel::COLUMNS; i++) {
> + QVariant width = s.value(QString("colwidth%1").arg(i));
> + if (width.isValid())
> + ui->cylinders->setColumnWidth(i, width.toInt());
> + else
> + ui->cylinders->resizeColumnToContents(i);
> + }
> + s.endGroup();
> + s.beginGroup("Weights");
> + for (int i = 0; i < WeightModel::COLUMNS; i++) {
> + QVariant width = s.value(QString("colwidth%1").arg(i));
> + if (width.isValid())
> + ui->weights->setColumnWidth(i, width.toInt());
> + else
> + ui->weights->resizeColumnToContents(i);
> + }
> + s.endGroup();
> +
> +}
> diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
> index b92db67..124bcff 100644
> --- a/qt-ui/maintab.h
> +++ b/qt-ui/maintab.h
> @@ -40,6 +40,10 @@ public:
> bool eventFilter(QObject* , QEvent*);
> virtual void resizeEvent(QResizeEvent*);
> virtual void showEvent(QShowEvent*);
> + virtual void hideEvent(QHideEvent* );
> +
> + void initialUiSetup();
> +
>
> public Q_SLOTS:
> void addCylinder_clicked();
> diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
> index 733a605..c42dc46 100644
> --- a/qt-ui/maintab.ui
> +++ b/qt-ui/maintab.ui
> @@ -14,7 +14,7 @@
> <string>TabWidget</string>
> </property>
> <property name="currentIndex">
> - <number>0</number>
> + <number>1</number>
> </property>
> <widget class="QWidget" name="notesTab">
> <attribute name="title">
> @@ -192,6 +192,12 @@
> <property name="alternatingRowColors">
> <bool>true</bool>
> </property>
> + <property name="showGrid">
> + <bool>false</bool>
> + </property>
> + <attribute name="verticalHeaderVisible">
> + <bool>false</bool>
> + </attribute>
> </widget>
> </item>
> </layout>
> @@ -202,7 +208,45 @@
> </property>
> <layout class="QVBoxLayout" name="verticalLayout_3">
> <item>
> - <widget class="QTableView" name="weights"/>
> + <widget class="QTableView" name="weights">
> + <property name="styleSheet">
> + <string notr="true"> QTableView {
> + show-decoration-selected: 1;
> + }
> +
> + QTableView::item {
> + border: 1px solid #d9d9d9;
> + border-top-color: transparent;
> + border-bottom-color: transparent;
> + padding: 2px;
> + }
> +
> + QTableView::item:hover {
> + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd,
> stop: 1 #cbdaf1);
> + border: 1px solid #bfcde4;
> + }
> +
> + QTableView::item:selected {
> + border: 1px solid #567dbc;
> + }
> +
> + QTableView::item:selected:active{
> + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1,
> stop: 1 #567dbc);
> + }
> +
> + QTableView::item:selected:!active {
> + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8,
> stop: 1 #577fbf);
> + }
> +
> +</string>
> + </property>
> + <property name="showGrid">
> + <bool>false</bool>
> + </property>
> + <attribute name="verticalHeaderVisible">
> + <bool>false</bool>
> + </attribute>
> + </widget>
> </item>
> </layout>
> </widget>
> diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
> index c90a1e8..01f5197 100644
> --- a/qt-ui/modeldelegates.cpp
> +++ b/qt-ui/modeldelegates.cpp
> @@ -17,7 +17,6 @@ StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
> QStyledItemDelegate(parent),
> parentWidget(parent)
> {
> -
> }
>
> void StarWidgetsDelegate::paint(QPainter* painter, const
> QStyleOptionViewItem& option, const QModelIndex& index) const
> @@ -51,19 +50,11 @@ QSize StarWidgetsDelegate::sizeHint(const
> QStyleOptionViewItem& option, const QM
> return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1),
> IMG_SIZE);
> }
>
> -QWidget* TankInfoDelegate::createEditor(QWidget* parent, const
> QStyleOptionViewItem& option, const QModelIndex& index) const
> +ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject*
> parent): QStyledItemDelegate(parent), model(model)
> {
> - QComboBox *comboDelegate = new QComboBox(parent);
> - TankInfoModel *model = TankInfoModel::instance();
> - comboDelegate->setModel(model);
> - comboDelegate->setEditable(true);
> - comboDelegate->setAutoCompletion(true);
> - comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
> - comboDelegate->completer()-
>
> >setCompletionMode(QCompleter::PopupCompletion);
> - return comboDelegate;
> }
>
> -void TankInfoDelegate::setEditorData(QWidget* editor, const QModelIndex&
> index) const
> +void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex&
> index) const
> {
> QComboBox *c = qobject_cast<QComboBox*>(editor);
> QString data = index.model()->data(index, Qt::DisplayRole).toString();
> @@ -74,6 +65,28 @@ void TankInfoDelegate::setEditorData(QWidget* editor, const
> QModelIndex& index)
> c->setEditText(data);
> }
>
> +QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const
> QStyleOptionViewItem& option, const QModelIndex& index) const
> +{
> + QComboBox *comboDelegate = new QComboBox(parent);
> + comboDelegate->setModel(model);
> + comboDelegate->setEditable(true);
> + comboDelegate->setAutoCompletion(true);
> + comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
> + comboDelegate->completer()-
>
> >setCompletionMode(QCompleter::PopupCompletion);
> + return comboDelegate;
> +}
> +
> +void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const
> QStyleOptionViewItem& option, const QModelIndex& index) const
> +{
> + QRect defaultRect = option.rect;
> + defaultRect.setX( defaultRect.x() -1);
> + defaultRect.setY( defaultRect.y() -1);
> + defaultRect.setWidth( defaultRect.width() + 2);
> + defaultRect.setHeight( defaultRect.height() + 2);
> + editor->setGeometry(defaultRect);
> +}
> +
> +
> void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel*
> model, const QModelIndex& thisindex) const
> {
> QComboBox *c = qobject_cast<QComboBox*>(editor);
> @@ -97,31 +110,8 @@ void TankInfoDelegate::setModelData(QWidget* editor,
> QAbstractItemModel* model,
> mymodel->passInData(model->index(thisindex.row(),
> CylindersModel::SIZE), tankSize);
> }
>
> -TankInfoDelegate::TankInfoDelegate(QObject* parent):
> QStyledItemDelegate(parent)
> -{
> -}
> -
> -QWidget* WSInfoDelegate::createEditor(QWidget* parent, const
> QStyleOptionViewItem& option, const QModelIndex& index) const
> +TankInfoDelegate::TankInfoDelegate(QObject* parent):
> ComboBoxDelegate(TankInfoModel::instance(), parent)
> {
> - QComboBox *comboDelegate = new QComboBox(parent);
> - WSInfoModel *model = WSInfoModel::instance();
> - comboDelegate->setModel(model);
> - comboDelegate->setEditable(true);
> - comboDelegate->setAutoCompletion(true);
> - comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
> - comboDelegate->completer()-
>
> >setCompletionMode(QCompleter::PopupCompletion);
> - return comboDelegate;
> -}
> -
> -void WSInfoDelegate::setEditorData(QWidget* editor, const QModelIndex& index)
> const
> -{
> - QComboBox *c = qobject_cast<QComboBox*>(editor);
> - QString data = index.model()->data(index, Qt::DisplayRole).toString();
> - int i = c->findText(data);
> - if (i != -1)
> - c->setCurrentIndex(i);
> - else
> - c->setEditText(data);
> }
>
> void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
> const QModelIndex& thisindex) const
> @@ -145,6 +135,6 @@ void WSInfoDelegate::setModelData(QWidget* editor,
> QAbstractItemModel* model, co
> mymodel->passInData(model->index(thisindex.row(),
> WeightModel::WEIGHT), grams);
> }
>
> -WSInfoDelegate::WSInfoDelegate(QObject* parent): QStyledItemDelegate(parent)
> +WSInfoDelegate::WSInfoDelegate(QObject* parent):
> ComboBoxDelegate(WSInfoModel::instance(), parent)
> {
> }
> diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
> index 79fbe29..a33fc89 100644
> --- a/qt-ui/modeldelegates.h
> +++ b/qt-ui/modeldelegates.h
> @@ -13,21 +13,28 @@ private:
> QWidget *parentWidget;
> };
>
> -class TankInfoDelegate : public QStyledItemDelegate{
> +class ComboBoxDelegate : public QStyledItemDelegate{
> Q_OBJECT
> public:
> - explicit TankInfoDelegate(QObject* parent = 0);
> + explicit ComboBoxDelegate(QAbstractItemModel *model, QObject* parent =
> 0);
> virtual QWidget* createEditor(QWidget* parent, const
> QStyleOptionViewItem& option, const QModelIndex& index) const;
> virtual void setEditorData(QWidget* editor, const QModelIndex& index)
> const;
> + virtual void updateEditorGeometry(QWidget* editor, const
> QStyleOptionViewItem& option, const QModelIndex& index) const;
> +protected:
> + QAbstractItemModel *model;
> +};
> +
> +class TankInfoDelegate : public ComboBoxDelegate{
> + Q_OBJECT
> +public:
> + explicit TankInfoDelegate(QObject* parent = 0);
> virtual void setModelData(QWidget* editor, QAbstractItemModel* model,
> const QModelIndex& index) const;
> };
>
> -class WSInfoDelegate : public QStyledItemDelegate{
> +class WSInfoDelegate : public ComboBoxDelegate{
> Q_OBJECT
> public:
> explicit WSInfoDelegate(QObject* parent = 0);
> - virtual QWidget* createEditor(QWidget* parent, const
> QStyleOptionViewItem& option, const QModelIndex& index) const;
> - virtual void setEditorData(QWidget* editor, const QModelIndex& index)
> const;
> virtual void setModelData(QWidget* editor, QAbstractItemModel* model,
> const QModelIndex& index) const;
> };
>
> diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
> index b85c067..6d64599 100644
> --- a/qt-ui/models.cpp
> +++ b/qt-ui/models.cpp
> @@ -14,6 +14,13 @@
> #include <QFont>
> #include <QIcon>
>
> +QFont defaultModelFont()
> +{
> + QFont font;
> + font.setPointSizeF( font.pointSizeF() * 0.8);
> + return font;
> +}
> +
> CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent),
> current(0), rows(0)
> {
> }
> @@ -21,15 +28,14 @@ CylindersModel::CylindersModel(QObject* parent):
> QAbstractTableModel(parent), cu
> QVariant CylindersModel::headerData(int section, Qt::Orientation orientation,
> int role) const
> {
> QVariant ret;
> - QFont font;
>
> if (orientation == Qt::Vertical)
> return ret;
>
> switch (role) {
> case Qt::FontRole:
> - font.setPointSizeF(font.pointSizeF() * 0.8);
> - return font;
> + ret = defaultModelFont();
> + break;
> case Qt::DisplayRole:
> switch(section) {
> case TYPE: ret = tr("Type"); break;
> @@ -52,7 +58,6 @@ int CylindersModel::columnCount(const QModelIndex& parent)
> const
> QVariant CylindersModel::data(const QModelIndex& index, int role) const
> {
> QVariant ret;
> - QFont font;
>
> if (!index.isValid() || index.row() >= MAX_CYLINDERS)
> return ret;
> @@ -60,11 +65,10 @@ QVariant CylindersModel::data(const QModelIndex& index,
> int role) const
> cylinder_t *cyl = ¤t->cylinder[index.row()];
> switch (role) {
> case Qt::FontRole:
> - font.setPointSizeF(font.pointSizeF() * 0.80);
> - ret = font;
> + ret = defaultModelFont();
> break;
> case Qt::TextAlignmentRole:
> - ret = Qt::AlignRight;
> + ret = Qt::AlignHCenter;
> break;
> case Qt::DisplayRole:
> case Qt::EditRole:
> @@ -336,7 +340,6 @@ int WeightModel::columnCount(const QModelIndex& parent)
> const
> QVariant WeightModel::data(const QModelIndex& index, int role) const
> {
> QVariant ret;
> - QFont font;
> if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
> return ret;
>
> @@ -344,8 +347,7 @@ QVariant WeightModel::data(const QModelIndex& index, int
> role) const
>
> switch (role) {
> case Qt::FontRole:
> - font.setPointSizeF(font.pointSizeF() * 0.80);
> - ret = font;
> + ret = defaultModelFont();
> break;
> case Qt::TextAlignmentRole:
> ret = Qt::AlignRight;
> @@ -429,14 +431,12 @@ int WeightModel::rowCount(const QModelIndex& parent)
> const
> QVariant WeightModel::headerData(int section, Qt::Orientation orientation,
> int role) const
> {
> QVariant ret;
> - QFont font;
> if (orientation == Qt::Vertical)
> return ret;
>
> switch (role) {
> case Qt::FontRole:
> - font.setPointSizeF(font.pointSizeF() * 0.8);
> - ret = font;
> + ret = defaultModelFont();
> break;
> case Qt::DisplayRole:
> switch(section) {
> @@ -534,16 +534,21 @@ QVariant WSInfoModel::data(const QModelIndex& index, int
> role) const
> struct ws_info *info = &ws_info[index.row()];
>
> int gr = info->grams;
> -
> - if (role == Qt::DisplayRole || role == Qt::EditRole) {
> - switch(index.column()) {
> - case GR:
> - ret = gr;
> - break;
> - case DESCRIPTION:
> - ret = QString(info->name);
> - break;
> - }
> + switch(role){
> + case Qt::FontRole :
> + ret = defaultModelFont();
> + break;
> + case Qt::DisplayRole :
> + case Qt::EditRole :
> + switch(index.column()) {
> + case GR:
> + ret = gr;
> + break;
> + case DESCRIPTION:
> + ret = QString(info->name);
> + break;
> + }
> + break;
> }
> return ret;
> }
> @@ -555,15 +560,20 @@ QVariant WSInfoModel::headerData(int section,
> Qt::Orientation orientation, int r
> if (orientation != Qt::Horizontal)
> return ret;
>
> - if (role == Qt::DisplayRole) {
> - switch(section) {
> - case GR:
> - ret = tr("kg");
> - break;
> - case DESCRIPTION:
> - ret = tr("Description");
> - break;
> - }
> + switch(role){
> + case Qt::FontRole :
> + ret = defaultModelFont();
> + break;
> + case Qt::DisplayRole :
> + switch(section) {
> + case GR:
> + ret = tr("kg");
> + break;
> + case DESCRIPTION:
> + ret = tr("Description");
> + break;
> + }
> + break;
> }
> return ret;
> }
> @@ -573,10 +583,20 @@ int WSInfoModel::rowCount(const QModelIndex& parent)
> const
> return rows+1;
> }
>
> +const QString& WSInfoModel::biggerString() const
> +{
> + return biggerEntry;
> +}
> +
> WSInfoModel::WSInfoModel() : QAbstractTableModel(), rows(-1)
> {
> struct ws_info *info = ws_info;
> - for (info = ws_info; info->name; info++, rows++);
> + for (info = ws_info; info->name; info++, rows++){
> + QString wsInfoName(info->name);
> + if( wsInfoName.count() > biggerEntry.count()){
> + biggerEntry = wsInfoName;
> + }
> + }
>
> if (rows > -1) {
> beginInsertRows(QModelIndex(), 0, rows);
> @@ -606,6 +626,11 @@ TankInfoModel* TankInfoModel::instance()
> return self;
> }
>
> +const QString& TankInfoModel::biggerString() const
> +{
> + return biggerEntry;
> +}
> +
> bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent)
> {
> beginInsertRows(parent, rowCount(), rowCount());
> @@ -646,6 +671,10 @@ QVariant TankInfoModel::data(const QModelIndex& index,
> int role) const
> if (!index.isValid()) {
> return ret;
> }
> + if (role == Qt::FontRole){
> + return defaultModelFont();
> + }
> +
> struct tank_info *info = &tank_info[index.row()];
>
> int ml = info->ml;
> @@ -680,8 +709,12 @@ QVariant TankInfoModel::headerData(int section,
> Qt::Orientation orientation, int
> if (orientation != Qt::Horizontal)
> return ret;
>
> - if (role == Qt::DisplayRole) {
> - switch(section) {
> + switch(role){
> + case Qt::FontRole:
> + ret = defaultModelFont();
> + break;
> + case Qt::DisplayRole:
> + switch(section) {
> case BAR:
> ret = tr("Bar");
> break;
> @@ -691,7 +724,8 @@ QVariant TankInfoModel::headerData(int section,
> Qt::Orientation orientation, int
> case DESCRIPTION:
> ret = tr("Description");
> break;
> - }
> + }
> + break;
> }
> return ret;
> }
> @@ -704,7 +738,13 @@ int TankInfoModel::rowCount(const QModelIndex& parent)
> const
> TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
> {
> struct tank_info *info = tank_info;
> - for (info = tank_info; info->name; info++, rows++);
> + for (info = tank_info; info->name; info++, rows++){
> + QString infoName(info->name);
> + if (infoName.count() > biggerEntry.count()){
> + biggerEntry = infoName;
> + }
> + }
> +
> if (rows > -1) {
> beginInsertRows(QModelIndex(), 0, rows);
> endInsertRows();
> @@ -752,21 +792,25 @@ int TreeItemDT::row() const
> QVariant TreeItemDT::data(int column, int role) const
> {
> QVariant ret;
> - switch (column) {
> - case NR: ret = tr("#"); break;
> - case DATE: ret = tr("Date"); break;
> - case RATING: ret = UTF8_BLACKSTAR; break;
> - case DEPTH: ret = (get_units()->length == units::METERS) ?
> tr("m") : tr("ft"); break;
> - case DURATION: ret = tr("min"); break;
> - case TEMPERATURE: ret =
> QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature ==
> units::CELSIUS) ? "C" : "F"); break;
> - case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ?
> tr("kg") : tr("lbs"); break;
> - case SUIT: ret = tr("Suit"); break;
> - case CYLINDER: ret = tr("Cyl"); break;
> - case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2);
> break;
> - case SAC: ret = tr("SAC"); break;
> - case OTU: ret = tr("OTU"); break;
> - case MAXCNS: ret = tr("maxCNS"); break;
> - case LOCATION: ret = tr("Location"); break;
> + switch(role){
> + case Qt::DisplayRole :
> + switch (column) {
> + case NR: ret = tr("#"); break;
> + case DATE: ret = tr("Date"); break;
> + case RATING: ret = UTF8_BLACKSTAR; break;
> + case DEPTH: ret = (get_units()->length ==
> units::METERS) ? tr("m") : tr("ft"); break;
> + case DURATION: ret = tr("min"); break;
> + case TEMPERATURE: ret =
> QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature ==
> units::CELSIUS) ? "C" : "F"); break;
> + case TOTALWEIGHT: ret = (get_units()->weight ==
> units::KG) ? tr("kg") : tr("lbs"); break;
> + case SUIT: ret = tr("Suit"); break;
> + case CYLINDER: ret = tr("Cyl"); break;
> + case NITROX: ret =
> QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
> + case SAC: ret = tr("SAC"); break;
> + case OTU: ret = tr("OTU"); break;
> + case MAXCNS: ret = tr("maxCNS"); break;
> + case LOCATION: ret = tr("Location"); break;
> + }
> + break;
> }
> return ret;
> }
> @@ -981,9 +1025,7 @@ QVariant DiveTripModel::data(const QModelIndex& index,
> int role) const
> return QVariant();
>
> if (role == Qt::FontRole) {
> - QFont font;
> - font.setPointSizeF(font.pointSizeF() * 0.7);
> - return font;
> + return defaultModelFont();
> }
> TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
>
> @@ -1004,6 +1046,11 @@ QVariant DiveTripModel::headerData(int section,
> Qt::Orientation orientation,
> if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
> return rootItem->data(section, role);
>
> + switch(role){
> + case Qt::FontRole :
> + return defaultModelFont();
> + }
> +
> return QVariant();
> }
>
> diff --git a/qt-ui/models.h b/qt-ui/models.h
> index a012ec6..79af13b 100644
> --- a/qt-ui/models.h
> +++ b/qt-ui/models.h
> @@ -14,6 +14,8 @@
> #include "../dive.h"
> #include "../divelist.h"
>
> +QFont defaultModelFont();
> +
> /* Encapsulates the tank_info global variable
> * to show on Qt's Model View System.*/
> class TankInfoModel : public QAbstractTableModel {
> @@ -30,10 +32,12 @@ public:
> /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex())
> const;
> /*reimp*/ bool insertRows(int row, int count, const QModelIndex&
> parent = QModelIndex());
> /*reimp*/ bool setData(const QModelIndex& index, const QVariant&
> value, int role = Qt::EditRole);
> + const QString& biggerString() const;
> void clear();
> void update();
> private:
> int rows;
> + QString biggerEntry;
> };
>
> /* Encapsulate ws_info */
> @@ -51,11 +55,12 @@ public:
> /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex())
> const;
> /*reimp*/ bool insertRows(int row, int count, const QModelIndex&
> parent = QModelIndex());
> /*reimp*/ bool setData(const QModelIndex& index, const QVariant&
> value, int role = Qt::EditRole);
> + const QString& biggerString() const;
> void clear();
> void update();
> private:
> int rows;
> -
> + QString biggerEntry;
> };
>
> /* Encapsulation of the Cylinder Model, that presents the
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
More information about the subsurface
mailing list