mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive list view: setup columns in constructor
The column-widths must only be set once the source-model is that. The old code realized this with a rather complicated logic. Instead, simply set the source-model in the constructor and set the column widths after that. Rename the corresponding function from "setupUi" to "setColumnWidths". Moreover, the setupUi function had different code-paths for the first and other calls. Since it is only called once, remove the other code paths. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
079b99135a
commit
67a875ef81
2 changed files with 7 additions and 20 deletions
|
@ -36,6 +36,8 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
||||||
model->setSortRole(DiveTripModel::SORT_ROLE);
|
model->setSortRole(DiveTripModel::SORT_ROLE);
|
||||||
model->setFilterKeyColumn(-1); // filter all columns
|
model->setFilterKeyColumn(-1); // filter all columns
|
||||||
model->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
model->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
DiveTripModel *tripModel = new DiveTripModel(this);
|
||||||
|
model->setSourceModel(tripModel);
|
||||||
setModel(model);
|
setModel(model);
|
||||||
connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
|
connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
|
||||||
|
|
||||||
|
@ -48,11 +50,9 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
||||||
|
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
|
|
||||||
// TODO: We use a dummy DiveTripModel to calculated column widths.
|
|
||||||
// Change this to a global object.
|
|
||||||
DiveTripModel tripModel;
|
|
||||||
for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++)
|
for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++)
|
||||||
calculateInitialColumnWidth(tripModel, i);
|
calculateInitialColumnWidth(tripModel, i);
|
||||||
|
setColumnWidths();
|
||||||
}
|
}
|
||||||
|
|
||||||
DiveListView::~DiveListView()
|
DiveListView::~DiveListView()
|
||||||
|
@ -112,11 +112,9 @@ void DiveListView::calculateInitialColumnWidth(const DiveTripModel &tripModel, i
|
||||||
initialColumnWidths[col] = std::max(initialColumnWidths[col], width);
|
initialColumnWidths[col] = std::max(initialColumnWidths[col], width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::setupUi()
|
void DiveListView::setColumnWidths()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
static bool firstRun = true;
|
|
||||||
if (firstRun)
|
|
||||||
backupExpandedRows();
|
backupExpandedRows();
|
||||||
settings.beginGroup("ListWidget");
|
settings.beginGroup("ListWidget");
|
||||||
/* if no width are set, use the calculated width for each column;
|
/* if no width are set, use the calculated width for each column;
|
||||||
|
@ -132,11 +130,7 @@ void DiveListView::setupUi()
|
||||||
setColumnWidth(i, initialColumnWidths[i]);
|
setColumnWidth(i, initialColumnWidths[i]);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
if (firstRun)
|
|
||||||
restoreExpandedRows();
|
restoreExpandedRows();
|
||||||
else
|
|
||||||
collapseAll();
|
|
||||||
firstRun = false;
|
|
||||||
setColumnWidth(lastVisibleColumn(), 10);
|
setColumnWidth(lastVisibleColumn(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,13 +393,6 @@ void DiveListView::headerClicked(int i)
|
||||||
|
|
||||||
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
{
|
{
|
||||||
// we want to run setupUi() once we actually are displaying something
|
|
||||||
// in the widget
|
|
||||||
static bool first = true;
|
|
||||||
if (first && dive_table.nr > 0) {
|
|
||||||
setupUi();
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
if (layout == DiveTripModel::CURRENT)
|
if (layout == DiveTripModel::CURRENT)
|
||||||
layout = currentLayout;
|
layout = currentLayout;
|
||||||
else
|
else
|
||||||
|
|
|
@ -77,7 +77,7 @@ private:
|
||||||
/* if dive_trip_t is null, there's no problem. */
|
/* if dive_trip_t is null, there's no problem. */
|
||||||
QMultiHash<dive_trip_t *, int> selectedDives;
|
QMultiHash<dive_trip_t *, int> selectedDives;
|
||||||
void merge_trip(const QModelIndex &a, const int offset);
|
void merge_trip(const QModelIndex &a, const int offset);
|
||||||
void setupUi();
|
void setColumnWidths();
|
||||||
void calculateInitialColumnWidth(const DiveTripModel &tripModel, int col);
|
void calculateInitialColumnWidth(const DiveTripModel &tripModel, int col);
|
||||||
void backupExpandedRows();
|
void backupExpandedRows();
|
||||||
void restoreExpandedRows();
|
void restoreExpandedRows();
|
||||||
|
|
Loading…
Add table
Reference in a new issue