Create a new dive site and edit it automatically

If the user clicks on the first or second option of the drop
down list, subsurface will move him to the dive site edit panel
automatically, since it's a new dive site and there's no information
about it yet.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-08-25 21:03:20 -03:00 committed by Dirk Hohndel
parent 0ba832ef12
commit fc6d819616
4 changed files with 18 additions and 8 deletions

View file

@ -53,7 +53,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
// Special case to handle the 'create dive site' with name.
if (index.row() < 2) {
if (index.column() == UUID)
return 0;
return RECENTLY_ADDED_DIVESITE;
switch(role) {
case Qt::DisplayRole : {
if (index.row() == 1) {
@ -92,7 +92,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
case Qt::DisplayRole :
switch(index.column()) {
case UUID: return ds->uuid;
case NAME: return ds->name;
case NAME: return QString("%1, id:%2").arg(ds->name).arg(ds->uuid);
case LATITUDE: return ds->latitude.udeg;
case LONGITUDE: return ds->longitude.udeg;
case COORDS: return "TODO";

View file

@ -7,6 +7,8 @@
class QLineEdit;
#define RECENTLY_ADDED_DIVESITE 1
class LocationInformationModel : public QAbstractTableModel {
Q_OBJECT
public:

View file

@ -235,11 +235,19 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
activated.row(), LocationInformationModel::UUID);
last_uuid = uuidIdx.data().toInt();
// Special case: first two options: add dive site.
if (activated.row() < 2) {
qDebug() << "Setting to " << activated.data().toString();
emit setLineEditText(activated.data().toString());
/* if we are in 'recently added divesite mode, create a new divesite,
* and go to dive site edit edit mode. */
if (last_uuid == RECENTLY_ADDED_DIVESITE) {
uint32_t ds_uuid = create_dive_site(qPrintable(activated.data().toString()), current_dive->when);
qDebug() << "ds_uuid" << ds_uuid;
struct dive_site *ds = get_dive_site_by_uuid(ds_uuid);
copy_dive_site(ds, &displayed_dive_site);
displayed_dive.dive_site_uuid = ds->uuid;
last_uuid = ds->uuid;
// Move this out of here later.
MainWindow::instance()->startDiveSiteEdit();
}
qDebug() << "Selected dive_site: " << last_uuid;
}
@ -254,7 +262,7 @@ uint32_t LocationManagementEditHelper::diveSiteUuid() const {
void LocationInformationWidget::reverseGeocode()
{
qDebug() << "Chamou";
qDebug() << "Chamou aqui";
ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
geoLookup->lookup(&displayed_dive_site);
updateLabels();

View file

@ -868,7 +868,7 @@ void MainTab::updateDisplayedDiveSite()
if(orig_uuid) {
if (new_uuid && orig_uuid != new_uuid) {
// the user picked a different site
qDebug() << "copy the dive site we picked into the displayed dive site";
qDebug() << "copy the dive site we picked into the displayed dive site, id: " << new_uuid;
displayed_dive.dive_site_uuid = new_uuid;
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
} else if (!new_name.isEmpty() && orig_name != new_name) {