Update the dive location when showing the dialog

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-05-17 17:14:23 -03:00 committed by Dirk Hohndel
parent 0c33d585ea
commit 10a0a252c8
2 changed files with 21 additions and 9 deletions

View file

@ -7,7 +7,7 @@
#include <QDebug> #include <QDebug>
#include <QShowEvent> #include <QShowEvent>
LocationInformationModel::LocationInformationModel(QObject *obj) LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractListModel(obj), internalRowCount(0)
{ {
} }
@ -37,13 +37,13 @@ void LocationInformationModel::update()
for_each_dive_site (i, ds); for_each_dive_site (i, ds);
if (rowCount()) { if (rowCount()) {
beginRemoveRows(QModelIndex(), 0, rowCount()); beginRemoveRows(QModelIndex(), 0, rowCount()-1);
endRemoveRows(); endRemoveRows();
} }
if (i) { if (i) {
beginInsertRows(QModelIndex(), 0, i); beginInsertRows(QModelIndex(), 0, i);
internalRowCount = i; internalRowCount = i;
endRemoveRows(); endInsertRows();
} }
} }
@ -66,6 +66,14 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
ui.diveSiteMessage->setText(tr("Dive site management")); ui.diveSiteMessage->setText(tr("Dive site management"));
ui.diveSiteMessage->addAction(closeAction); ui.diveSiteMessage->addAction(closeAction);
ui.currentLocation->setModel(new LocationInformationModel());
connect(ui.currentLocation, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentDiveSite(int)));
}
void LocationInformationWidget::setCurrentDiveSite(int dive_nr)
{
currentDs = get_dive_site(dive_nr);
setLocationId(currentDs->uuid);
} }
void LocationInformationWidget::setLocationId(uint32_t uuid) void LocationInformationWidget::setLocationId(uint32_t uuid)
@ -151,8 +159,13 @@ void LocationInformationWidget::rejectChanges()
emit informationManagementEnded(); emit informationManagementEnded();
} }
void LocationInformationWidget::showEvent(QShowEvent *ev) { void LocationInformationWidget::showEvent(QShowEvent *ev)
{
LocationInformationModel *m = (LocationInformationModel*) ui.currentLocation->model();
ui.diveSiteMessage->setCloseButtonVisible(false); ui.diveSiteMessage->setCloseButtonVisible(false);
m->update();
QGroupBox::showEvent(ev);
} }
void LocationInformationWidget::markChangedWidget(QWidget *w) void LocationInformationWidget::markChangedWidget(QWidget *w)

View file

@ -20,20 +20,19 @@ class LocationInformationWidget : public QGroupBox {
Q_OBJECT Q_OBJECT
public: public:
LocationInformationWidget(QWidget *parent = 0); LocationInformationWidget(QWidget *parent = 0);
protected:
void showEvent(QShowEvent *);
\
public slots: public slots:
void acceptChanges(); void acceptChanges();
void rejectChanges(); void rejectChanges();
void showEvent(QShowEvent *);
void setLocationId(uint32_t uuid); void setLocationId(uint32_t uuid);
void updateGpsCoordinates(void); void updateGpsCoordinates(void);
void markChangedWidget(QWidget *w); void markChangedWidget(QWidget *w);
void enableEdition(); void enableEdition();
void resetState(); void resetState();
void resetPallete(); void resetPallete();
void setCurrentDiveSite(int dive_nr);
void on_diveSiteCoordinates_textChanged(const QString& text); void on_diveSiteCoordinates_textChanged(const QString& text);
void on_diveSiteDescription_textChanged(const QString& text); void on_diveSiteDescription_textChanged(const QString& text);
void on_diveSiteName_textChanged(const QString& text); void on_diveSiteName_textChanged(const QString& text);