From 11044170227a0c380d08defaef3f5e4223632163 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 5 Apr 2020 01:19:05 -0700 Subject: [PATCH] revert(chatlog): "edit load history in search" This reverts commit 8c4b1e00a128b739904ed60543132b34817f0ba5. --- src/chatlog/content/text.cpp | 23 ++++--------- src/chatlog/content/text.h | 4 --- src/persistence/history.cpp | 14 ++++---- src/widget/form/genericchatform.cpp | 45 ++++++++++---------------- src/widget/form/genericchatform.h | 2 -- src/widget/form/loadhistorydialog.cpp | 12 ++++--- src/widget/form/loadhistorydialog.h | 3 +- src/widget/form/loadhistorydialog.ui | 2 +- src/widget/form/searchsettingsform.cpp | 13 ++++---- src/widget/form/searchsettingsform.h | 2 +- src/widget/searchtypes.h | 4 +-- 11 files changed, 51 insertions(+), 73 deletions(-) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index ab7e56d70..dd9558621 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -66,11 +66,9 @@ void Text::selectText(const QString& txt, const std::pair& point) return; } - selectCursor = doc->find(txt, point.first); - selectPoint = point; + auto cursor = doc->find(txt, point.first); - regenerate(); - update(); + selectText(cursor, point); } void Text::selectText(const QRegularExpression &exp, const std::pair& point) @@ -81,20 +79,14 @@ void Text::selectText(const QRegularExpression &exp, const std::pair& return; } - selectCursor = doc->find(exp, point.first); - selectPoint = point; + auto cursor = doc->find(exp, point.first); - regenerate(); - update(); + selectText(cursor, point); } void Text::deselectText() { dirty = true; - - selectCursor = QTextCursor(); - selectPoint = {0, 0}; - regenerate(); update(); } @@ -363,10 +355,6 @@ void Text::regenerate() dirty = false; } - if (!selectCursor.isNull()) { - selectText(selectCursor, selectPoint); - } - // if we are not visible -> free mem if (!keepInMemory) freeResources(); @@ -474,6 +462,9 @@ void Text::selectText(QTextCursor& cursor, const std::pair& point) QTextCharFormat format; format.setBackground(QBrush(Style::getColor(Style::SearchHighlighted))); cursor.mergeCharFormat(format); + + regenerate(); + update(); } } diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index 624135fbf..397887964 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -23,7 +23,6 @@ #include "src/widget/style.h" #include -#include class QTextDocument; @@ -110,7 +109,4 @@ private: TextType textType; QColor color; QColor customColor; - - QTextCursor selectCursor; - std::pair selectPoint{0, 0}; }; diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index fd2643259..22a8faf69 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -1139,14 +1139,14 @@ QDateTime History::getDateWhereFindPhrase(const ToxPk& friendPk, const QDateTime break; } - QDateTime time = from; + QDateTime date = from; - if (!time.isValid()) { - time = QDateTime::currentDateTime(); + if (!date.isValid()) { + date = QDateTime::currentDateTime(); } if (parameter.period == PeriodSearch::AfterDate || parameter.period == PeriodSearch::BeforeDate) { - time = parameter.time; + date = QDateTime(parameter.date); } QString period; @@ -1156,15 +1156,15 @@ QDateTime History::getDateWhereFindPhrase(const ToxPk& friendPk, const QDateTime break; case PeriodSearch::AfterDate: period = QStringLiteral("AND timestamp > '%1' ORDER BY timestamp ASC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; case PeriodSearch::BeforeDate: period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; default: period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; } diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 393c0319c..42de7d468 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -36,7 +36,7 @@ #include "src/widget/contentlayout.h" #include "src/widget/emoticonswidget.h" #include "src/widget/form/chatform.h" -#include "src/widget/gui.h" +#include "src/widget/form/loadhistorydialog.h" #include "src/widget/maskablepixmapwidget.h" #include "src/widget/searchform.h" #include "src/widget/style.h" @@ -676,23 +676,6 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const return QDateTime(); } -void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type) -{ - chatWidget->clear(); - messages.clear(); - - auto begin = firstItemAfterDate(time.date(), chatLog); - auto end = ChatLogIdx(begin.get() + 1); - - renderMessages(begin, end); - - if (type == LoadHistoryDialog::from) { - loadHistoryUpper(); - } else { - loadHistoryLower(); - } -} - void GenericChatForm::disableSearchText() { @@ -839,10 +822,22 @@ void GenericChatForm::onLoadHistory() { LoadHistoryDialog dlg(&chatLog); if (dlg.exec()) { + chatWidget->clear(); + messages.clear(); + QDateTime time = dlg.getFromDate(); auto type = dlg.getLoadType(); - loadHistory(time, type); + auto begin = firstItemAfterDate(dlg.getFromDate().date(), chatLog); + auto end = ChatLogIdx(begin.get() + 1); + + renderMessages(begin, end); + + if (type == LoadHistoryDialog::from) { + loadHistoryUpper(); + } else { + loadHistoryLower(); + } } } @@ -889,12 +884,6 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch { disableSearchText(); - if (!parameter.time.isNull()) { - LoadHistoryDialog::LoadType type = (parameter.period == PeriodSearch::BeforeDate) - ? LoadHistoryDialog::to : LoadHistoryDialog::from; - loadHistory(parameter.time, type); - } - bool bForwardSearch = false; switch (parameter.period) { case PeriodSearch::WithTheFirst: { @@ -912,13 +901,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch } case PeriodSearch::AfterDate: { bForwardSearch = true; - searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog); searchPos.numMatches = 0; break; } case PeriodSearch::BeforeDate: { bForwardSearch = false; - searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog); searchPos.numMatches = 0; break; } @@ -1066,7 +1055,7 @@ void GenericChatForm::loadHistoryLower() void GenericChatForm::loadHistoryUpper() { - auto begin = messages.rbegin()->first; + auto begin = messages.end()->first; int add = 100; if (begin.get() + 100 > chatLog.getNextIdx().get()) { diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 7f5598c42..be29119d8 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -22,7 +22,6 @@ #include "src/chatlog/chatmessage.h" #include "src/core/toxpk.h" #include "src/model/ichatlog.h" -#include "src/widget/form/loadhistorydialog.h" #include "src/widget/searchtypes.h" #include @@ -127,7 +126,6 @@ private: void retranslateUi(); void addSystemDateMessage(const QDate& date); QDateTime getTime(const ChatLine::Ptr& chatLine) const; - void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type); void renderItem(const ChatLogItem &item, bool hideName, bool colorizeNames, ChatMessage::Ptr &chatMessage); void renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp, ChatMessage::Ptr &chatMessage); diff --git a/src/widget/form/loadhistorydialog.cpp b/src/widget/form/loadhistorydialog.cpp index f894be7cf..151979b29 100644 --- a/src/widget/form/loadhistorydialog.cpp +++ b/src/widget/form/loadhistorydialog.cpp @@ -75,12 +75,14 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType() return LoadType::to; } -void LoadHistoryDialog::turnSearchMode() +void LoadHistoryDialog::setTitle(const QString& title) { - setWindowTitle(tr("Select date dialog")); - ui->fromLabel->setText(tr("Select a date")); - ui->loadTypeComboBox->setVisible(false); - ui->infoLabel->setVisible(false); + setWindowTitle(title); +} + +void LoadHistoryDialog::setInfoLabel(const QString& info) +{ + ui->fromLabel->setText(info); } void LoadHistoryDialog::highlightDates(int year, int month) diff --git a/src/widget/form/loadhistorydialog.h b/src/widget/form/loadhistorydialog.h index 1bce0d06f..00a2cfc4a 100644 --- a/src/widget/form/loadhistorydialog.h +++ b/src/widget/form/loadhistorydialog.h @@ -44,7 +44,8 @@ public: QDateTime getFromDate(); LoadType getLoadType(); - void turnSearchMode(); + void setTitle(const QString& title); + void setInfoLabel(const QString& info); public slots: void highlightDates(int year, int month); diff --git a/src/widget/form/loadhistorydialog.ui b/src/widget/form/loadhistorydialog.ui index 202ffa80b..ef3a8bda8 100644 --- a/src/widget/form/loadhistorydialog.ui +++ b/src/widget/form/loadhistorydialog.ui @@ -41,7 +41,7 @@ - + (about 100 messages are loaded) diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index 72dd4d882..49863cc58 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -90,7 +90,7 @@ ParameterSearch SearchSettingsForm::getParameterSearch() break; } - ps.time = startTime; + ps.date = startDate; ps.isUpdate = isUpdate; isUpdate = false; @@ -105,7 +105,7 @@ void SearchSettingsForm::reloadTheme() void SearchSettingsForm::updateStartDateLabel() { - ui->startDateLabel->setText(startTime.toString(Settings::getInstance().getDateFormat())); + ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat())); } void SearchSettingsForm::setUpdate(const bool isUpdate) @@ -123,8 +123,8 @@ void SearchSettingsForm::onStartSearchSelected(const int index) ui->choiceDateButton->setProperty("state", QStringLiteral("green")); ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); - if (startTime.isNull()) { - startTime = QDateTime::currentDateTime(); + if (startDate.isNull()) { + startDate = QDate::currentDate(); updateStartDateLabel(); } @@ -166,9 +166,10 @@ void SearchSettingsForm::onRegularClicked(const bool checked) void SearchSettingsForm::onChoiceDate() { LoadHistoryDialog dlg; - dlg.turnSearchMode(); + dlg.setTitle(tr("Select Date Dialog")); + dlg.setInfoLabel(tr("Select a date")); if (dlg.exec()) { - startTime = dlg.getFromDate(); + startDate = dlg.getFromDate().date(); updateStartDateLabel(); } diff --git a/src/widget/form/searchsettingsform.h b/src/widget/form/searchsettingsform.h index ab4942c84..5f4b7f0a2 100644 --- a/src/widget/form/searchsettingsform.h +++ b/src/widget/form/searchsettingsform.h @@ -39,7 +39,7 @@ public: private: Ui::SearchSettingsForm *ui; - QDateTime startTime; + QDate startDate; bool isUpdate{false}; void updateStartDateLabel(); diff --git a/src/widget/searchtypes.h b/src/widget/searchtypes.h index c4f554a62..da2d9dcbe 100644 --- a/src/widget/searchtypes.h +++ b/src/widget/searchtypes.h @@ -47,13 +47,13 @@ enum class SearchDirection { struct ParameterSearch { FilterSearch filter{FilterSearch::None}; PeriodSearch period{PeriodSearch::None}; - QDateTime time; + QDate date; bool isUpdate{false}; bool operator ==(const ParameterSearch& other) { return filter == other.filter && period == other.period && - time == other.time; + date == other.date; } bool operator !=(const ParameterSearch& other) {