mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue