diff --git a/src/persistence/db/rawdatabase.cpp b/src/persistence/db/rawdatabase.cpp index aff9b11ec..c11cea6da 100644 --- a/src/persistence/db/rawdatabase.cpp +++ b/src/persistence/db/rawdatabase.cpp @@ -742,13 +742,13 @@ void RawDatabase::regexpSensitive(sqlite3_context* ctx, int argc, sqlite3_value* void RawDatabase::regexp(sqlite3_context* ctx, int argc, sqlite3_value** argv, const QRegularExpression::PatternOptions cs) { QRegularExpression regex; - QString str1((const char*)sqlite3_value_text(argv[0])); - QString str2((const char*)sqlite3_value_text(argv[1])); + const QString str1(reinterpret_cast(sqlite3_value_text(argv[0]))); + const QString str2(reinterpret_cast(sqlite3_value_text(argv[1]))); regex.setPattern(str1); regex.setPatternOptions(cs); - bool b = str2.contains(regex); + const bool b = str2.contains(regex); if (b) { sqlite3_result_int(ctx, 1); diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 6daf32a37..84dcb16ed 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -388,7 +388,6 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi .arg(message) .arg(period); - qDebug() << "mes:" << queryText; db->execNow({queryText, rowCallback}); if (!counts.isEmpty()) { return counts[0]; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index c6a0a9f31..030c6992b 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -503,12 +503,12 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param searchPoint = QPoint(1, -1); - bool b = (parameter.period == PeriodSearch::WithTheFirst); - bool b1 = (parameter.period == PeriodSearch::AfterDate); - if (b || b1) { - if (b || (b1 && parameter.date < getFirstDate())) { - QString pk = f->getPublicKey().toString(); - if ((b || parameter.date >= history->getStartDateChatHistory(pk).date()) && + const bool isFirst = (parameter.period == PeriodSearch::WithTheFirst); + const bool isAfter = (parameter.period == PeriodSearch::AfterDate); + if (isFirst || isAfter) { + if (isFirst || (isAfter && parameter.date < getFirstDate())) { + const QString pk = f->getPublicKey().toString(); + if ((isFirst || parameter.date >= history->getStartDateChatHistory(pk).date()) && loadHistory(phrase, parameter)) { return; @@ -518,7 +518,7 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param onSearchDown(phrase, parameter); } else { if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstDate()) { - QString pk = f->getPublicKey().toString(); + const QString pk = f->getPublicKey().toString(); if (parameter.date >= history->getStartDateChatHistory(pk).date() && loadHistory(phrase, parameter)) { return; } @@ -553,8 +553,8 @@ void ChatForm::onSearchUp(const QString& phrase, const ParameterSearch& paramete bool isSearch = searchInText(phrase, parameter, true); if (!isSearch) { - QString pk = f->getPublicKey().toString(); - QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); + const QString pk = f->getPublicKey().toString(); + const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); if (!newBaseDate.isValid()) { return; @@ -750,7 +750,7 @@ QString getMsgAuthorDispName(const ToxPk& authorPk, const QString& dispName) void ChatForm::loadHistoryDefaultNum(bool processUndelivered) { - QString pk = f->getPublicKey().toString(); + const QString pk = f->getPublicKey().toString(); QList msgs = history->getChatHistoryDefaultNum(pk); if (!msgs.isEmpty()) { earliestMessage = msgs.first().timestamp; @@ -1075,8 +1075,8 @@ void ChatForm::SendMessageStr(QString msg) bool ChatForm::loadHistory(const QString& phrase, const ParameterSearch& parameter) { - QString pk = f->getPublicKey().toString(); - QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); + const QString pk = f->getPublicKey().toString(); + const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); if (newBaseDate.isValid() && getFirstDate().isValid() && newBaseDate.date() < getFirstDate()) { searchAfterLoadHistory = true; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 6007ea357..ff411d66c 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -948,8 +948,8 @@ void GenericChatForm::onSearchTriggered() void GenericChatForm::onContinueSearch() { - QString phrase = searchForm->getSearchPhrase(); - ParameterSearch parameter = searchForm->getParameterSearch(); + const QString phrase = searchForm->getSearchPhrase(); + const ParameterSearch parameter = searchForm->getParameterSearch(); if (!phrase.isEmpty() && searchAfterLoadHistory) { if (parameter.period == PeriodSearch::WithTheFirst || parameter.period == PeriodSearch::AfterDate) { searchAfterLoadHistory = false; diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index 1a642975c..20507e715 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -13,11 +13,10 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) : ui->startDateLabel->setEnabled(false); ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); - ui->choiceDateButton->setObjectName("choiceDateButton"); + ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton")); ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); - ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}"); - isUpdate = false; + ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #ddd;}")); // TODO: need use a style file (.css) connect(ui->startSearchComboBox, static_cast(&QComboBox::currentIndexChanged), this, &SearchSettingsForm::onStartSearchSelected); @@ -77,7 +76,7 @@ ParameterSearch SearchSettingsForm::getParameterSearch() void SearchSettingsForm::updateStartDateLabel() { - ui->startDateLabel->setText(startDate.toString("dd.MM.yyyy")); + ui->startDateLabel->setText(startDate.toString(QStringLiteral("dd.MM.yyyy"))); } void SearchSettingsForm::setUpdate(const bool isUpdate) @@ -92,10 +91,10 @@ void SearchSettingsForm::onStartSearchSelected(const int index) ui->choiceDateButton->setEnabled(true); ui->startDateLabel->setEnabled(true); - ui->choiceDateButton->setProperty("state", "green"); + ui->choiceDateButton->setProperty("state", QStringLiteral("green")); ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); - ui->startDateLabel->setStyleSheet("QLabel{color: #000;}"); + ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #000;}")); if (startDate.isNull()) { startDate = QDate::currentDate(); @@ -106,10 +105,10 @@ void SearchSettingsForm::onStartSearchSelected(const int index) ui->choiceDateButton->setEnabled(false); ui->startDateLabel->setEnabled(false); - ui->choiceDateButton->setProperty("state", ""); + ui->choiceDateButton->setProperty("state", QString()); ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); - ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}"); + ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #ddd;}")); } setUpdate(true); @@ -117,6 +116,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index) void SearchSettingsForm::onRegisterClicked(const bool checked) { + Q_UNUSED(checked) setUpdate(true); } diff --git a/src/widget/form/searchsettingsform.h b/src/widget/form/searchsettingsform.h index a2441c55d..dfdc59428 100644 --- a/src/widget/form/searchsettingsform.h +++ b/src/widget/form/searchsettingsform.h @@ -21,7 +21,7 @@ public: private: Ui::SearchSettingsForm *ui; QDate startDate; - bool isUpdate; + bool isUpdate{false}; void updateStartDateLabel(); void setUpdate(const bool isUpdate); diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index 23d6b2faf..4de119b06 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -33,9 +33,6 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent) settings = new SearchSettingsForm(); settings->setVisible(false); - isActiveSettings = false; - isChangedPhrase = false; - settingsButton = createButton("searchSettingsButton", "green"); upButton = createButton("searchUpButton", "green"); downButton = createButton("searchDownButton", "green"); @@ -133,12 +130,11 @@ ParameterSearch SearchForm::getAndCheckParametrSearch() void SearchForm::changedSearchPhrase(const QString& text) { - QString l = text.right(1); - if (searchPhrase == text) { return; } + QString l = text.right(1); if (!l.isEmpty() && l != " " && l[0].isSpace()) { searchLine->setText(searchPhrase); return; @@ -191,9 +187,9 @@ void SearchForm::clickedSearch() settings->setVisible(isActiveSettings); if (isActiveSettings) { - settingsButton->setProperty("state", "red"); + settingsButton->setProperty("state", QStringLiteral("red")); } else { - settingsButton->setProperty("state", "green"); + settingsButton->setProperty("state", QStringLiteral("green")); changedButtons(false); } settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); diff --git a/src/widget/searchform.h b/src/widget/searchform.h index 7690d961f..4329d1275 100644 --- a/src/widget/searchform.h +++ b/src/widget/searchform.h @@ -58,8 +58,8 @@ private: QString searchPhrase; ParameterSearch parameter; - bool isActiveSettings; - bool isChangedPhrase; + bool isActiveSettings{false}; + bool isChangedPhrase{false}; private slots: void changedSearchPhrase(const QString& text); diff --git a/src/widget/searchtypes.h b/src/widget/searchtypes.h index dfceb442f..0f1141ffb 100644 --- a/src/widget/searchtypes.h +++ b/src/widget/searchtypes.h @@ -21,31 +21,15 @@ enum class PeriodSearch { }; struct ParameterSearch { - FilterSearch filter; - PeriodSearch period; + FilterSearch filter{FilterSearch::None}; + PeriodSearch period{PeriodSearch::None}; QDate date; - bool isUpdate; - - ParameterSearch() { - filter = FilterSearch::None; - period = PeriodSearch::None; - isUpdate = false; - } + bool isUpdate{false}; bool operator ==(const ParameterSearch& other) { - if (this->filter != other.filter) { - return false; - } - - if (this->period != other.period) { - return false; - } - - if (this->date != other.date) { - return false; - } - - return true; + return filter == other.filter && + period == other.period && + date == other.date; } bool operator !=(const ParameterSearch& other) {