1
0
Fork 0

Updating the search in log feature changes as per the review comments

- Ran the format.bat on the changes
- Using ConfigColor() instead of QColor
- Implementing the search similar to notepad find(find, find next, find previous).
This commit is contained in:
Rajkumar Ananthu 2022-02-21 19:35:22 +05:30
parent 1b6289eaa4
commit 9dddf68b83
2 changed files with 46 additions and 14 deletions

View File

@ -40,8 +40,8 @@ LogView::LogView(QWidget* parent) : QTextBrowser(parent), logRedirection(NULL)
connect(Bridge::getBridge(), SIGNAL(setLogEnabled(bool)), this, SLOT(setLoggingEnabled(bool)));
connect(Bridge::getBridge(), SIGNAL(flushLog()), this, SLOT(flushLogSlot()));
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(onAnchorClicked(QUrl)));
dialogSearchInLog = new LineEditDialog(this);
dialogSearchInLog->setWindowTitle(tr("Seach For"));
dialogFindInLog = new LineEditDialog(this);
dialogFindInLog->setWindowTitle(tr("Find For"));
duint setting;
if(BridgeSettingGetUint("Misc", "Utf16LogRedirect", &setting))
@ -107,7 +107,9 @@ void LogView::setupContextMenu()
menuCopyToNotes->addAction(actionCopyToDebuggeeNotes);
actionAutoScroll->setCheckable(true);
actionAutoScroll->setChecked(autoScroll);
actionSearchInLog = setupAction(DIcon("search-for.png"), tr("Search Log"), this, SLOT(searchInLogSlot()));
actionFindInLog = setupAction(tr("Find"), this, SLOT(findInLogSlot()));
actionFindNext = setupAction(tr("Find Next Occurance"), this, SLOT(findNextInLogSlot()));;
actionFindPrevious = setupAction(tr("Find Previous Occurance"), this, SLOT(findPreviousInLogSlot()));
refreshShortcutsSlot();
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(refreshShortcutsSlot()));
@ -119,7 +121,9 @@ void LogView::refreshShortcutsSlot()
actionCopy->setShortcut(ConfigShortcut("ActionCopy"));
actionToggleLogging->setShortcut(ConfigShortcut("ActionToggleLogging"));
actionRedirectLog->setShortcut(ConfigShortcut("ActionRedirectLog"));
actionSearchInLog->setShortcut(ConfigShortcut("ActionFind"));
actionFindInLog->setShortcut(ConfigShortcut("ActionFind"));
actionFindNext->setShortcut(ConfigShortcut("ActionGotoNext"));
actionFindPrevious->setShortcut(ConfigShortcut("ActionGotoPrevious"));
}
void LogView::contextMenuEvent(QContextMenuEvent* event)
@ -140,7 +144,9 @@ void LogView::contextMenuEvent(QContextMenuEvent* event)
wMenu.addAction(actionToggleLogging);
actionAutoScroll->setChecked(autoScroll);
wMenu.addAction(actionAutoScroll);
wMenu.addAction(actionSearchInLog);
wMenu.addAction(actionFindInLog);
wMenu.addAction(actionFindNext);
wMenu.addAction(actionFindPrevious);
if(logRedirection == NULL)
actionRedirectLog->setText(tr("&Redirect Log..."));
else
@ -420,24 +426,45 @@ void LogView::copyToDebuggeeNotes()
emit Bridge::getBridge()->setDebuggeeNotes(Notes);
}
void LogView::searchInLogSlot() {
dialogSearchInLog->show();
void LogView::findNextInLogSlot()
{
find(QRegExp(lastFindText));
}
if (dialogSearchInLog->exec() == QDialog::Accepted) {
void LogView::findPreviousInLogSlot()
{
find(QRegExp(lastFindText), QTextDocument::FindBackward);
}
void LogView::findInLogSlot()
{
dialogFindInLog->show();
if(dialogFindInLog->exec() == QDialog::Accepted)
{
QList<QTextEdit::ExtraSelection> extraSelections;
QColor highlight = QColor(Qt::blue);
QColor highlight = ConfigColor("SearchListViewHighlightColor");
QColor background = ConfigColor("SearchListViewHighlightBackgroundColor");
// capturing the current location, so that we can reset it once capturing all the
// extra selections
QTextCursor resetCursorLoc = textCursor();
moveCursor(QTextCursor::Start);
// finding all occurances matching the regex given from start
while(find(QRegExp(dialogSearchInLog->editText))) {
while(find(QRegExp(dialogFindInLog->editText)))
{
QTextEdit::ExtraSelection extra;
extra.format.setBackground(highlight);
extra.format.setForeground(highlight);
extra.format.setBackground(background);
extra.cursor = textCursor();
extraSelections.append(extra);
}
// highlighting all those selections
setExtraSelections(extraSelections);
setTextCursor(resetCursorLoc); // resetting the cursor location
find(QRegExp(dialogFindInLog->editText));
lastFindText = dialogFindInLog->editText;
}
}

View File

@ -22,7 +22,9 @@ public slots:
void redirectLogSlot();
void setLoggingEnabled(bool enabled);
void autoScrollSlot();
void searchInLogSlot();
void findInLogSlot();
void findNextInLogSlot();
void findPreviousInLogSlot();
void copyToGlobalNotes();
void copyToDebuggeeNotes();
void pasteSlot();
@ -53,11 +55,14 @@ private:
QMenu* menuCopyToNotes;
QAction* actionCopyToGlobalNotes;
QAction* actionCopyToDebuggeeNotes;
QAction* actionSearchInLog;
LineEditDialog* dialogSearchInLog;
QAction* actionFindInLog;
QAction* actionFindNext;
QAction* actionFindPrevious;
LineEditDialog* dialogFindInLog;
FILE* logRedirection;
QString logBuffer;
QTimer* flushTimer;
bool flushLog;
QString lastFindText;
};