From 706822123f80c426ffb5c64edf2d31038aa8c276 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Sat, 14 Jul 2018 00:06:04 +0300 Subject: [PATCH] refactor: delete sqlite in travis, edit some functions --- .travis/build-ubuntu-14-04.sh | 9 -------- src/chatlog/content/text.cpp | 4 +++- src/chatlog/content/text.h | 1 - src/persistence/db/rawdatabase.cpp | 7 ------- src/persistence/db/rawdatabase.h | 11 ++++++---- src/persistence/history.cpp | 23 ++++++++------------- src/widget/form/genericchatform.cpp | 32 +++++++++++++++++------------ src/widget/searchtypes.h | 10 ++++----- 8 files changed, 42 insertions(+), 55 deletions(-) diff --git a/.travis/build-ubuntu-14-04.sh b/.travis/build-ubuntu-14-04.sh index 34343b39a..f19b5e97e 100755 --- a/.travis/build-ubuntu-14-04.sh +++ b/.travis/build-ubuntu-14-04.sh @@ -52,15 +52,6 @@ sudo apt-get install -y --force-yes \ # Qt source /opt/qt55/bin/qt55-env.sh || yes -# sqlite -wget https://sqlite.org/2018/sqlite-autoconf-3240000.tar.gz -tar xvfz sqlite-autoconf-3240000.tar.gz -cd sqlite-autoconf-3240000 -./configure -make -j$(nproc) -sudo make install -cd .. - # ffmpeg if [ ! -e "libs" ]; then mkdir libs; fi if [ ! -e "ffmpeg" ]; then mkdir ffmpeg; fi diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index bc89709b0..f34ff8aea 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -33,6 +33,8 @@ #include "src/widget/style.h" +static const QString COLOR_HIGHLIGHT = QStringLiteral("#ff7626"); + Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText, const QColor c) : rawText(rwText) @@ -450,7 +452,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair& point) cursor.endEditBlock(); QTextCharFormat format; - format.setBackground(QBrush(colorHighlight)); + format.setBackground(QBrush(QColor(COLOR_HIGHLIGHT))); cursor.mergeCharFormat(format); regenerate(); diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index c0eb1d7ce..633a8a06f 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -97,7 +97,6 @@ private: QFont defFont; QString defStyleSheet; QColor color; - const QColor colorHighlight{"#ff7626"}; }; #endif // TEXT_H diff --git a/src/persistence/db/rawdatabase.cpp b/src/persistence/db/rawdatabase.cpp index c11cea6da..686bc7746 100644 --- a/src/persistence/db/rawdatabase.cpp +++ b/src/persistence/db/rawdatabase.cpp @@ -29,13 +29,6 @@ #include #include -/// The two following defines are required to use SQLCipher -/// They are used by the sqlite3.h header -#define SQLITE_HAS_CODEC -#define SQLITE_TEMP_STORE 2 - -#include - /** * @class RawDatabase diff --git a/src/persistence/db/rawdatabase.h b/src/persistence/db/rawdatabase.h index f4a8b37a4..9fd820233 100644 --- a/src/persistence/db/rawdatabase.h +++ b/src/persistence/db/rawdatabase.h @@ -14,10 +14,13 @@ #include #include -struct sqlite3; -struct sqlite3_stmt; -struct sqlite3_context; -struct sqlite3_value; +/// The two following defines are required to use SQLCipher +/// They are used by the sqlite3.h header +#define SQLITE_HAS_CODEC +#define SQLITE_TEMP_STORE 2 + +#include + class RawDatabase : QObject { diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 84dcb16ed..7c52a8f76 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -325,9 +325,9 @@ QList History::getChatHistoryCounts(const ToxPk& friendPk */ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, QString phrase, const ParameterSearch& parameter) { - QList counts; - auto rowCallback = [&counts](const QVector& row) { - counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong())); + QDateTime result; + auto rowCallback = [&result](const QVector& row) { + result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong()); }; phrase.replace("'", "''"); @@ -389,11 +389,8 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi .arg(period); db->execNow({queryText, rowCallback}); - if (!counts.isEmpty()) { - return counts[0]; - } - return QDateTime(); + return result; } /** @@ -403,9 +400,9 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi */ QDateTime History::getStartDateChatHistory(const QString &friendPk) { - QList counts; - auto rowCallback = [&counts](const QVector& row) { - counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong())); + QDateTime result; + auto rowCallback = [&result](const QVector& row) { + result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong()); }; QString queryText = @@ -418,11 +415,7 @@ QDateTime History::getStartDateChatHistory(const QString &friendPk) db->execNow({queryText, rowCallback}); - if (!counts.isEmpty()) { - return counts[0]; - } - - return QDateTime(); + return result; } /** diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index ff411d66c..af8dd80c2 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -540,7 +540,7 @@ void GenericChatForm::addSystemDateMessage() QDate GenericChatForm::getDate(const ChatLine::Ptr &chatLine) const { if (chatLine) { - Timestamp* timestamp = qobject_cast(chatLine->getContent(2)); + Timestamp* const timestamp = qobject_cast(chatLine->getContent(2)); if (timestamp) { return timestamp->getTime().date(); @@ -589,20 +589,26 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch& if (parameter.period == PeriodSearch::WithTheFirst) { startLine = 0; } else if (parameter.period == PeriodSearch::AfterDate) { - for (int i = 0; i < lines.size(); ++i) { - auto d = getDate(lines[i]); - if (d.isValid() && parameter.date <= d) { - startLine = i; - break; - } + auto lambda = [=](const ChatLine::Ptr& item) { + auto d = getDate(item); + return d.isValid() && parameter.date <= d; + }; + + auto find = std::find_if(lines.begin(), lines.end(), lambda); + + if (find != lines.end()) { + startLine = static_cast(std::distance(lines.begin(), find)); } } else if (parameter.period == PeriodSearch::BeforeDate) { - for (int i = lines.size() - 1; i >= 0; --i) { - auto d = getDate(lines[i]); - if (d.isValid() && parameter.date >= d) { - startLine = i; - break; - } + auto lambda = [=](const ChatLine::Ptr& item) { + auto d = getDate(item); + return d.isValid() && parameter.date >= d; + }; + + auto find = std::find_if(lines.rbegin(), lines.rend(), lambda); + + if (find != lines.rend()) { + startLine = static_cast(std::distance(find, lines.rend())) - 1; } } diff --git a/src/widget/searchtypes.h b/src/widget/searchtypes.h index be618dba1..319964d6c 100644 --- a/src/widget/searchtypes.h +++ b/src/widget/searchtypes.h @@ -49,18 +49,18 @@ public: static QString generateFilterWordsOnly(const QString &phrase) { QString filter = QRegularExpression::escape(phrase); - QString symbols = {"\\[]/^$.|?*+(){}"}; + const QString symbols = QStringLiteral("\\[]/^$.|?*+(){}"); if (filter != phrase) { if (filter.left(1) != QLatin1String("\\")) { - filter = "\\b" + filter; + filter = QLatin1String("\\b") + filter; } else { - filter = "(^|\\s)" + filter; + filter = QLatin1String("(^|\\s)") + filter; } if (!symbols.contains(filter.right(1))) { - filter += "\\b"; + filter += QLatin1String("\\b"); } else { - filter += "($|\\s)"; + filter += QLatin1String("($|\\s)"); } } else { filter = QStringLiteral("\\b%1\\b").arg(filter);