From 61ac0a7c8d45c0d96e75d5e55ad48c6def5f4257 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 18 Nov 2013 22:33:01 -0200 Subject: Make it posible to renumber dives. If the user doubleclicks on the number of the dive in the dive list, this will present to him a dialog to change that number. Pressing enter will renumber the dive if there's no dive with the same number already. Fixes #288 Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/models.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'qt-ui/models.cpp') diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 2e4a0860e..63a5fda4f 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -810,6 +810,11 @@ TreeItem::~TreeItem() qDeleteAll(children); } +Qt::ItemFlags TreeItem::flags(const QModelIndex& index) const +{ + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + int TreeItem::row() const { if (parent) @@ -846,6 +851,10 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const return val; } +bool TreeItem::setData(const QModelIndex& index, const QVariant& value, int role) +{ +} + QModelIndex TreeModel::index(int row, int column, const QModelIndex& parent) const { @@ -995,6 +1004,34 @@ QVariant DiveItem::data(int column, int role) const return retVal; } +Qt::ItemFlags DiveItem::flags(const QModelIndex& index) const +{ + if(index.column() == NR){ + return TreeItem::flags(index) | Qt::ItemIsEditable; + } + return TreeItem::flags(index); +} + +bool DiveItem::setData(const QModelIndex& index, const QVariant& value, int role) +{ + if (role != Qt::EditRole) + return false; + if (index.column() != NR) + return false; + + int v = value.toInt(); + int i; + struct dive *d; + for_each_dive(i, d){ + if (d->number == v) + return false; + } + + dive->number = value.toInt(); + mark_divelist_changed(TRUE); + return true; +} + QString DiveItem::displayDate() const { return get_dive_date_string(dive->when); @@ -1075,7 +1112,8 @@ Qt::ItemFlags DiveTripModel::flags(const QModelIndex& index) const if (!index.isValid()) return 0; - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + TripItem *item = static_cast(index.internalPointer()); + return item->flags(index); } QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -1167,6 +1205,15 @@ void DiveTripModel::setLayout(DiveTripModel::Layout layout) setupModelData(); } +bool DiveTripModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + TreeItem* item = static_cast(index.internalPointer()); + DiveItem *diveItem = dynamic_cast(item); + if(!diveItem) + return false; + return diveItem->setData(index, value, role);} + + /*#################################################################### * * Dive Computer Model -- cgit v1.2.3-70-g09d2