diff options
author | Maximilian Güntner <maximilian.guentner@gmail.com> | 2013-11-02 02:20:02 +0100 |
---|---|---|
committer | Maximilian Güntner <maximilian.guentner@gmail.com> | 2013-11-02 03:37:31 +0100 |
commit | 04cdfce782f2a104ab5d0ee92de67c7b6271835b (patch) | |
tree | f937c8c8a005ef00f880bbcd3d7c56fd043ddfeb /qt-ui/maintab.cpp | |
parent | 6fe8cb652191728586f3731dcf6688b5a5b3efbb (diff) | |
download | subsurface-04cdfce782f2a104ab5d0ee92de67c7b6271835b.tar.gz |
Added a custom widget for tagging dives
A custom tag widget has been added to MainTab.
Tags are seperated by a comma ",". The implementation
supports escaping a comma by using "\,".
While typing, the widget supports the user by suggesting
tags using a QCompleter.
Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r-- | qt-ui/maintab.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index ddcdc6c63..b7c0f15c7 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -58,6 +58,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.airtemp->installEventFilter(this); ui.watertemp->installEventFilter(this); ui.dateTimeEdit->installEventFilter(this); + ui.tagWidget->installEventFilter(this); QList<QObject *> statisticsTabWidgets = ui.statisticsTab->children(); Q_FOREACH(QObject* obj, statisticsTabWidgets) { @@ -87,10 +88,12 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), completers.divemaster = new QCompleter(DiveMasterCompletionModel::instance(), ui.divemaster); completers.location = new QCompleter(LocationCompletionModel::instance(), ui.location); completers.suit = new QCompleter(SuitCompletionModel::instance(), ui.suit); + completers.tags = new QCompleter(TagCompletionModel::instance(), ui.tagWidget); ui.buddy->setCompleter(completers.buddy); ui.divemaster->setCompleter(completers.divemaster); ui.location->setCompleter(completers.location); ui.suit->setCompleter(completers.suit); + ui.tagWidget->setCompleter(completers.tags); setMinimumHeight(0); setMinimumWidth(0); @@ -161,6 +164,9 @@ void MainTab::enableEdition(EditMode newEditMode) notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true); notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true); notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when - gettimezoneoffset()).toString(QString("M/d/yy h:mm")); + char buf[1024]; + taglist_get_tagstring(mydive->tag_list, buf, 1024); + notesBackup[mydive].tags = QString(buf); // maybe this is a place for memset? for (int i = 0; i < MAX_CYLINDERS; i++) { @@ -182,7 +188,9 @@ bool MainTab::eventFilter(QObject* object, QEvent* event) enableEdition(); } - if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui.rating || object == ui.visibility)) { + if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui.rating || + object == ui.visibility || + object == ui.tagWidget)) { tabBar()->setTabIcon(currentIndex(), QIcon(":warning")); enableEdition(); } @@ -215,6 +223,7 @@ void MainTab::clearInfo() ui.airTemperatureText->clear(); ui.airPressureText->clear(); ui.salinityText->clear(); + ui.tagWidget->clear(); } void MainTab::clearStats() @@ -356,6 +365,11 @@ void MainTab::updateDiveInfo(int dive) ui.timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 0)); ui.timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0)); + + char buf[1024]; + taglist_get_tagstring(d->tag_list, buf, 1024); + ui.tagWidget->setText(QString(buf)); + multiEditEquipmentPlaceholder = *d; cylindersModel->setDive(&multiEditEquipmentPlaceholder); weightModel->setDive(&multiEditEquipmentPlaceholder); @@ -393,6 +407,7 @@ void MainTab::reload() BuddyCompletionModel::instance()->updateModel(); LocationCompletionModel::instance()->updateModel(); DiveMasterCompletionModel::instance()->updateModel(); + TagCompletionModel::instance()->updateModel(); } void MainTab::acceptChanges() @@ -423,7 +438,8 @@ void MainTab::acceptChanges() notesBackup[curr].airtemp != ui.airtemp->text() || notesBackup[curr].watertemp != ui.watertemp->text() || notesBackup[curr].datetime != ui.dateTimeEdit->dateTime().toString(QString("M/d/yy h:mm")) || - notesBackup[curr].visibility != ui.rating->currentStars()) { + notesBackup[curr].visibility != ui.rating->currentStars() || + notesBackup[curr].tags != ui.tagWidget->text()) { mark_divelist_changed(TRUE); } if (notesBackup[curr].location != ui.location->text() || @@ -431,6 +447,9 @@ void MainTab::acceptChanges() mainWindow()->globe()->reload(); } + if (notesBackup[curr].tags != ui.tagWidget->text()) + saveTags(); + if (cylindersModel->changed) { mark_divelist_changed(TRUE); Q_FOREACH (dive *d, notesBackup.keys()) { @@ -480,6 +499,7 @@ void MainTab::resetPallete() ui.airtemp->setPalette(p); ui.watertemp->setPalette(p); ui.dateTimeEdit->setPalette(p); + ui.tagWidget->setPalette(p); } #define EDIT_TEXT2(what, text) \ @@ -522,6 +542,7 @@ void MainTab::rejectChanges() ui.airtemp->setText(notesBackup[curr].airtemp); ui.watertemp->setText(notesBackup[curr].watertemp); ui.dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime, QString("M/d/y h:mm"))); + ui.tagWidget->setText(notesBackup[curr].tags); struct dive *mydive; for (int i = 0; i < dive_table.nr; i++) { @@ -628,6 +649,21 @@ void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime) markChangedWidget(ui.dateTimeEdit); } +void MainTab::saveTags() +{ + EDIT_SELECTED_DIVES( + QString tag; + taglist_clear(mydive->tag_list); + foreach (tag, ui.tagWidget->getBlockStringList()) + taglist_add_tag(mydive->tag_list, tag.toAscii().data()); + ); +} + +void MainTab::on_tagWidget_textChanged() +{ + markChangedWidget(ui.tagWidget); +} + void MainTab::on_location_textChanged(const QString& text) { if (editMode == NONE) |