Dive list view: move column width logic back from DiveTripModel

Conceptually, the width of the columns should probably reside in
the view not the model. But much more severly, the old code didn't
work: Columns were set in a DiveTripModel, which was deleted
right away.

Therefore, move the logic back to the DiveListView. Introduce
a QVector<int> of the initial column widths, so that they can be
erased from the setting if unchanged.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-25 20:40:47 +02:00 committed by Dirk Hohndel
parent d3dc698bba
commit 079b99135a
4 changed files with 53 additions and 92 deletions

View file

@ -442,18 +442,6 @@ DiveTripModel::DiveTripModel(QObject *parent) :
currentLayout(TREE)
{
columns = COLUMNS;
// setup the default width of columns (px)
columnWidthMap = QVector<int>(COLUMNS);
// pre-fill with 50px; the rest are explicit
for(int i = 0; i < COLUMNS; i++)
columnWidthMap[i] = 50;
columnWidthMap[NR] = 70;
columnWidthMap[DATE] = 140;
columnWidthMap[RATING] = 90;
columnWidthMap[SUIT] = 70;
columnWidthMap[SAC] = 70;
columnWidthMap[PHOTOS] = 5;
columnWidthMap[LOCATION] = 500;
}
Qt::ItemFlags DiveTripModel::flags(const QModelIndex &index) const
@ -658,21 +646,3 @@ bool DiveTripModel::setData(const QModelIndex &index, const QVariant &value, int
return false;
return diveItem->setData(index, value, role);
}
int DiveTripModel::columnWidth(int column)
{
if (column > COLUMNS - 1 || column < 0) {
qWarning() << "DiveTripModel::columnWidth(): not a valid column index -" << column;
return 50;
}
return columnWidthMap[column];
}
void DiveTripModel::setColumnWidth(int column, int width)
{
if (column > COLUMNS - 1 || column < 0) {
qWarning() << "DiveTripModel::setColumnWidth(): not a valid column index -" << column;
return;
}
columnWidthMap[column] = width;
}