mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Merge branch 'bug111' of https://github.com/tcanabrava/subsurface
This commit is contained in:
commit
8df20f4149
5 changed files with 74 additions and 7 deletions
|
@ -22,16 +22,53 @@ 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);
|
||||
}
|
||||
|
||||
void DiveListView::reload()
|
||||
void DiveListView::headerClicked(int i )
|
||||
{
|
||||
QModelIndexList oldSelection = selectionModel()->selectedRows();
|
||||
QList<struct dive*> currentSelectedDives;
|
||||
Q_FOREACH(const QModelIndex& index , oldSelection){
|
||||
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
||||
if (d){
|
||||
currentSelectedDives.push_back(d);
|
||||
}
|
||||
}
|
||||
|
||||
if (i == (int) TreeItemDT::NR){
|
||||
reload(DiveTripModel::TREE);
|
||||
}else{
|
||||
reload(DiveTripModel::LIST);
|
||||
}
|
||||
|
||||
QModelIndexList newSelection;
|
||||
QItemSelection newSelection2;
|
||||
|
||||
Q_FOREACH(struct dive *d, currentSelectedDives){
|
||||
QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::DIVE_ROLE, QVariant::fromValue<void*>(d), 1, Qt::MatchRecursive);
|
||||
if (match.count() == 0){
|
||||
qDebug() << "Well, this shouldn't happen.";
|
||||
}else{
|
||||
newSelection << match.first();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiveListView::reload(DiveTripModel::Layout layout)
|
||||
{
|
||||
header()->setClickable(true);
|
||||
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
||||
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||
QAbstractItemModel *oldModel = m->sourceModel();
|
||||
if (oldModel)
|
||||
oldModel->deleteLater();
|
||||
m->setSourceModel(new DiveTripModel(this));
|
||||
DiveTripModel *tripModel = new DiveTripModel(this);
|
||||
tripModel->setLayout(layout);
|
||||
|
||||
m->setSourceModel(tripModel);
|
||||
sortByColumn(0, Qt::DescendingOrder);
|
||||
QModelIndex firstDiveOrTrip = m->index(0,0);
|
||||
if (firstDiveOrTrip.isValid()) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <QTreeView>
|
||||
#include "models.h"
|
||||
|
||||
class DiveListView : public QTreeView
|
||||
{
|
||||
|
@ -28,11 +29,12 @@ public:
|
|||
void keyPressEvent(QKeyEvent* event);
|
||||
void keyReleaseEvent(QKeyEvent*);
|
||||
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
|
||||
void reload();
|
||||
void reload(DiveTripModel::Layout layout = DiveTripModel::TREE);
|
||||
|
||||
public slots:
|
||||
void toggleColumnVisibilityByIndex();
|
||||
void reloadHeaderActions();
|
||||
void headerClicked(int);
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentDiveChanged(int divenr);
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
|
@ -103,7 +103,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>763</width>
|
||||
<height>25</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue