mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Adds the code to make the dive list behave like tree or list
This code adds the possibility to make the DiveList behave like a Tree or a List, depending on what layout is set. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
8394828806
commit
c6f84de37c
3 changed files with 35 additions and 3 deletions
|
@ -22,6 +22,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
|||
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
|
||||
QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
|
||||
setModel(model);
|
||||
setSortingEnabled(false);
|
||||
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
}
|
||||
|
||||
|
@ -31,7 +32,10 @@ void DiveListView::reload()
|
|||
QAbstractItemModel *oldModel = m->sourceModel();
|
||||
if (oldModel)
|
||||
oldModel->deleteLater();
|
||||
m->setSourceModel(new DiveTripModel(this));
|
||||
DiveTripModel *tripModel = new DiveTripModel(this);
|
||||
tripModel->setLayout(DiveTripModel::LIST);
|
||||
|
||||
m->setSourceModel(tripModel);
|
||||
sortByColumn(0, Qt::DescendingOrder);
|
||||
QModelIndex firstDiveOrTrip = m->index(0,0);
|
||||
if (firstDiveOrTrip.isValid()) {
|
||||
|
|
|
@ -1003,7 +1003,6 @@ DiveTripModel::DiveTripModel(QObject* parent) :
|
|||
QAbstractItemModel(parent)
|
||||
{
|
||||
rootItem = new TreeItemDT();
|
||||
setupModelData();
|
||||
}
|
||||
|
||||
DiveTripModel::~DiveTripModel()
|
||||
|
@ -1096,6 +1095,11 @@ void DiveTripModel::setupModelData()
|
|||
{
|
||||
int i = dive_table.nr;
|
||||
|
||||
if (rowCount()){
|
||||
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
while (--i >= 0) {
|
||||
struct dive* dive = get_dive(i);
|
||||
update_cylinder_related_info(dive);
|
||||
|
@ -1104,11 +1108,14 @@ void DiveTripModel::setupModelData()
|
|||
DiveItem* diveItem = new DiveItem();
|
||||
diveItem->dive = dive;
|
||||
|
||||
if (!trip) {
|
||||
if (!trip || currentLayout == LIST) {
|
||||
diveItem->parent = rootItem;
|
||||
rootItem->children.push_back(diveItem);
|
||||
continue;
|
||||
}
|
||||
if (currentLayout == LIST)
|
||||
continue;
|
||||
|
||||
if (!trips.keys().contains(trip)) {
|
||||
TripItem* tripItem = new TripItem();
|
||||
tripItem->trip = trip;
|
||||
|
@ -1121,4 +1128,20 @@ void DiveTripModel::setupModelData()
|
|||
TripItem* tripItem = trips[trip];
|
||||
tripItem->children.push_back(diveItem);
|
||||
}
|
||||
|
||||
if (rowCount()){
|
||||
beginInsertRows(QModelIndex(), 0, rowCount()-1);
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
DiveTripModel::Layout DiveTripModel::layout() const
|
||||
{
|
||||
return currentLayout;
|
||||
}
|
||||
|
||||
void DiveTripModel::setLayout(DiveTripModel::Layout layout)
|
||||
{
|
||||
currentLayout = layout;
|
||||
setupModelData();
|
||||
}
|
||||
|
|
|
@ -144,6 +144,8 @@ class DiveTripModel : public QAbstractItemModel
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Layout{TREE, LIST};
|
||||
|
||||
DiveTripModel(QObject *parent = 0);
|
||||
~DiveTripModel();
|
||||
|
||||
|
@ -155,11 +157,14 @@ public:
|
|||
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
/*reimp*/ QModelIndex parent(const QModelIndex &child) const;
|
||||
|
||||
Layout layout() const;
|
||||
void setLayout(Layout layout);
|
||||
private:
|
||||
void setupModelData();
|
||||
|
||||
TreeItemDT *rootItem;
|
||||
QMap<dive_trip_t*, TripItem*> trips;
|
||||
Layout currentLayout;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue