mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Clean up Translator a little
Using the STL is still better than writting our own for loops.
This commit is contained in:
parent
b948ef890f
commit
3284a66f49
|
@ -7,9 +7,10 @@
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
QTranslator* Translator::translator{nullptr};
|
QTranslator* Translator::translator{nullptr};
|
||||||
QVector<QPair<void*, std::function<void()>>> Translator::callbacks;
|
QVector<Translator::Callback> Translator::callbacks;
|
||||||
QMutex Translator::lock;
|
QMutex Translator::lock;
|
||||||
|
|
||||||
void Translator::translate()
|
void Translator::translate()
|
||||||
|
@ -64,12 +65,6 @@ void Translator::registerHandler(std::function<void()> f, void *owner)
|
||||||
void Translator::unregister(void *owner)
|
void Translator::unregister(void *owner)
|
||||||
{
|
{
|
||||||
QMutexLocker locker{&lock};
|
QMutexLocker locker{&lock};
|
||||||
for (int i=0; i<callbacks.size(); i++)
|
callbacks.erase(std::remove_if(begin(callbacks), end(callbacks),
|
||||||
{
|
[=](const Callback& c){return c.first==owner;}), end(callbacks));
|
||||||
if (callbacks[i].first == owner)
|
|
||||||
{
|
|
||||||
callbacks.removeAt(i);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,10 @@ public:
|
||||||
static void unregister(void* owner);
|
static void unregister(void* owner);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QTranslator* translator;
|
using Callback = QPair<void*, std::function<void()>>;
|
||||||
static QVector<QPair<void*, std::function<void()>>> callbacks;
|
static QVector<Callback> callbacks;
|
||||||
static QMutex lock;
|
static QMutex lock;
|
||||||
|
static QTranslator* translator;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSLATOR_H
|
#endif // TRANSLATOR_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user