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 <QDebug>
|
||||
#include <QMutexLocker>
|
||||
#include <algorithm>
|
||||
|
||||
QTranslator* Translator::translator{nullptr};
|
||||
QVector<QPair<void*, std::function<void()>>> Translator::callbacks;
|
||||
QVector<Translator::Callback> Translator::callbacks;
|
||||
QMutex Translator::lock;
|
||||
|
||||
void Translator::translate()
|
||||
|
@ -64,12 +65,6 @@ void Translator::registerHandler(std::function<void()> f, void *owner)
|
|||
void Translator::unregister(void *owner)
|
||||
{
|
||||
QMutexLocker locker{&lock};
|
||||
for (int i=0; i<callbacks.size(); i++)
|
||||
{
|
||||
if (callbacks[i].first == owner)
|
||||
{
|
||||
callbacks.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
callbacks.erase(std::remove_if(begin(callbacks), end(callbacks),
|
||||
[=](const Callback& c){return c.first==owner;}), end(callbacks));
|
||||
}
|
||||
|
|
|
@ -19,9 +19,10 @@ public:
|
|||
static void unregister(void* owner);
|
||||
|
||||
private:
|
||||
static QTranslator* translator;
|
||||
static QVector<QPair<void*, std::function<void()>>> callbacks;
|
||||
using Callback = QPair<void*, std::function<void()>>;
|
||||
static QVector<Callback> callbacks;
|
||||
static QMutex lock;
|
||||
static QTranslator* translator;
|
||||
};
|
||||
|
||||
#endif // TRANSLATOR_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user