diff --git a/src/autotype/xcb/AutoTypeXCB.cpp b/src/autotype/xcb/AutoTypeXCB.cpp index 4c6597040..40acaf663 100644 --- a/src/autotype/xcb/AutoTypeXCB.cpp +++ b/src/autotype/xcb/AutoTypeXCB.cpp @@ -18,6 +18,7 @@ #include "AutoTypeXCB.h" #include "KeySymMap.h" +#include "core/Tools.h" #include #include @@ -404,9 +405,9 @@ KeySym AutoTypePlatformX11::charToKeySym(const QChar& ch) } /* mapping table generated from keysymdef.h */ - const uint* match = qBinaryFind(m_unicodeToKeysymKeys, - m_unicodeToKeysymKeys + m_unicodeToKeysymLen, - unicode); + const uint* match = Tools::binaryFind(m_unicodeToKeysymKeys, + m_unicodeToKeysymKeys + m_unicodeToKeysymLen, + unicode); int index = match - m_unicodeToKeysymKeys; if (index != m_unicodeToKeysymLen) { return m_unicodeToKeysymValues[index]; diff --git a/src/core/Tools.h b/src/core/Tools.h index 19c6094b8..d55c30a5a 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -18,10 +18,14 @@ #ifndef KEEPASSX_TOOLS_H #define KEEPASSX_TOOLS_H +#include "core/Global.h" + #include #include #include +#include + class QIODevice; namespace Tools { @@ -36,6 +40,19 @@ void sleep(int ms); void wait(int ms); void disableCoreDumps(); +template +KEEPASSX_EXPORT RandomAccessIterator binaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T& value) +{ + RandomAccessIterator it = std::lower_bound(begin, end, value); + + if ((it == end) || (value < *it)) { + return end; + } + else { + return it; + } +} + } // namespace Tools #endif // KEEPASSX_TOOLS_H diff --git a/src/gui/entry/EntryAttachmentsModel.cpp b/src/gui/entry/EntryAttachmentsModel.cpp index baf04549f..39ed69f1f 100644 --- a/src/gui/entry/EntryAttachmentsModel.cpp +++ b/src/gui/entry/EntryAttachmentsModel.cpp @@ -20,6 +20,8 @@ #include "core/Entry.h" #include "core/Tools.h" +#include + EntryAttachmentsModel::EntryAttachmentsModel(QObject* parent) : QAbstractListModel(parent) , m_entryAttachments(nullptr) @@ -102,7 +104,7 @@ void EntryAttachmentsModel::attachmentAboutToAdd(const QString& key) { QList rows = m_entryAttachments->keys(); rows.append(key); - qSort(rows); + std::sort(rows.begin(), rows.end()); int row = rows.indexOf(key); beginInsertRows(QModelIndex(), row, row); } diff --git a/src/gui/entry/EntryAttributesModel.cpp b/src/gui/entry/EntryAttributesModel.cpp index d4454adef..297740c3c 100644 --- a/src/gui/entry/EntryAttributesModel.cpp +++ b/src/gui/entry/EntryAttributesModel.cpp @@ -20,6 +20,8 @@ #include "core/Entry.h" #include "core/Tools.h" +#include + EntryAttributesModel::EntryAttributesModel(QObject* parent) : QAbstractListModel(parent) , m_entryAttributes(nullptr) @@ -152,7 +154,7 @@ void EntryAttributesModel::attributeAboutToAdd(const QString& key) { QList rows = m_attributes; rows.append(key); - qSort(rows); + std::sort(rows.begin(), rows.end()); int row = rows.indexOf(key); beginInsertRows(QModelIndex(), row, row); } @@ -182,7 +184,7 @@ void EntryAttributesModel::attributeAboutToRename(const QString& oldKey, const Q QList rows = m_attributes; rows.removeOne(oldKey); rows.append(newKey); - qSort(rows); + std::sort(rows.begin(), rows.end()); int newRow = rows.indexOf(newKey); if (newRow > oldRow) { newRow++;