mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4433830f55
commit
61ac0a7c8d
2 changed files with 54 additions and 3 deletions
|
@ -810,6 +810,11 @@ TreeItem::~TreeItem()
|
||||||
qDeleteAll(children);
|
qDeleteAll(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags TreeItem::flags(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
}
|
||||||
|
|
||||||
int TreeItem::row() const
|
int TreeItem::row() const
|
||||||
{
|
{
|
||||||
if (parent)
|
if (parent)
|
||||||
|
@ -846,6 +851,10 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TreeItem::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex TreeModel::index(int row, int column, const QModelIndex& parent)
|
QModelIndex TreeModel::index(int row, int column, const QModelIndex& parent)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -995,6 +1004,34 @@ QVariant DiveItem::data(int column, int role) const
|
||||||
return retVal;
|
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
|
QString DiveItem::displayDate() const
|
||||||
{
|
{
|
||||||
return get_dive_date_string(dive->when);
|
return get_dive_date_string(dive->when);
|
||||||
|
@ -1075,7 +1112,8 @@ Qt::ItemFlags DiveTripModel::flags(const QModelIndex& index) const
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
TripItem *item = static_cast<TripItem*>(index.internalPointer());
|
||||||
|
return item->flags(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
@ -1167,6 +1205,15 @@ void DiveTripModel::setLayout(DiveTripModel::Layout layout)
|
||||||
setupModelData();
|
setupModelData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DiveTripModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
|
{
|
||||||
|
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
|
||||||
|
DiveItem *diveItem = dynamic_cast<DiveItem*>(item);
|
||||||
|
if(!diveItem)
|
||||||
|
return false;
|
||||||
|
return diveItem->setData(index, value, role);}
|
||||||
|
|
||||||
|
|
||||||
/*####################################################################
|
/*####################################################################
|
||||||
*
|
*
|
||||||
* Dive Computer Model
|
* Dive Computer Model
|
||||||
|
|
|
@ -144,6 +144,9 @@ public:
|
||||||
virtual ~TreeItem();
|
virtual ~TreeItem();
|
||||||
TreeItem();
|
TreeItem();
|
||||||
virtual QVariant data (int column, int role) const;
|
virtual QVariant data (int column, int role) const;
|
||||||
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
int row() const;
|
int row() const;
|
||||||
QList<TreeItem*> children;
|
QList<TreeItem*> children;
|
||||||
TreeItem *parent;
|
TreeItem *parent;
|
||||||
|
@ -155,7 +158,8 @@ struct DiveItem : public TreeItem {
|
||||||
|
|
||||||
virtual QVariant data(int column, int role) const;
|
virtual QVariant data(int column, int role) const;
|
||||||
struct dive* dive;
|
struct dive* dive;
|
||||||
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||||
QString displayDate() const;
|
QString displayDate() const;
|
||||||
QString displayDuration() const;
|
QString displayDuration() const;
|
||||||
QString displayDepth() const;
|
QString displayDepth() const;
|
||||||
|
@ -174,7 +178,6 @@ class TreeModel : public QAbstractItemModel
|
||||||
public:
|
public:
|
||||||
TreeModel(QObject *parent = 0);
|
TreeModel(QObject *parent = 0);
|
||||||
virtual ~TreeModel();
|
virtual ~TreeModel();
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||||
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
@ -197,6 +200,7 @@ public:
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
DiveTripModel(QObject* parent = 0);
|
DiveTripModel(QObject* parent = 0);
|
||||||
Layout layout() const;
|
Layout layout() const;
|
||||||
void setLayout(Layout layout);
|
void setLayout(Layout layout);
|
||||||
|
|
Loading…
Add table
Reference in a new issue