summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/locationinformation.cpp133
-rw-r--r--qt-ui/locationinformation.h40
-rw-r--r--qt-ui/maintab.cpp1
-rw-r--r--qt-ui/maintab.ui7
4 files changed, 180 insertions, 1 deletions
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index bf8300426..3a213e679 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -317,3 +317,136 @@ void LocationInformationWidget::reverseGeocode()
geoLookup->lookup(&displayed_dive_site);
updateLabels();
}
+
+DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *parent)
+{
+
+}
+
+DiveLocationLineEdit *location_line_edit = 0;
+
+bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
+{
+ if(source_row == 0 || source_row == 1)
+ return true;
+
+ QString sourceString = sourceModel()->index(source_row, DiveLocationModel::NAME).data(Qt::DisplayRole).toString();
+ return sourceString.toLower().startsWith(location_line_edit->text().toLower());
+}
+
+DiveLocationModel::DiveLocationModel(QObject *o)
+{
+ resetModel();
+}
+
+void DiveLocationModel::resetModel()
+{
+ beginResetModel();
+ qDebug() << "Dive site table size" <<dive_site_table.nr;
+ endResetModel();
+}
+
+QVariant DiveLocationModel::data(const QModelIndex& index, int role) const
+{
+ if(index.row() <= 1) { // two special cases.
+ switch(role) {
+ case Qt::DisplayRole : return new_ds_value[index.row()];
+ case Qt::ToolTipRole : return "Create a new dive site";
+ }
+ }
+
+ // The dive sites are -2 because of the first two items.
+ struct dive_site *ds = get_dive_site(index.row() - 2);
+ switch(role) {
+ case Qt::EditRole:
+ 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 DESCRIPTION: return ds->description;
+ case NOTES: return ds->name;
+ }
+ break;
+ case Qt::DecorationRole : {
+ if (dive_site_has_gps_location(ds))
+ return QIcon(":geocode");
+ }
+ }
+ return QVariant();
+}
+
+int DiveLocationModel::columnCount(const QModelIndex& parent) const
+{
+ return COLUMNS;
+}
+
+int DiveLocationModel::rowCount(const QModelIndex& parent) const
+{
+ return dive_site_table.nr + 2;
+}
+
+
+bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+ if(!index.isValid())
+ return false;
+ if (index.row() > 1)
+ return false;
+
+ new_ds_value[index.row()] = value.toString();
+
+ dataChanged(index, index);
+ return true;
+}
+
+DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent)
+{
+ proxy = new DiveLocationFilterProxyModel();
+ model = new DiveLocationModel();
+ view = new DiveLocationListView();
+
+ proxy->setSourceModel(model);
+ view->setModel(model);
+
+ connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
+
+ //HACK:
+ /* This is being show currently just to test. */
+ qDebug() << "AAAAAAH";
+ qDebug() << model->rowCount() << model->columnCount();
+ view->show();
+}
+
+void DiveLocationLineEdit::refreshDiveSiteCache()
+{
+ model->resetModel();
+}
+
+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;
+}
+
+void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
+{
+ QModelIndex i0 = model->index(0, DiveLocationModel::NAME);
+ model->setData(i0, text());
+
+ struct dive_site *ds = get_dive_site_name_start_which_str(text());
+ QModelIndex i1 = model->index(1, DiveLocationModel::NAME);
+ model->setData(i1, ds ? ds->name : INVALID_DIVE_SITE_NAME);
+}
+
+DiveLocationListView::DiveLocationListView(QWidget *parent)
+{
+
+}
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 080e013a8..18c3dc760 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -4,6 +4,7 @@
#include "ui_locationInformation.h"
#include <stdint.h>
#include <QAbstractListModel>
+#include <QSortFilterProxyModel>
class LocationInformationWidget : public QGroupBox {
Q_OBJECT
@@ -58,4 +59,43 @@ private:
uint32_t last_uuid;
};
+class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
+ Q_OBJECT
+public:
+ DiveLocationFilterProxyModel(QObject *parent = 0);
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
+};
+
+class DiveLocationModel : public QAbstractTableModel {
+ Q_OBJECT
+public:
+ enum columns{UUID, NAME, LATITUDE, LONGITUDE, DESCRIPTION, NOTES, COLUMNS};
+ DiveLocationModel(QObject *o = 0);
+ void resetModel();
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+private:
+ QString new_ds_value[2];
+};
+
+class DiveLocationListView : public QListView {
+ Q_OBJECT
+public:
+ DiveLocationListView(QWidget *parent = 0);
+};
+
+class DiveLocationLineEdit : public QLineEdit {
+ Q_OBJECT
+public:
+ DiveLocationLineEdit(QWidget *parent =0 );
+ void refreshDiveSiteCache();
+ void setTemporaryDiveSiteName(const QString& s);
+private:
+ DiveLocationFilterProxyModel *proxy;
+ DiveLocationModel *model;
+ DiveLocationListView *view;
+};
+
#endif
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 2e4d3fc9f..2499906c9 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -480,6 +480,7 @@ void MainTab::updateDiveInfo(bool clear)
#endif
}
+ ui.location->refreshDiveSiteCache();
EditMode rememberEM = editMode;
// don't execute this while adding / planning a dive
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics()->isPlanner())
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index 23bacbf85..28c96454e 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -188,7 +188,7 @@
<number>2</number>
</property>
<item>
- <widget class="QLineEdit" name="location"/>
+ <widget class="DiveLocationLineEdit" name="location"/>
</item>
<item>
<widget class="QToolButton" name="editDiveSiteButton">
@@ -1131,6 +1131,11 @@
<header>qtwaitingspinner.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>DiveLocationLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>locationinformation.h</header>
+ </customwidget>
</customwidgets>
<tabstops>
<tabstop>dateEdit</tabstop>