2015-05-30 00:19:44 +00:00
|
|
|
#include "divelocationmodel.h"
|
|
|
|
#include "dive.h"
|
2015-06-02 01:30:33 +00:00
|
|
|
#include <QDebug>
|
2015-05-30 00:19:44 +00:00
|
|
|
|
2015-06-02 00:00:09 +00:00
|
|
|
bool dive_site_less_than(dive_site *a, dive_site *b)
|
2015-05-31 20:56:53 +00:00
|
|
|
{
|
|
|
|
return QString(a->name) <= QString(b->name);
|
|
|
|
}
|
|
|
|
|
2015-05-30 01:22:24 +00:00
|
|
|
LocationInformationModel *LocationInformationModel::instance()
|
|
|
|
{
|
|
|
|
static LocationInformationModel *self = new LocationInformationModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-07-01 21:46:27 +00:00
|
|
|
LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj), internalRowCount(0)
|
2015-05-30 00:19:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-01 21:46:27 +00:00
|
|
|
int LocationInformationModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return COLUMNS;
|
|
|
|
}
|
|
|
|
|
2015-05-30 00:19:44 +00:00
|
|
|
int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return internalRowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
struct dive_site *ds = get_dive_site(index.row());
|
|
|
|
|
2015-06-02 13:35:06 +00:00
|
|
|
if (!ds)
|
|
|
|
return QVariant();
|
|
|
|
|
2015-05-30 00:19:44 +00:00
|
|
|
switch(role) {
|
2015-07-01 21:46:27 +00:00
|
|
|
case Qt::DisplayRole :
|
|
|
|
switch(index.column()) {
|
|
|
|
case UUID: return ds->uuid;
|
|
|
|
case NAME: return ds->name;
|
|
|
|
case LATITUDE: return ds->latitude.udeg;
|
|
|
|
case LONGITUDE: return ds->longitude.udeg;
|
|
|
|
case COORDS: return "TODO";
|
|
|
|
case DESCRIPTION: return ds->description;
|
|
|
|
case NOTES: return ds->name;
|
|
|
|
case TAXONOMY_1: return "TODO";
|
|
|
|
case TAXONOMY_2: return "TODO";
|
|
|
|
case TAXONOMY_3: return "TODO";
|
|
|
|
}
|
|
|
|
break;
|
2015-05-30 00:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationInformationModel::update()
|
|
|
|
{
|
2015-06-02 02:13:51 +00:00
|
|
|
beginResetModel();
|
|
|
|
internalRowCount = dive_site_table.nr;
|
2015-06-04 15:45:45 +00:00
|
|
|
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
2015-06-02 02:13:51 +00:00
|
|
|
endResetModel();
|
2015-05-30 00:19:44 +00:00
|
|
|
}
|
2015-06-01 19:58:23 +00:00
|
|
|
|
|
|
|
int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int lat)
|
|
|
|
{
|
|
|
|
degrees_t latitude, longitude;
|
|
|
|
latitude.udeg = lat;
|
|
|
|
longitude.udeg = lon;
|
|
|
|
|
2015-06-04 03:05:05 +00:00
|
|
|
beginInsertRows(QModelIndex(), dive_site_table.nr, dive_site_table.nr);
|
2015-06-04 15:45:45 +00:00
|
|
|
uint32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
|
|
|
|
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
2015-06-04 03:05:05 +00:00
|
|
|
internalRowCount = dive_site_table.nr;
|
|
|
|
endInsertRows();
|
2015-06-01 19:58:23 +00:00
|
|
|
return uuid;
|
|
|
|
}
|
2015-06-02 01:16:07 +00:00
|
|
|
|
|
|
|
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
struct dive_site *ds = get_dive_site(index.row());
|
|
|
|
free(ds->name);
|
|
|
|
ds->name = copy_string(qPrintable(value.toString()));
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-02 02:13:51 +00:00
|
|
|
|
2015-06-22 20:24:15 +00:00
|
|
|
bool LocationInformationModel::removeRows(int row, int count, const QModelIndex & parent)
|
|
|
|
{
|
2015-06-02 02:13:51 +00:00
|
|
|
if(row >= rowCount())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
struct dive_site *ds = get_dive_site(row);
|
2015-06-02 13:35:06 +00:00
|
|
|
if (ds)
|
|
|
|
delete_dive_site(ds->uuid);
|
2015-06-04 03:13:09 +00:00
|
|
|
internalRowCount = dive_site_table.nr;
|
2015-06-02 02:13:51 +00:00
|
|
|
endRemoveRows();
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-22 20:24:15 +00:00
|
|
|
|
|
|
|
GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance() {
|
|
|
|
static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeoReferencingOptionsModel::GeoReferencingOptionsModel(QObject *parent) : QStringListModel(parent)
|
|
|
|
{
|
|
|
|
QStringList list;
|
2015-07-01 19:32:46 +00:00
|
|
|
int i;
|
2015-07-02 17:21:35 +00:00
|
|
|
for (i = 0; i < TC_NR_CATEGORIES; i++)
|
2015-07-01 19:32:46 +00:00
|
|
|
list << taxonomy_category_names[i];
|
2015-06-22 20:24:15 +00:00
|
|
|
setStringList(list);
|
|
|
|
}
|