From c917b29701470398b51aa5ad9541275825d912fd Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 16 Jun 2013 14:36:23 -0300 Subject: Save / Restore the sizes of the columns in Cylinders / Weigth widgets This patch saves / restores the sizes of the columns in the cylinders and weigth table widgets, so everything is now properly behaved. There 's still other things to do - but I'm tired. i's sunday and there's a protest against the brazilian government to go. Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- qt-ui/maintab.h | 4 ++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index bee94fb4b..c6b49da39 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -16,6 +16,7 @@ #include #include #include +#include MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui(new Ui::MainTab()), @@ -82,17 +83,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), QFontMetrics metrics(defaultModelFont()); QFontMetrics metrics2(font()); - ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24); - ui->cylinders->setColumnWidth(CylindersModel::TYPE, metrics2.width(TankInfoModel::instance()->biggerString()) + 20); 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->setColumnWidth(WeightModel::TYPE, metrics2.width(WSInfoModel::instance()->biggerString()) + 20); 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. @@ -481,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 b92db67e1..124bcff7e 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(); -- cgit v1.2.3-70-g09d2