Implements the DiveList to behave like Linus Explained.

Implements the divelist to behave like linus explained,
essentially, it filters the layoutChanges of the model,
greps for trips, and for each trip that it finds, it set
the 'firstColumnSpanned' property, to make the column
to have the size of the whole table. e

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-12 14:14:25 -03:00
parent bd8470ebcf
commit ab0213f28e
3 changed files with 16 additions and 6 deletions

View file

@ -28,6 +28,8 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
model->setSortRole(TreeItemDT::SORT_ROLE);
model->setFilterKeyColumn(-1); // filter all columns
setModel(model);
connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
setSortingEnabled(false);
setContextMenuPolicy(Qt::DefaultContextMenu);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
@ -42,6 +44,16 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
}
void DiveListView::fixMessyQtModelBehaviour()
{
QAbstractItemModel *m = model();
for(int i = 0; i < model()->rowCount(); i++){
if (m->rowCount( m->index(i, 0) ) != 0){
setFirstColumnSpanned(i, QModelIndex(), true);
}
}
}
void DiveListView::unselectDives()
{
selectionModel()->clearSelection();

View file

@ -38,7 +38,8 @@ public slots:
void removeFromTrip();
void deleteDive();
void testSlot();
void fixMessyQtModelBehaviour();
Q_SIGNALS:
void currentDiveChanged(int divenr);

View file

@ -785,11 +785,8 @@ QVariant TripItem::data(int column, int role) const
if (role == Qt::DisplayRole) {
switch (column) {
case LOCATION:
ret = QString(trip->location);
break;
case DATE:
ret = QString(get_trip_date_string(trip->when, trip->nrdives));
case NR:
ret = QString(trip->location) + QString(get_trip_date_string(trip->when, trip->nrdives));
break;
}
}