Browse Source

revert(chatlog): "simple edit code"

This reverts commit b807998fe9.
reviewable/pr6070/r2
Anthony Bilinski 6 years ago
parent
commit
3f36b31f8b
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 18
      src/chatlog/chatlog.cpp
  2. 5
      src/model/chathistory.cpp
  3. 2
      src/model/ichatlog.h
  4. 34
      src/widget/form/genericchatform.cpp
  5. 8
      src/widget/form/loadhistorydialog.cpp
  6. 10
      src/widget/form/loadhistorydialog.h
  7. 3
      src/widget/form/searchsettingsform.cpp

18
src/chatlog/chatlog.cpp

@ -171,9 +171,8 @@ void ChatLog::updateSceneRect()
void ChatLog::layout(int start, int end, qreal width) void ChatLog::layout(int start, int end, qreal width)
{ {
if (lines.empty()) { if (lines.empty())
return; return;
}
qreal h = 0.0; qreal h = 0.0;
@ -316,9 +315,8 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
// Much faster than QGraphicsScene::itemAt()! // Much faster than QGraphicsScene::itemAt()!
ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
{ {
if (lines.empty()) { if (lines.empty())
return nullptr; return nullptr;
}
auto itr = auto itr =
std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom); std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom);
@ -461,9 +459,8 @@ void ChatLog::scrollToBottom()
void ChatLog::startResizeWorker() void ChatLog::startResizeWorker()
{ {
if (lines.empty()) { if (lines.empty())
return; return;
}
// (re)start the worker // (re)start the worker
if (!workerTimer->isActive()) { if (!workerTimer->isActive()) {
@ -664,9 +661,8 @@ void ChatLog::scrollToLine(ChatLine::Ptr line)
void ChatLog::selectAll() void ChatLog::selectAll()
{ {
if (lines.empty()) { if (lines.empty())
return; return;
}
clearSelection(); clearSelection();
@ -728,9 +724,8 @@ void ChatLog::forceRelayout()
void ChatLog::checkVisibility(bool causedWheelEvent) void ChatLog::checkVisibility(bool causedWheelEvent)
{ {
if (lines.empty()) { if (lines.empty())
return; return;
}
// find first visible line // find first visible line
auto lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), auto lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(),
@ -829,9 +824,8 @@ void ChatLog::updateTypingNotification()
qreal posY = 0.0; qreal posY = 0.0;
if (!lines.empty()) { if (!lines.empty())
posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing; posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing;
}
notification->layout(useableWidth(), QPointF(0.0, posY)); notification->layout(useableWidth(), QPointF(0.0, posY));
} }

5
src/model/chathistory.cpp

@ -94,9 +94,10 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
// NOTE: this has to be done _after_ sending all sent messages since initial // NOTE: this has to be done _after_ sending all sent messages since initial
// state of the message has to be marked according to our dispatch state // state of the message has to be marked according to our dispatch state
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < DEF_NUM_MSG_TO_LOAD constexpr auto defaultNumMessagesToLoad = 100;
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < defaultNumMessagesToLoad
? ChatLogIdx(0) ? ChatLogIdx(0)
: sessionChatLog.getFirstIdx() - DEF_NUM_MSG_TO_LOAD; : sessionChatLog.getFirstIdx() - defaultNumMessagesToLoad;
if (canUseHistory()) { if (canUseHistory()) {
loadHistoryIntoSessionChatLog(firstChatLogIdx); loadHistoryIntoSessionChatLog(firstChatLogIdx);

2
src/model/ichatlog.h

@ -35,8 +35,6 @@
#include <cassert> #include <cassert>
static const auto DEF_NUM_MSG_TO_LOAD = 100;
using ChatLogIdx = using ChatLogIdx =
NamedType<size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable>; NamedType<size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable>;
Q_DECLARE_METATYPE(ChatLogIdx); Q_DECLARE_METATYPE(ChatLogIdx);

34
src/widget/form/genericchatform.cpp

@ -386,7 +386,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog,
connect(contact, &Contact::displayedNameChanged, this, &GenericChatForm::setName); connect(contact, &Contact::displayedNameChanged, this, &GenericChatForm::setName);
auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx(); auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx();
auto firstChatLogIdx = (chatLogIdxRange < DEF_NUM_MSG_TO_LOAD) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - DEF_NUM_MSG_TO_LOAD; auto firstChatLogIdx = (chatLogIdxRange < 100) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - 100;
renderMessages(firstChatLogIdx, chatLog.getNextIdx()); renderMessages(firstChatLogIdx, chatLog.getNextIdx());
@ -665,10 +665,10 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
{ {
auto end = ChatLogIdx(0); auto end = ChatLogIdx(0);
if (time.isNull()) { if (time.isNull()) {
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { if (messages.size() + 100 >= maxMessages) {
end = ChatLogIdx(messages.rbegin()->first.get() - DEF_NUM_MSG_TO_LOAD); end = ChatLogIdx(messages.rbegin()->first.get() - 100);
chatWidget->removeLasts(DEF_NUM_MSG_TO_LOAD); chatWidget->removeLasts(100);
removeLastsMessages(DEF_NUM_MSG_TO_LOAD); removeLastsMessages(100);
} else { } else {
end = messages.begin()->first; end = messages.begin()->first;
} }
@ -677,8 +677,8 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
} }
auto begin = ChatLogIdx(0); auto begin = ChatLogIdx(0);
if (end.get() > DEF_NUM_MSG_TO_LOAD) { if (end.get() > 100) {
begin = ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD); begin = ChatLogIdx(end.get() - 100);
} }
renderMessages(begin, end); renderMessages(begin, end);
@ -688,10 +688,10 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time)
{ {
auto begin = ChatLogIdx(0); auto begin = ChatLogIdx(0);
if (time.isNull()) { if (time.isNull()) {
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { if (messages.size() + 100 >= maxMessages) {
begin = ChatLogIdx(messages.rbegin()->first.get() + DEF_NUM_MSG_TO_LOAD); begin = ChatLogIdx(messages.rbegin()->first.get() + 100);
chatWidget->removeFirsts(DEF_NUM_MSG_TO_LOAD); chatWidget->removeFirsts(100);
removeFirstsMessages(DEF_NUM_MSG_TO_LOAD); removeFirstsMessages(100);
} else { } else {
begin = messages.rbegin()->first; begin = messages.rbegin()->first;
} }
@ -700,9 +700,9 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time)
begin = firstItemAfterDate(time.date(), chatLog); begin = firstItemAfterDate(time.date(), chatLog);
} }
int add = DEF_NUM_MSG_TO_LOAD; int add = 100;
if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { if (begin.get() + 100 > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + DEF_NUM_MSG_TO_LOAD); add = chatLog.getNextIdx().get() - (begin.get() + 100);
} }
auto end = ChatLogIdx(begin.get() + add); auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end); renderMessages(begin, end);
@ -719,8 +719,8 @@ void GenericChatForm::removeFirstsMessages(const int num)
void GenericChatForm::removeLastsMessages(const int num) void GenericChatForm::removeLastsMessages(const int num)
{ {
if (messages.size() > num) { if (messages.size() > 100) {
messages.erase(std::next(messages.end(), -num), messages.end()); messages.erase(std::next(messages.end(), -100), messages.end());
} else { } else {
messages.clear(); messages.clear();
} }
@ -1076,7 +1076,7 @@ void GenericChatForm::goToCurrentDate()
chatWidget->clear(); chatWidget->clear();
messages.clear(); messages.clear();
auto end = ChatLogIdx(chatLog.size() - 1); auto end = ChatLogIdx(chatLog.size() - 1);
auto begin = end.get() > DEF_NUM_MSG_TO_LOAD ? ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD) : ChatLogIdx(0); auto begin = end.get() > 100 ? ChatLogIdx(end.get() - 100) : ChatLogIdx(0);
renderMessages(begin, end); renderMessages(begin, end);
} }

8
src/widget/form/loadhistorydialog.cpp

@ -38,15 +38,11 @@ LoadHistoryDialog::LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent)
&LoadHistoryDialog::highlightDates); &LoadHistoryDialog::highlightDates);
} }
LoadHistoryDialog::LoadHistoryDialog(Mode mode, QWidget* parent) LoadHistoryDialog::LoadHistoryDialog(QWidget* parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::LoadHistoryDialog) , ui(new Ui::LoadHistoryDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
if (mode == Mode::search) {
enableSearchMode();
}
} }
LoadHistoryDialog::~LoadHistoryDialog() LoadHistoryDialog::~LoadHistoryDialog()
@ -75,7 +71,7 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType()
return LoadType::to; return LoadType::to;
} }
void LoadHistoryDialog::enableSearchMode() void LoadHistoryDialog::turnSearchMode()
{ {
setWindowTitle(tr("Select Date Dialog")); setWindowTitle(tr("Select Date Dialog"));
ui->fromLabel->setText(tr("Select a date")); ui->fromLabel->setText(tr("Select a date"));

10
src/widget/form/loadhistorydialog.h

@ -39,24 +39,18 @@ public:
to to
}; };
enum Mode {
common,
search
};
explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr); explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr);
explicit LoadHistoryDialog(Mode mode, QWidget* parent = nullptr); explicit LoadHistoryDialog(QWidget* parent = nullptr);
~LoadHistoryDialog(); ~LoadHistoryDialog();
QDateTime getFromDate(); QDateTime getFromDate();
LoadType getLoadType(); LoadType getLoadType();
void turnSearchMode();
public slots: public slots:
void highlightDates(int year, int month); void highlightDates(int year, int month);
private: private:
void enableSearchMode();
Ui::LoadHistoryDialog* ui; Ui::LoadHistoryDialog* ui;
const IChatLog* chatLog; const IChatLog* chatLog;
}; };

3
src/widget/form/searchsettingsform.cpp

@ -161,7 +161,8 @@ void SearchSettingsForm::onRegularClicked(const bool checked)
void SearchSettingsForm::onChoiceDate() void SearchSettingsForm::onChoiceDate()
{ {
LoadHistoryDialog dlg(LoadHistoryDialog::search); LoadHistoryDialog dlg;
dlg.turnSearchMode();
if (dlg.exec()) { if (dlg.exec()) {
startTime = dlg.getFromDate(); startTime = dlg.getFromDate();
updateStartDateLabel(); updateStartDateLabel();

Loading…
Cancel
Save