mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Show the number of dives with given person / location in the filter panel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5a329ff262
commit
61dc19d2e0
4 changed files with 52 additions and 3 deletions
29
dive.c
29
dive.c
|
@ -2500,6 +2500,7 @@ bool taglist_contains(struct tag_entry *tag_list, const char *tag)
|
|||
return false;
|
||||
}
|
||||
|
||||
// count the dives where the tag list contains the given tag
|
||||
int count_dives_with_tag(const char *tag)
|
||||
{
|
||||
int i, counter = 0;
|
||||
|
@ -2512,6 +2513,34 @@ int count_dives_with_tag(const char *tag)
|
|||
return counter;
|
||||
}
|
||||
|
||||
extern bool string_sequence_contains(const char *string_sequence, const char *text);
|
||||
|
||||
// count the dives where the person is included in the comma separated string sequences of buddies or divemasters
|
||||
int count_dives_with_person(const char *person)
|
||||
{
|
||||
int i, counter = 0;
|
||||
struct dive *d;
|
||||
|
||||
for_each_dive (i, d) {
|
||||
if (string_sequence_contains(d->buddy, person) || string_sequence_contains(d->divemaster, person))
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
// count the dives with exactly the location
|
||||
int count_dives_with_location(const char *location)
|
||||
{
|
||||
int i, counter = 0;
|
||||
struct dive *d;
|
||||
|
||||
for_each_dive (i, d) {
|
||||
if (same_string(d->location, location))
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded)
|
||||
{
|
||||
struct dive *res = alloc_dive();
|
||||
|
|
2
dive.h
2
dive.h
|
@ -235,6 +235,8 @@ void taglist_free(struct tag_entry *tag_list);
|
|||
|
||||
bool taglist_contains(struct tag_entry *tag_list, const char *tag);
|
||||
int count_dives_with_tag(const char *tag);
|
||||
int count_dives_with_person(const char *person);
|
||||
int count_dives_with_location(const char *location);
|
||||
|
||||
struct extra_data {
|
||||
const char *key;
|
||||
|
|
|
@ -2270,7 +2270,7 @@ QVariant TagFilterModel::data(const QModelIndex &index, int role) const
|
|||
} else if (role == Qt::DisplayRole) {
|
||||
QString tag = stringList()[index.row()];
|
||||
int count = count_dives_with_tag(tag.toUtf8().data());
|
||||
return tag + QString("(%1)").arg(count);
|
||||
return tag + QString(" (%1)").arg(count);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -2467,7 +2467,9 @@ QVariant BuddyFilterModel::data(const QModelIndex &index, int role) const
|
|||
if (role == Qt::CheckStateRole) {
|
||||
return checkState[index.row()] ? Qt::Checked : Qt::Unchecked;
|
||||
} else if (role == Qt::DisplayRole) {
|
||||
return stringList()[index.row()];
|
||||
QString person = stringList()[index.row()];
|
||||
int count = count_dives_with_person(person.toUtf8().data());
|
||||
return person + QString(" (%1)").arg(count);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -2499,7 +2501,9 @@ QVariant LocationFilterModel::data(const QModelIndex &index, int role) const
|
|||
if (role == Qt::CheckStateRole) {
|
||||
return checkState[index.row()] ? Qt::Checked : Qt::Unchecked;
|
||||
} else if (role == Qt::DisplayRole) {
|
||||
return stringList()[index.row()];
|
||||
QString location = stringList()[index.row()];
|
||||
int count = count_dives_with_location(location.toUtf8().data());
|
||||
return location + QString(" (%1)").arg(count);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
|
14
qthelper.cpp
14
qthelper.cpp
|
@ -301,6 +301,20 @@ extern "C" void copy_image_and_overwrite(const char *cfileName, const char *cnew
|
|||
QFile::copy(fileName, newName);
|
||||
}
|
||||
|
||||
extern "C" bool string_sequence_contains(const char *string_sequence, const char *text)
|
||||
{
|
||||
if (same_string(text, "") || same_string(string_sequence, ""))
|
||||
return false;
|
||||
|
||||
QString stringSequence(string_sequence);
|
||||
QStringList strings = stringSequence.split(",", QString::SkipEmptyParts);
|
||||
Q_FOREACH (QString string, strings) {
|
||||
if (string.trimmed().compare(QString(text).trimmed(), Qt::CaseInsensitive) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool lessThan(const QPair<QString, int> &a, const QPair<QString, int> &b)
|
||||
{
|
||||
return a.second < b.second;
|
||||
|
|
Loading…
Add table
Reference in a new issue