Skip to content

Commit

Permalink
move search form specific vars from mainwindow
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kopp <[email protected]>
  • Loading branch information
vifactor authored and alexmucde committed Jan 7, 2025
1 parent 1f783ad commit 99013c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
16 changes: 4 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->actionProject->setChecked(ui->dockWidgetContents->isVisible());
ui->actionSearch_Results->setChecked(ui->dockWidgetSearchIndex->isVisible());

newCompleter = new QCompleter(&m_CompleterModel,this);

/* what for do we need the next 2 lines ? */
draw_timer.setSingleShot (true);
connect(&draw_timer, SIGNAL(timeout()), this, SLOT(draw_timeout()));
Expand Down Expand Up @@ -278,7 +276,6 @@ MainWindow::~MainWindow()
delete dltIndexer;
delete m_shortcut_searchnext;
delete m_shortcut_searchprev;
delete newCompleter;
delete sortProxyModel;
}

Expand Down Expand Up @@ -2384,21 +2381,15 @@ void MainWindow::on_action_menuFile_Quit_triggered()

void MainWindow::on_actionFindNext()
{
//qDebug() << "on_actionFindNext" << __LINE__;
if(!searchInput->input()->text().isEmpty() && !list.contains(searchInput->input()->text()))
{
list.append(searchInput->input()->text());
}
QString title = "Search Results";
searchInput->updateHistory();

QString title = "Search Results";
if ( 0 < m_searchtableModel->get_SearchResultListSize())
{
title = QString("Search Results: %L1").arg(m_searchtableModel->get_SearchResultListSize());
title += QStringLiteral(": %L1").arg(m_searchtableModel->get_SearchResultListSize());
}
ui->dockWidgetSearchIndex->setWindowTitle(title);
ui->dockWidgetSearchIndex->show();
m_CompleterModel.setStringList(list);
searchInput->input()->setCompleter(newCompleter);
}

void MainWindow::on_action_menuProject_New_triggered()
Expand Down Expand Up @@ -4488,6 +4479,7 @@ void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QD
versionString(msg);
autoloadPluginsVersionEcus.append(msg.getEcuid());
}
break;
}
case DLT_SERVICE_ID_GET_LOG_INFO:
{
Expand Down
14 changes: 0 additions & 14 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include <QColor>
#include <QComboBox>
#include <QProgressBar>
#include <QCompleter>
#include <QStringListModel>

#include "tablemodel.h"
#include "settingsdialog.h"
Expand All @@ -43,14 +41,6 @@
#include "ui_mainwindow.h"
#include "searchform.h"


/**
* When ecu items buffer size exceeds this while using
* serial connection, it will be considered corrupted.
**/

#define DLT_BUFFER_CORRUPT_TRESHOLD 4* 1024

/**
* @brief Namespace to contain the toolbar positions.
* You should always remember to update these enums if you
Expand Down Expand Up @@ -116,7 +106,6 @@ class MainWindow : public QMainWindow

private:
Ui::MainWindow *ui;
QCompleter *newCompleter;
/* Timer for connecting to ECUs */
QTimer timer;

Expand Down Expand Up @@ -374,8 +363,6 @@ class MainWindow : public QMainWindow
/* default filters */
void resetDefaultFilter();

QStringListModel m_CompleterModel;

/* Get path from explorerView model index */
QString getPathFromExplorerViewIndexModel(const QModelIndex &proxyIndex);

Expand Down Expand Up @@ -626,7 +613,6 @@ public slots:
QDltDefaultFilter defaultFilter;

QStringList openFileNames;
QStringList list;

/* store startLoggingDateTime when logging first data */
QDateTime startLoggingDateTime;
Expand Down
12 changes: 12 additions & 0 deletions src/searchform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_searchform.h"

#include <QLineEdit>
#include <QCompleter>

SearchForm::SearchForm(QWidget *parent)
: QWidget(parent)
Expand All @@ -12,6 +13,9 @@ SearchForm::SearchForm(QWidget *parent)
ui->comboBox->setLineEdit(new QLineEdit);
ui->comboBox->setInsertPolicy(QComboBox::InsertAtTop);

m_completer = new QCompleter(&m_historyModel, this);
input()->setCompleter(m_completer);

connect (ui->abortButton, &QPushButton::clicked, this, &SearchForm::abortSearch);
}

Expand Down Expand Up @@ -46,3 +50,11 @@ void SearchForm::resetProgress()
{
setProgress(0);
}

void SearchForm::updateHistory() {
if (auto list = m_historyModel.stringList();
!input()->text().isEmpty() && !list.contains(input()->text())) {
list.append(input()->text());
m_historyModel.setStringList(std::move(list));
}
}
6 changes: 6 additions & 0 deletions src/searchform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#define SEARCHFORM_H

#include <QWidget>
#include <QStringListModel>

namespace Ui {
class SearchForm;
}

class QLineEdit;
class QCompleter;

class SearchForm : public QWidget
{
Expand All @@ -27,12 +29,16 @@ class SearchForm : public QWidget
void setState(State state);
void setProgress(int val);
void resetProgress();
void updateHistory();

signals:
void abortSearch();

private:
Ui::SearchForm *ui;

QCompleter *m_completer{nullptr};
QStringListModel m_historyModel;
};

#endif // SEARCHFORM_H

0 comments on commit 99013c1

Please sign in to comment.