summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-06-01 16:58:23 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-01 13:24:37 -0700
commitb8092c07a4b4d7715d825641e458be5fa56972d6 (patch)
tree81d7604b2f53fe234d83a09a3645616a681e9ba1
parent82d3f088a40545624f0d1ac61ca990e05325081c (diff)
downloadsubsurface-b8092c07a4b4d7715d825641e458be5fa56972d6.tar.gz
Create a new DiveSite when user clicks on add
Also reorganized a bit of the code, and renamed a few misleading methods. [Dirk Hohndel: remove some C++11 code] Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-models/divelocationmodel.cpp11
-rw-r--r--qt-models/divelocationmodel.h2
-rw-r--r--qt-ui/locationinformation.cpp8
-rw-r--r--qt-ui/locationinformation.h4
-rw-r--r--qt-ui/maintab.cpp12
-rw-r--r--qt-ui/maintab.ui24
-rw-r--r--qt-ui/mainwindow.cpp6
7 files changed, 44 insertions, 23 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index c335f7039..3f8c486fe 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -49,3 +49,14 @@ void LocationInformationModel::update()
endInsertRows();
}
}
+
+int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int lat)
+{
+ degrees_t latitude, longitude;
+ latitude.udeg = lat;
+ longitude.udeg = lon;
+
+ int32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
+ update();
+ return uuid;
+}
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 9238c4b5b..9d30adf41 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -10,6 +10,8 @@ public:
static LocationInformationModel *instance();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
+ int32_t addDiveSite(const QString& name, int lat = 0, int lon = 0);
+
public slots:
void update();
private:
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 699b80d47..b6c4f7fa9 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -34,16 +34,16 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
connect(this, SIGNAL(stopFilterDiveSite()), MultiFilterSortModel::instance(), SLOT(stopFilterDiveSite()));
}
-void LocationInformationWidget::setCurrentDiveSite(int dive_nr)
+void LocationInformationWidget::setCurrentDiveSiteByIndex(int dive_nr)
{
currentDs = get_dive_site(dive_nr);
if (currentDs)
- setLocationId(currentDs->uuid);
+ setCurrentDiveSiteByUuid(currentDs->uuid);
else
- setLocationId(displayed_dive.dive_site_uuid);
+ setCurrentDiveSiteByUuid(displayed_dive.dive_site_uuid);
}
-void LocationInformationWidget::setLocationId(uint32_t uuid)
+void LocationInformationWidget::setCurrentDiveSiteByUuid(uint32_t uuid)
{
currentDs = get_dive_site_by_uuid(uuid);
if(!currentDs)
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 2a34512bd..0dcae9d7f 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -15,13 +15,13 @@ protected:
public slots:
void acceptChanges();
void rejectChanges();
- void setLocationId(uint32_t uuid);
+ void setCurrentDiveSiteByUuid(uint32_t uuid);
void updateGpsCoordinates(void);
void markChangedWidget(QWidget *w);
void enableEdition();
void resetState();
void resetPallete();
- void setCurrentDiveSite(int dive_nr);
+ void setCurrentDiveSiteByIndex(int dive_nr);
void on_diveSiteCoordinates_textChanged(const QString& text);
void on_diveSiteDescription_textChanged(const QString& text);
void on_diveSiteName_textChanged(const QString& text);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 2ecfb6c6d..cc09ed723 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -21,6 +21,8 @@
#include "divepicturemodel.h"
#include "divecomputerextradatamodel.h"
#include "divelocationmodel.h"
+#include "divesite.h"
+
#if defined(FBSUPPORT)
#include "socialnetworks.h"
#endif
@@ -55,7 +57,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.extraData->setModel(extraDataModel);
closeMessage();
- connect(ui.manageDiveSite, SIGNAL(clicked()), this, SLOT(prepareDiveSiteEdit()));
+ connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(prepareDiveSiteEdit()));
QAction *action = new QAction(tr("Apply changes"), this);
connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
@@ -231,17 +233,19 @@ void MainTab::setCurrentLocationIndex()
void MainTab::enableGeoLookupEdition()
{
ui.waitingSpinner->stop();
- ui.manageDiveSite->show();
+ ui.addDiveSite->show();
}
void MainTab::disableGeoLookupEdition()
{
ui.waitingSpinner->start();
- ui.manageDiveSite->hide();
+ ui.addDiveSite->hide();
}
void MainTab::prepareDiveSiteEdit() {
- emit requestDiveSiteEdit(displayed_dive.dive_site_uuid);
+ uint32_t dive_site_uuid = LocationInformationModel::instance()->addDiveSite(tr("Unnamed"));
+ displayed_dive.dive_site_uuid = dive_site_uuid;
+ emit requestDiveSiteEdit(dive_site_uuid);
}
void MainTab::toggleTriggeredColumn()
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index 07c4d9fe0..d681fbdbb 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -55,8 +55,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>447</width>
- <height>766</height>
+ <width>445</width>
+ <height>760</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -196,9 +196,13 @@
</widget>
</item>
<item>
- <widget class="QPushButton" name="manageDiveSite">
+ <widget class="QToolButton" name="addDiveSite">
<property name="text">
- <string>manage</string>
+ <string>...</string>
+ </property>
+ <property name="icon">
+ <iconset resource="../subsurface.qrc">
+ <normaloff>:/plus</normaloff>:/plus</iconset>
</property>
</widget>
</item>
@@ -535,8 +539,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>447</width>
- <height>756</height>
+ <width>445</width>
+ <height>754</height>
</rect>
</property>
<layout class="QGridLayout" name="equipmentTabScrollAreaLayout">
@@ -630,8 +634,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>447</width>
- <height>756</height>
+ <width>445</width>
+ <height>754</height>
</rect>
</property>
<layout class="QGridLayout" name="diveInfoScrollAreaLayout">
@@ -971,8 +975,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>447</width>
- <height>756</height>
+ <width>445</width>
+ <height>754</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 9fa1a81d1..3abb230c4 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -216,7 +216,7 @@ void MainWindow::on_actionManage_dive_sites_triggered() {
}
void MainWindow::enableDiveSiteEdit(uint32_t id) {
- locationInformationWidget()->setLocationId(displayed_dive.dive_site_uuid);
+ locationInformationWidget()->setCurrentDiveSiteByUuid(id);
setApplicationState("EditDiveSite");
}
@@ -404,7 +404,7 @@ void MainWindow::cleanUpEmpty()
information()->updateDiveInfo(true);
graphics()->setEmptyState();
dive_list()->reload(DiveTripModel::TREE);
- locationInformationWidget()->setLocationId(0);
+ locationInformationWidget()->setCurrentDiveSiteByUuid(0);
globe()->reload();
if (!existing_filename)
setTitle(MWTF_DEFAULT);
@@ -632,7 +632,7 @@ void MainWindow::setupForAddAndPlan(const char *model)
// setup the dive cylinders
DivePlannerPointsModel::instance()->clear();
DivePlannerPointsModel::instance()->setupCylinders();
- locationInformationWidget()->setLocationId(0);
+ locationInformationWidget()->setCurrentDiveSiteByUuid(0);
}
void MainWindow::on_actionReplanDive_triggered()