2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/completionmodels.h"
|
|
|
|
#include "core/dive.h"
|
2019-05-30 16:29:36 +00:00
|
|
|
#include "core/tag.h"
|
2015-09-03 00:22:29 +00:00
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
2013-08-13 13:30:22 +00:00
|
|
|
|
2020-10-26 14:27:47 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
#define SKIP_EMPTY Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
#define SKIP_EMPTY QString::SkipEmptyParts
|
|
|
|
#endif
|
|
|
|
|
2020-11-12 16:48:54 +00:00
|
|
|
static QStringList getCSVList(char *dive::*item)
|
|
|
|
{
|
|
|
|
QSet<QString> set;
|
|
|
|
struct dive *dive;
|
|
|
|
int i = 0;
|
|
|
|
for_each_dive (i, dive) {
|
|
|
|
QString str(dive->*item);
|
|
|
|
for (const QString &value: str.split(",", SKIP_EMPTY))
|
|
|
|
set.insert(value.trimmed());
|
2014-02-28 04:09:57 +00:00
|
|
|
}
|
2020-11-12 16:48:54 +00:00
|
|
|
QStringList setList = set.values();
|
|
|
|
std::sort(setList.begin(), setList.end());
|
|
|
|
return setList;
|
|
|
|
}
|
2014-01-15 20:35:13 +00:00
|
|
|
|
2020-11-12 16:48:54 +00:00
|
|
|
void BuddyCompletionModel::updateModel()
|
|
|
|
{
|
|
|
|
setStringList(getCSVList(&dive::buddy));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveMasterCompletionModel::updateModel()
|
|
|
|
{
|
|
|
|
setStringList(getCSVList(&dive::divemaster));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuitCompletionModel::updateModel()
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
struct dive *dive;
|
|
|
|
int i = 0;
|
|
|
|
for_each_dive (i, dive) {
|
|
|
|
QString suit(dive->suit);
|
|
|
|
if (!list.contains(suit))
|
|
|
|
list.append(suit);
|
|
|
|
}
|
|
|
|
std::sort(list.begin(), list.end());
|
|
|
|
setStringList(list);
|
|
|
|
}
|
2013-08-13 13:30:22 +00:00
|
|
|
|
2013-11-02 01:20:02 +00:00
|
|
|
void TagCompletionModel::updateModel()
|
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
if (g_tag_list == NULL)
|
2013-11-02 01:20:02 +00:00
|
|
|
return;
|
|
|
|
QStringList list;
|
2015-09-09 18:52:43 +00:00
|
|
|
struct tag_entry *current_tag_entry = g_tag_list;
|
2013-11-02 01:20:02 +00:00
|
|
|
while (current_tag_entry != NULL) {
|
|
|
|
list.append(QString(current_tag_entry->tag->name));
|
|
|
|
current_tag_entry = current_tag_entry->next;
|
|
|
|
}
|
|
|
|
setStringList(list);
|
|
|
|
}
|