1
0
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:
tux3 2015-06-05 22:21:16 +02:00
parent b948ef890f
commit 3284a66f49
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 7 additions and 11 deletions

View File

@ -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));
}

View File

@ -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