Dive sites: don't add dummy entries to LocationInformationModel

The LocationInformationModel added two dummy sites to the front
of the list (add new dive site). This was never used - desktop
uses its own model, mobile only extracts the list of dive site
names with a custom function. Remove this functionality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-09 09:07:04 +02:00 committed by Dirk Hohndel
parent 65ca3444f5
commit 50e42bffa1
3 changed files with 4 additions and 58 deletions

View file

@ -73,8 +73,6 @@ unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degree
uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime);
void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count); void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count);
#define INVALID_DIVE_SITE_NAME "development use only - not a valid dive site name"
#ifdef __cplusplus #ifdef __cplusplus
} }
QString constructLocationTags(struct dive_site *ds, bool for_maintab); QString constructLocationTags(struct dive_site *ds, bool for_maintab);

View file

@ -19,8 +19,7 @@ LocationInformationModel *LocationInformationModel::instance()
} }
LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj), LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj),
internalRowCount(0), internalRowCount(0)
textField(NULL)
{ {
} }
@ -31,19 +30,7 @@ int LocationInformationModel::columnCount(const QModelIndex&) const
int LocationInformationModel::rowCount(const QModelIndex&) const int LocationInformationModel::rowCount(const QModelIndex&) const
{ {
return internalRowCount + 2; return internalRowCount;
}
static struct dive_site *get_dive_site_name_start_which_str(const QString& str) {
struct dive_site *ds;
int i;
for_each_dive_site(i,ds) {
QString dsName(ds->name);
if (dsName.startsWith(str)) {
return ds;
}
}
return NULL;
} }
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
@ -51,39 +38,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
// Special case to handle the 'create dive site' with name. struct dive_site *ds = get_dive_site(index.row());
if (index.row() < 2) {
if (index.column() == UUID)
return RECENTLY_ADDED_DIVESITE;
switch(role) {
case Qt::DisplayRole : {
if (index.row() == 1) {
struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
if(ds)
return ds->name;
}
return textField->text();
}
case Qt::ToolTipRole : {
return QString(tr("Create dive site with this name"));
}
case Qt::EditRole : {
if (index.row() == 1) {
struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
if (!ds)
return INVALID_DIVE_SITE_NAME;
if (QString(ds->name) == textField->text())
return INVALID_DIVE_SITE_NAME;
}
return textField->text();
}
case Qt::DecorationRole : return QIcon(":list-add-icon");
}
}
// The dive sites are -2 because of the first two items.
struct dive_site *ds = get_dive_site(index.row() - 2);
if (!ds) if (!ds)
return QVariant(); return QVariant();
@ -116,11 +71,6 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
return QVariant(); return QVariant();
} }
void LocationInformationModel::setFirstRowTextField(QLineEdit *t)
{
textField = t;
}
void LocationInformationModel::update() void LocationInformationModel::update()
{ {
beginResetModel(); beginResetModel();
@ -142,7 +92,7 @@ bool LocationInformationModel::removeRows(int row, int, const QModelIndex&)
if(row >= rowCount()) if(row >= rowCount())
return false; return false;
beginRemoveRows(QModelIndex(), row + 2, row + 2); beginRemoveRows(QModelIndex(), row, row);
struct dive_site *ds = get_dive_site(row); struct dive_site *ds = get_dive_site(row);
if (ds) if (ds)
delete_dive_site(ds->uuid); delete_dive_site(ds->uuid);

View file

@ -25,7 +25,6 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
void setFirstRowTextField(QLineEdit *textField);
public slots: public slots:
void update(); void update();
@ -33,7 +32,6 @@ public slots:
private: private:
int internalRowCount; int internalRowCount;
QStringList locationNames; QStringList locationNames;
QLineEdit *textField;
}; };
class GeoReferencingOptionsModel : public QStringListModel { class GeoReferencingOptionsModel : public QStringListModel {