From 778d6ea103b0e7f9d60bc125a66e5fc95cc2805e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 26 Aug 2014 17:52:05 -0700 Subject: TableWidgets: change default column width and don't save unchanged widths Similar change to the dive list. The idea is to not save things that are the default. This way Subsurface will do the right thing when defaults change. Signed-off-by: Dirk Hohndel --- qt-ui/tableview.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'qt-ui/tableview.cpp') diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp index cbbea264e..a56ab47f2 100644 --- a/qt-ui/tableview.cpp +++ b/qt-ui/tableview.cpp @@ -29,8 +29,22 @@ TableView::~TableView() { QSettings s; s.beginGroup(objectName()); - for (int i = 0; i < ui.tableView->model()->columnCount(); i++) { - s.setValue(QString("colwidth%1").arg(i), ui.tableView->columnWidth(i)); + // remove the old default + bool oldDefault = (ui.tableView->columnWidth(0) == 30); + for (int i = 1; oldDefault && i < ui.tableView->model()->columnCount(); i++) { + if (ui.tableView->columnWidth(i) != 80) + oldDefault = false; + } + if (oldDefault) { + s.remove(""); + } else { + for (int i = 0; i < ui.tableView->model()->columnCount(); i++) { + if ((i == CylindersModel::REMOVE && ui.tableView->columnWidth(i) == 30) || + ui.tableView->columnWidth(i) == 70) + s.remove(QString("colwidth%1").arg(i)); + else + s.setValue(QString("colwidth%1").arg(i), ui.tableView->columnWidth(i)); + } } s.endGroup(); } @@ -54,7 +68,7 @@ void TableView::setModel(QAbstractItemModel *model) s.beginGroup(objectName()); const int columnCount = ui.tableView->model()->columnCount(); for (int i = 0; i < columnCount; i++) { - QVariant width = s.value(QString("colwidth%1").arg(i), i == CylindersModel::REMOVE ? 30 : 80); + QVariant width = s.value(QString("colwidth%1").arg(i), i == CylindersModel::REMOVE ? 30 : 70); ui.tableView->setColumnWidth(i, width.toInt()); } s.endGroup(); -- cgit v1.2.3-70-g09d2