mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
map: use value semantics for MapLocation
This makes memory management more simple, as not explicit deletion is necessary. A rather large commit, because changing QVector<> to std::vector<> is propagated up the call chain. Adds a new range_contains() helper function for collection types such as std::vector<>. I didn't want to call it contains(), since we already have a contains function for strings and let's keep argument overloading simple. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e39dea3d68
commit
6b835710bc
17 changed files with 84 additions and 75 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "divelog.h"
|
||||
#include "gettextfromc.h"
|
||||
#include "qthelper.h"
|
||||
#include "range.h"
|
||||
#include "selection.h"
|
||||
#include "subsurface-qt/divelistnotifier.h"
|
||||
#if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER)
|
||||
|
|
@ -61,7 +62,7 @@ ShownChange DiveFilter::update(const QVector<dive *> &dives) const
|
|||
std::vector<dive *> removeFromSelection;
|
||||
for (dive *d: dives) {
|
||||
// There are three modes: divesite, fulltext, normal
|
||||
bool newStatus = doDS ? dive_sites.contains(d->dive_site) :
|
||||
bool newStatus = doDS ? range_contains(dive_sites, d->dive_site) :
|
||||
doFullText ? fulltext_dive_matches(d, filterData.fullText, filterData.fulltextStringMode) && showDive(d) :
|
||||
showDive(d);
|
||||
updateDiveStatus(d, newStatus, res, removeFromSelection);
|
||||
|
|
@ -91,7 +92,7 @@ ShownChange DiveFilter::updateAll() const
|
|||
// There are three modes: divesite, fulltext, normal
|
||||
if (diveSiteMode()) {
|
||||
for_each_dive(i, d) {
|
||||
bool newStatus = dive_sites.contains(d->dive_site);
|
||||
bool newStatus = range_contains(dive_sites, d->dive_site);
|
||||
updateDiveStatus(d, newStatus, res, removeFromSelection);
|
||||
}
|
||||
} else if (filterData.fullText.doit()) {
|
||||
|
|
@ -142,7 +143,7 @@ bool DiveFilter::showDive(const struct dive *d) const
|
|||
}
|
||||
|
||||
#if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER)
|
||||
void DiveFilter::startFilterDiveSites(QVector<dive_site *> ds)
|
||||
void DiveFilter::startFilterDiveSites(std::vector<dive_site *> ds)
|
||||
{
|
||||
if (++diveSiteRefCount > 1) {
|
||||
setFilterDiveSite(std::move(ds));
|
||||
|
|
@ -169,7 +170,7 @@ void DiveFilter::stopFilterDiveSites()
|
|||
#endif
|
||||
}
|
||||
|
||||
void DiveFilter::setFilterDiveSite(QVector<dive_site *> ds)
|
||||
void DiveFilter::setFilterDiveSite(std::vector<dive_site *> ds)
|
||||
{
|
||||
// If the filter didn't change, return early to avoid a full
|
||||
// map reload. For a well-defined comparison, sort the vector first.
|
||||
|
|
@ -185,7 +186,7 @@ void DiveFilter::setFilterDiveSite(QVector<dive_site *> ds)
|
|||
MainWindow::instance()->diveList->expandAll();
|
||||
}
|
||||
|
||||
const QVector<dive_site *> &DiveFilter::filteredDiveSites() const
|
||||
const std::vector<dive_site *> &DiveFilter::filteredDiveSites() const
|
||||
{
|
||||
return dive_sites;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ public:
|
|||
bool diveSiteMode() const; // returns true if we're filtering on dive site (on mobile always returns false)
|
||||
std::vector<dive *> visibleDives() const;
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
const QVector<dive_site *> &filteredDiveSites() const;
|
||||
void startFilterDiveSites(QVector<dive_site *> ds);
|
||||
void setFilterDiveSite(QVector<dive_site *> ds);
|
||||
const std::vector<dive_site *> &filteredDiveSites() const;
|
||||
void startFilterDiveSites(std::vector<dive_site *> ds);
|
||||
void setFilterDiveSite(std::vector<dive_site *> ds);
|
||||
void stopFilterDiveSites();
|
||||
#endif
|
||||
void setFilter(const FilterData &data);
|
||||
|
|
@ -62,7 +62,7 @@ private:
|
|||
void updateDiveStatus(dive *d, bool newStatus, ShownChange &change,
|
||||
std::vector<dive *> &removeFromSelection) const;
|
||||
|
||||
QVector<dive_site *> dive_sites;
|
||||
std::vector<dive_site *> dive_sites;
|
||||
FilterData filterData;
|
||||
mutable int shown_dives;
|
||||
|
||||
|
|
|
|||
|
|
@ -98,4 +98,11 @@ int index_of_if(const Range &range, Func f)
|
|||
return it == std::end(range) ? -1 : it - std::begin(range);
|
||||
}
|
||||
|
||||
// Not really appropriate here, but oh my.
|
||||
template<typename Range, typename Element>
|
||||
bool range_contains(const Range &v, const Element &item)
|
||||
{
|
||||
return std::find(v.begin(), v.end(), item) != v.end();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#ifndef SUBSURFACE_STRING_H
|
||||
#define SUBSURFACE_STRING_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue