diff --git a/src/searchdialog.cpp b/src/searchdialog.cpp index 1d0da1b0..8119a230 100644 --- a/src/searchdialog.cpp +++ b/src/searchdialog.cpp @@ -29,10 +29,13 @@ #include #include - +/** + * @brief Constructor for SearchDialog. + * @param parent Parent widget. + */ SearchDialog::SearchDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::SearchDialog) + QDialog(parent), + ui(new Ui::SearchDialog) { ui->setupUi(this); @@ -46,7 +49,7 @@ SearchDialog::SearchDialog(QWidget *parent) : lineEdits->append(ui->lineEditText); table = nullptr; - // at start we want to know if single step search or "fill search table mode" is active ! + // at start we want to know if single step search or "fill search table mode" is active ! bool checked = QDltSettingsManager::getInstance()->value("other/search/checkBoxSearchIndex", bool(true)).toBool(); ui->checkBoxSearchIndex->setChecked(checked); @@ -64,88 +67,195 @@ SearchDialog::SearchDialog(QWidget *parent) : updateColorbutton(); } +/** + * @brief Destructor for SearchDialog. + */ SearchDialog::~SearchDialog() { clearCacheHistory(); delete ui; } +/** + * @brief Selects and focuses the search text field. + */ void SearchDialog::selectText(){ui->lineEditText->setFocus();ui->lineEditText->selectAll();} + +/** + * @brief Sets the header checkbox state. + * @param header True to check, false to uncheck. + */ void SearchDialog::setHeader(bool header) { ui->checkBoxHeader->setCheckState(header?Qt::Checked:Qt::Unchecked);} + +/** + * @brief Sets the payload checkbox state. + * @param payload True to check, false to uncheck. + */ void SearchDialog::setPayload(bool payload) { ui->checkBoxPayload->setCheckState(payload?Qt::Checked:Qt::Unchecked);} + +/** + * @brief Sets the case sensitivity checkbox state. + * @param caseSensitive True to check, false to uncheck. + */ void SearchDialog::setCaseSensitive(bool caseSensitive) { ui->checkBoxCaseSensitive->setCheckState(caseSensitive?Qt::Checked:Qt::Unchecked);} + +/** + * @brief Sets the regular expression checkbox state. + * @param regExp True to check, false to uncheck. + */ void SearchDialog::setRegExp(bool regExp) { ui->checkBoxRegExp->setCheckState(regExp?Qt::Checked:Qt::Unchecked);} -void SearchDialog::setNextClicked(bool next){nextClicked = next;} -void SearchDialog::setMatch(bool matched){match=matched;} +/** + * @brief Sets the search direction (next/previous). + * @param next True for next, false for previous. + */ +void SearchDialog::setNextClicked(bool next){nextClicked = next;} +/** + * @brief Sets the match flag. + * @param matched True if matched. + */ +void SearchDialog::setMatch(bool matched){match=matched;} +/** + * @brief Sets the once clicked flag. + * @param clicked True if clicked once. + */ void SearchDialog::setOnceClicked(bool clicked){onceClicked=clicked;} + +/** + * @brief Appends a QLineEdit to the list of line edits. + * @param lineEdit Pointer to QLineEdit. + */ void SearchDialog::appendLineEdit(QLineEdit *lineEdit){ lineEdits->append(lineEdit);} +/** + * @brief Gets the search text. + * @return Search text as QString. + */ QString SearchDialog::getText() { return ui->lineEditText->text(); } +/** + * @brief Aborts the ongoing search. + */ void SearchDialog::abortSearch() { isSearchCancelled = true; } +/** + * @brief Checks if header search is enabled. + * @return True if enabled. + */ bool SearchDialog::getHeader() { return (ui->checkBoxHeader->checkState() == Qt::Checked); } +/** + * @brief Checks if payload search is enabled. + * @return True if enabled. + */ bool SearchDialog::getPayload() { return (ui->checkBoxPayload->checkState() == Qt::Checked); } +/** + * @brief Checks if regular expression search is enabled. + * @return True if enabled. + */ bool SearchDialog::getRegExp() { return (ui->checkBoxRegExp->checkState() == Qt::Checked); } +/** + * @brief Gets the search direction. + * @return True if next, false if previous. + */ bool SearchDialog::getNextClicked(){return nextClicked;} +/** + * @brief Gets the once clicked flag + * @return True if clicked. + */ bool SearchDialog::getOnceClicked(){return onceClicked;} +/** + * @brief Gets the APID text. + * @return APID as QString. + */ QString SearchDialog::getApIDText(){ return ui->apIdlineEdit->text();} + +/** + * @brief Gets the CTID text. + * @return CTID as QString. + */ QString SearchDialog::getCtIDText(){ return ui->ctIdlineEdit->text();} +/** + * @brief Gets the start timestamp text. + * @return Start timestamp as QString. + */ QString SearchDialog::getTimeStampStart() { //qDebug() << "content of start time" << ui->timeStartlineEdit->text()<< __LINE__; return ui->timeStartlineEdit->text(); } + +/** + * @brief Gets the end timestamp text. + * @return End timestamp as QString. + */ QString SearchDialog::getTimeStampEnd() { //qDebug() << "content of end time" << ui->timeEndlineEdit->text() << __LINE__; return ui->timeEndlineEdit->text(); } +/** + * @brief Checks if case sensitive search is enabled. + * @return True if enabled. + */ bool SearchDialog::getCaseSensitive() { //qDebug() << "getCaseSensitive is" << ui->checkBoxCaseSensitive->checkState() << __LINE__; return (ui->checkBoxCaseSensitive->checkState() == Qt::Checked); } +/** + * @brief Checks if search to index is enabled. + * @return True if enabled. + */ bool SearchDialog::searchtoIndex() { //qDebug() << "searchtoIndex is" << ui->checkBoxSearchIndex->checkState() << __LINE__; return (ui->checkBoxSearchIndex->checkState() == Qt::Checked); } - +/** + * @brief Checks if search should start from beginning. + * @return True if enabled. + */ bool SearchDialog::getSearchFromBeginning() { return (ui->radioButtonPosBeginning->isChecked()); } +/** + * @brief Sets the start line for search. + * @param start Line number. + */ void SearchDialog::setStartLine(long int start) { - startLine=start; + startLine=start; } - +/** + * @brief Sets the color of the search box based on result. + * @param lineEdit Pointer to QLineEdit. + * @param result Result code. + */ void SearchDialog::setSearchColour(QLineEdit *lineEdit,int result) { QPalette palette = lineEdit->palette(); @@ -176,6 +286,10 @@ void SearchDialog::setSearchColour(QLineEdit *lineEdit,int result) } } +/** + * @brief Focuses the specified row in the table. + * @param searchLine Row number. + */ void SearchDialog::focusRow(long int searchLine) { TableModel *model = qobject_cast(table->model()); @@ -192,6 +306,10 @@ void SearchDialog::focusRow(long int searchLine) model->modelChanged(); } +/** + * @brief Main function to perform search. + * @return Result code. + */ int SearchDialog::find() { isSearchCancelled = false; @@ -210,7 +328,7 @@ int SearchDialog::find() return 0; } - if( ( (match == true) || ( getSearchFromBeginning() == false )) && false == searchtoIndex() ) + if( ( (match == true) || ( getSearchFromBeginning() == false )) && false == searchtoIndex() ) { // single step search QModelIndexList list = table->selectionModel()->selection().indexes(); @@ -228,10 +346,10 @@ int SearchDialog::find() setStartLine(index.row()); } } - else - { - focusRow(-1); - } + else + { + focusRow(-1); + } if ( true == getSearchFromBeginning() ) @@ -241,19 +359,19 @@ int SearchDialog::find() else { if (table->selectionModel() != nullptr ) - { - { - if ( false == table->selectionModel()->selectedIndexes().isEmpty() ) + { { - if (table->selectionModel()->selectedIndexes().first().row() > -1) - { - lStartLine = table->selectionModel()->selectedIndexes().first().row(); - setStartLine( lStartLine ); - } - } - } - } - qDebug() << "Search starting at line" << startLine; + if ( false == table->selectionModel()->selectedIndexes().isEmpty() ) + { + if (table->selectionModel()->selectedIndexes().first().row() > -1) + { + lStartLine = table->selectionModel()->selectedIndexes().first().row(); + setStartLine( lStartLine ); + } + } + } + } + qDebug() << "Search starting at line" << startLine; } searchBorder = startLine; @@ -277,7 +395,7 @@ int SearchDialog::find() { if ( false == fSilentMode) { - QMessageBox::warning(0, QString("Search"), QString("Invalid regular expression!")); + QMessageBox::warning(0, QString("Search"), QString("Invalid regular expression!")); } emit searchProgressChanged(false); return 1; @@ -289,7 +407,7 @@ int SearchDialog::find() searchTextRegExpression.setPatternOptions(static_cast(options)); } - //check timestamp search pattern + //check timestamp search pattern TimeStampStarttime = getTimeStampStart(); TimeStampStoptime = getTimeStampEnd(); @@ -298,24 +416,24 @@ int SearchDialog::find() dTimeStampStart = TimeStampStarttime.toDouble(); dTimeStampStop = TimeStampStoptime.toDouble(); if( (dTimeStampStop - dTimeStampStart) >= 0 ) - { - //qDebug() << "Timestamp search enabled" << dTimeStampStart << dTimeStampStop << __LINE__; - is_TimeStampSearchSelected = true; - } + { + //qDebug() << "Timestamp search enabled" << dTimeStampStart << dTimeStampStop << __LINE__; + is_TimeStampSearchSelected = true; + } else { - qDebug() << "Invalid timestamp range" << dTimeStampStart << dTimeStampStop << __LINE__; - is_TimeStampSearchSelected = false; - if ( false == fSilentMode) - { - QMessageBox::warning(0, QString("Search"), QString("Invalid timestamp range !")); - } - emit searchProgressChanged(false); - return 1; + qDebug() << "Invalid timestamp range" << dTimeStampStart << dTimeStampStop << __LINE__; + is_TimeStampSearchSelected = false; + if ( false == fSilentMode) + { + QMessageBox::warning(0, QString("Search"), QString("Invalid timestamp range !")); + } + emit searchProgressChanged(false); + return 1; } } - //check APID and CTID search + //check APID and CTID search stApid = getApIDText(); stCtid = getCtIDText(); if( stApid.size() > 0 || stCtid.size() > 0 ) // so we need to consider what is given here @@ -325,7 +443,7 @@ int SearchDialog::find() qDebug() << "Given APID or CTID exceeds limit !"; if ( false == fSilentMode) { - QMessageBox::warning(0, QString("Search"), QString("Given APID or CTID exceeds limit !")); + QMessageBox::warning(0, QString("Search"), QString("Given APID or CTID exceeds limit !")); } emit searchProgressChanged(false); return 2; @@ -334,7 +452,7 @@ int SearchDialog::find() } else { - fIs_APID_CTID_requested = false; + fIs_APID_CTID_requested = false; } findMessages(startLine,searchBorder,searchTextRegExpression); @@ -361,6 +479,12 @@ int SearchDialog::find() } +/** + * @brief Iterates through messages and finds matches. + * @param searchLine Start line. + * @param searchBorder Border line. + * @param searchTextRegExp Regular expression for search. + */ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QRegularExpression &searchTextRegExp) { @@ -415,7 +539,7 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg } } - // Update progress every 0.5% + // Update progress every 0.5% if(searchLine%1000 == 0) { QApplication::processEvents(); @@ -453,6 +577,11 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg stoptime(); } +/** + * @brief Handles actions when a matching line is found. + * @param searchLine Line number. + * @return True to break search, false to continue. + */ bool SearchDialog::foundLine(long int searchLine) { match = true; @@ -472,6 +601,9 @@ bool SearchDialog::foundLine(long int searchLine) return false;//don't break search here } +/** + * @brief Slot for Next button click. + */ void SearchDialog::on_pushButtonNext_clicked() // connected to main window line 424 { /* For every new search, start payLoad and EndpayLoad will be different and hence member variable storing previous found @@ -480,20 +612,26 @@ void SearchDialog::on_pushButtonNext_clicked() // connected to main window line int result = find(); for(int i=0; isize();i++) { - setSearchColour(lineEdits->at(i),result); + setSearchColour(lineEdits->at(i),result); } } +/** + * @brief Slot for Previous button click. + */ void SearchDialog::on_pushButtonPrevious_clicked() { setNextClicked(false); int result = find(); for(int i=0; isize();i++) { - setSearchColour(lineEdits->at(i),result); + setSearchColour(lineEdits->at(i),result); } } +/** + * @brief Slot for Find Next action. + */ void SearchDialog::findNextClicked() { setNextClicked(true); @@ -501,45 +639,60 @@ void SearchDialog::findNextClicked() int result = find(); for(int i=0; isize();i++) { - setSearchColour(lineEdits->at(i),result); + setSearchColour(lineEdits->at(i),result); } } +/** + * @brief Slot for Find Previous action. + */ void SearchDialog::findPreviousClicked() { setNextClicked(false); int result = find(); for(int i=0; isize();i++){ - setSearchColour(lineEdits->at(i),result); + setSearchColour(lineEdits->at(i),result); } } +/** + * @brief Slot for text edited in main search box. + * @param newText New text. + */ void SearchDialog::on_lineEditText_textEdited(QString newText) { - { - // block signal so that it does not trigger a setText back on lineEdits->at(0)! - QSignalBlocker signalBlocker(lineEdits->at(1)); - lineEdits->at(1)->setText(newText); - } - for(int i=0; isize();i++){ - if(lineEdits->at(0)->text().isEmpty()) - setSearchColour(lineEdits->at(i),1); - } + { + // block signal so that it does not trigger a setText back on lineEdits->at(0)! + QSignalBlocker signalBlocker(lineEdits->at(1)); + lineEdits->at(1)->setText(newText); + } + for(int i=0; isize();i++){ + if(lineEdits->at(0)->text().isEmpty()) + setSearchColour(lineEdits->at(i),1); + } } + +/** + * @brief Slot for text edited from toolbar. + * @param newText New text. + */ void SearchDialog::textEditedFromToolbar(QString newText) { - { - // block signal so that it does not trigger a setText back on lineEdits->at(1)! - QSignalBlocker signalBlocker(lineEdits->at(0)); - lineEdits->at(0)->setText(newText); - } - for(int i=0; isize();i++){ - if(lineEdits->at(0)->text().isEmpty()) - setSearchColour(lineEdits->at(i),1); - } + { + // block signal so that it does not trigger a setText back on lineEdits->at(1)! + QSignalBlocker signalBlocker(lineEdits->at(0)); + lineEdits->at(0)->setText(newText); + } + for(int i=0; isize();i++){ + if(lineEdits->at(0)->text().isEmpty()) + setSearchColour(lineEdits->at(i),1); + } } +/** + * @brief Slot for Color button click. + */ void SearchDialog::on_pushButtonColor_clicked() { QString color = QDltSettingsManager::getInstance()->value("other/searchResultColor", QString("#00AAFF")).toString(); @@ -555,6 +708,9 @@ void SearchDialog::on_pushButtonColor_clicked() updateColorbutton(); } +/** + * @brief Updates the color button icon. + */ void SearchDialog::updateColorbutton() { QString color = QDltSettingsManager::getInstance()->value("other/searchResultColor", QString("#00AAFF")).toString(); @@ -565,19 +721,28 @@ void SearchDialog::updateColorbutton() ui->pushButtonColor->setIcon(px); } - +/** + * @brief Adds a found line to the search index. + * @param searchLine Line number. + */ void SearchDialog::addToSearchIndex(long int searchLine) { //qDebug() << "Add hit line to search table" << searchLine << __LINE__; - m_searchtablemodel->add_SearchResultEntry(file->getMsgFilterPos(searchLine)); - } + m_searchtablemodel->add_SearchResultEntry(file->getMsgFilterPos(searchLine)); +} +/** + * @brief Registers the search table model. + * @param model Pointer to SearchTableModel. + */ void SearchDialog::registerSearchTableModel(SearchTableModel *model) { - m_searchtablemodel = model; + m_searchtablemodel = model; } - +/** + * @brief Loads search history from cache. + */ void SearchDialog::loadSearchHistory() { // getting text of the action button clicked to load search history. @@ -588,13 +753,13 @@ void SearchDialog::loadSearchHistory() text = action->text(); } - // creating a local list to store the indexes related to the key retrieved from the cache. + // creating a local list to store the indexes related to the key retrieved from the cache. QList tmp ; if(cachedHistoryKey.size() > 0) { tmp = cachedHistoryKey[text]; - //deleting the previous search list and adding the cached search obtained to the model. + //deleting the previous search list and adding the cached search obtained to the model. m_searchtablemodel->clear_SearchResults(); for (int i = 0;i < tmp.size();i++) { @@ -604,20 +769,30 @@ void SearchDialog::loadSearchHistory() emit refreshedSearchIndex(); } +/** + * @brief Caches the current search history. + */ void SearchDialog::cacheSearchHistory() { // if it is a new search then add all the indexes of the search to a list(m_searchHistory). - QString searchBoxText = getText(); + QString searchBoxText = getText(); m_searchHistory.append(m_searchtablemodel->m_searchResultList); - cachedHistoryKey.insert(searchBoxText,m_searchHistory.last()); + cachedHistoryKey.insert(searchBoxText,m_searchHistory.last()); } +/** + * @brief Clears the cached search history. + */ void SearchDialog::clearCacheHistory() { // obtaining the list of keys stored in cache cachedHistoryKey.clear(); } +/** + * @brief Saves search history to persistent storage. + * @param searchHistory Reference to QStringList of history. + */ void SearchDialog::saveSearchHistory(QStringList& searchHistory) { //To save the search history QSettings settings("MyApp", "SearchHistory"); @@ -630,6 +805,10 @@ void SearchDialog::saveSearchHistory(QStringList& searchHistory) { settings.endArray(); } +/** + * @brief Loads search history from persistent storage. + * @param searchHistory Reference to QStringList to populate. + */ void SearchDialog::loadSearchHistoryList(QStringList& searchHistory) { //To retrive the search history once DLT Viewer restarts @@ -643,39 +822,56 @@ void SearchDialog::loadSearchHistoryList(QStringList& searchHistory) settings.endArray(); } +/** + * @brief Slot for header checkbox toggled. + * @param checked Checkbox state. + */ void SearchDialog::on_checkBoxHeader_toggled(bool checked) { - QDltSettingsManager::getInstance()->setValue("other/search/checkBoxHeader", checked); + QDltSettingsManager::getInstance()->setValue("other/search/checkBoxHeader", checked); } - +/** + * @brief Slot for search index checkbox toggled. + * @param checked Checkbox state. + */ void SearchDialog::on_checkBoxSearchIndex_toggled(bool checked) { QDltSettingsManager::getInstance()->setValue("other/search/checkBoxSearchIndex", checked); setStartLine(-1); } +/** + * @brief Slot for case sensitivity checkbox toggled. + * @param checked Checkbox state. + */ void SearchDialog::on_checkBoxCaseSensitive_toggled(bool checked) { QDltSettingsManager::getInstance()->setValue("other/search/checkBoxCasesensitive", checked); } +/** + * @brief Slot for regular expression checkbox toggled. + * @param checked Checkbox state. + */ void SearchDialog::on_checkBoxRegExp_toggled(bool checked) { QDltSettingsManager::getInstance()->setValue("other/search/checkBoxRegEx", checked); } - +/** + * @brief Starts timing for search duration. + */ void SearchDialog::starttime(void) { -long int temps; + long int temps; #if defined(_MSC_VER) - SYSTEMTIME systemtime; - GetSystemTime(&systemtime); - time_t timestamp_sec; - time(×tamp_sec); - temps = (time_t)timestamp_sec; + SYSTEMTIME systemtime; + GetSystemTime(&systemtime); + time_t timestamp_sec; + time(×tamp_sec); + temps = (time_t)timestamp_sec; #else struct timeval tv; gettimeofday(&tv, NULL); @@ -685,17 +881,20 @@ long int temps; } +/** + * @brief Stops timing and logs search duration. + */ void SearchDialog::stoptime(void) { -long int temps; -long int dtemps; + long int temps; + long int dtemps; #if defined(_MSC_VER) - SYSTEMTIME systemtime; - GetSystemTime(&systemtime); - time_t timestamp_sec; - time(×tamp_sec); - temps = (time_t)timestamp_sec; + SYSTEMTIME systemtime; + GetSystemTime(&systemtime); + time_t timestamp_sec; + time(×tamp_sec); + temps = (time_t)timestamp_sec; #else struct timeval tv; gettimeofday(&tv, NULL); diff --git a/src/searchdialog.h b/src/searchdialog.h index b1ca18e8..ac84398f 100644 --- a/src/searchdialog.h +++ b/src/searchdialog.h @@ -43,7 +43,11 @@ namespace Ui { class SearchDialog; } - +/** + * @class SearchDialog + * @brief Provides a dialog for searching messages in DLT Viewer. + * * Handles search parameters, search execution, result highlighting, and search history. + */ class SearchDialog : public QDialog { Q_OBJECT