aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/common/utils.h
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
commit65d5f68cc6dc81799c5a5d90400a2c1f0dd02547 (patch)
tree6f245ba901b87ef42fed69965aea22f5eea6b590 /SQLiteStudio3/coreSQLiteStudio/common/utils.h
parentaeb6bad01630d325a4e768e798a7a6d44e18fdaf (diff)
parent5d9314f134ddd3dc4c853e398ac90ba247fb2e4f (diff)
Merge tag 'upstream/3.1.0'
Upstream version 3.1.0 # gpg: Signature made Mon 13 Jun 2016 06:42:54 PM EDT using RSA key ID EBE9BD91 # gpg: Good signature from "Unit 193 <unit193@gmail.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.org>" # gpg: aka "Unit 193 <unit193@ubuntu.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.com>"
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/utils.h')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/common/utils.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/utils.h b/SQLiteStudio3/coreSQLiteStudio/common/utils.h
index 90d2d62..934e70a 100644
--- a/SQLiteStudio3/coreSQLiteStudio/common/utils.h
+++ b/SQLiteStudio3/coreSQLiteStudio/common/utils.h
@@ -57,7 +57,7 @@ API_EXPORT QString randStr(int length, bool numChars = true, bool whiteSpaces =
API_EXPORT QString randStr(int length, const QString& charCollection);
API_EXPORT QString randBinStr(int length);
API_EXPORT QString randStrNotIn(int length, const QSet<QString> set, bool numChars = true, bool whiteSpaces = false);
-API_EXPORT QString generateUniqueName(const QString& prefix, const QStringList& existingNames);
+API_EXPORT QString generateUniqueName(const QString& prefix, const QStringList& existingNames, Qt::CaseSensitivity cs = Qt::CaseSensitive);
API_EXPORT bool isNumeric(const QVariant& value);
API_EXPORT QString rStrip(const QString& str);
API_EXPORT QStringList tokenizeArgs(const QString& str);
@@ -73,6 +73,20 @@ API_EXPORT QHash<QString,QVariant> bytesToHash(const QByteArray& bytes);
API_EXPORT int indexOf(const QStringList& list, const QString& value, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive);
API_EXPORT int indexOf(const QStringList& list, const QString& value, Qt::CaseSensitivity cs = Qt::CaseSensitive);
+template <class T>
+int indexOf(const QList<T>& list, std::function<bool(const T&)> predicate)
+{
+ int i = 0;
+ for (const T& item : list)
+ {
+ if (predicate(item))
+ return i;
+
+ ++i;
+ }
+ return -1;
+}
+
/**
* @brief Returns only those elements from the list, which passed the filter.
* @tparam T type for which the filter will be applied for. It should match the type in the list and in the function argument.
@@ -103,6 +117,18 @@ bool contains(const QList<T>& list, std::function<bool(const T& value)> testFunc
return false;
}
+template <class T>
+QList<T> concat(const QList<QList<T>>& list)
+{
+ QList<T> result;
+ for (const QList<T>& item : list)
+ result.append(item);
+
+ return result;
+}
+
+API_EXPORT QStringList concat(const QList<QStringList>& list);
+
/**
* @brief Appends or prepends characters to the string to make it of specified length.
* @param str Input string to work with.
@@ -205,6 +231,18 @@ API_EXPORT bool renameBetweenPartitions(const QString& src, const QString& dst);
API_EXPORT bool isWritableRecursively(const QString& dir);
API_EXPORT QString encryptRsa(const QString& input, const QString& modulus, const QString& exponent);
API_EXPORT QString decryptRsa(const QString& input, const QString& modulus, const QString& exponent);
+API_EXPORT QString doubleToString(double val);
+
+/**
+ * @brief Sorts string list using reference list for ordering.
+ * @param listToSort This list will be sorted.
+ * @param referenceList Should contain all elements from list to sort - it tells the order.
+ * @param cs Case sensitivity of the string comparision.
+ *
+ * Sorts \p listToSort using \p referenceList as a reference of what is the order.
+ * If any element from \p listToSort is not on the list of \p referenceList, then the element will be placed at the end.
+ */
+API_EXPORT void sortWithReferenceList(QList<QString>& listToSort, const QList<QString>& referenceList, Qt::CaseSensitivity cs = Qt::CaseSensitive);
enum class DistributionType
{