Skip to content

Commit

Permalink
Github Issue #122: Got a working version of the text search on the ma…
Browse files Browse the repository at this point in the history
…in window
  • Loading branch information
AngryFender committed Feb 8, 2024
1 parent 74b5c7d commit 115c7be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions navigationview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ NavigationView::NavigationView(QWidget *parent, bool editable):QTreeView(parent)
connect(this,&NavigationView::clicked, this, &NavigationView::rowClicked);
}

void NavigationView::setRowsEditable(bool enable)
{
this->editable = enable;
}

void NavigationView::expandEveryItems(QModelIndex index)
{
if(!expandTimer.isActive())
Expand Down
1 change: 1 addition & 0 deletions navigationview.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NavigationView : public QTreeView
Q_OBJECT
public:
NavigationView(QWidget * parent = nullptr, bool editable = true);
void setRowsEditable(bool enable);
void expandEveryItems(QModelIndex index);
void keyPressEvent(QKeyEvent *event)override;
private:
Expand Down
22 changes: 16 additions & 6 deletions views_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void ViewsHandler::initViews(Ui::MainWindow &ui)
frameSearchTextTree = ui.uiFrameSearchTree;
viewTextSearchEdit = ui.uiSearchText;
viewTextSearchTree = ui.uiSearchTree;
viewTextSearchTree->setRowsEditable(false);
viewTextSearchCount = ui.uiTextSearchCount;

viewTextSearchEdit->setPlaceholderText("Search Texts...");
Expand Down Expand Up @@ -178,12 +179,6 @@ void ViewsHandler::initConnection()
QObject::connect(&textSearchWorker,&TextSearchWorker::finished,
&searchThread, &QThread::quit);

// QObject::connect(&textSearchWorker,&TextSearchWorker::updateTextSearchView,
// textSearchAllView, &SearchAllDialog::updateTextSearchViewHandle);

QObject::connect(textSearchAllView,&SearchAllDialog::showSearchedTextInFile,
this,&ViewsHandler::displayTextSearchedFilePosition);

QObject::connect(this,&ViewsHandler::updateRecentFile,
recentFilesView,&RecentFilesDialog::updateRecentFileHandle);

Expand All @@ -206,6 +201,9 @@ void ViewsHandler::initConnection()
QObject::connect(&textSearchWorker,&TextSearchWorker::updateTextSearchView,
this, &ViewsHandler::updateTextSearchViewHandler);

QObject::connect(viewTextSearchTree,&NavigationView::pressed,
this,&ViewsHandler::textSearchResultPositionSelected);


}

Expand Down Expand Up @@ -612,6 +610,7 @@ void ViewsHandler::textSearchChangedHandler(const QString &text)
{
textSearchWorker.setText(text);
textSearchWorker.setRootPath(modelTree.rootPath());
proxyModel.createAllFilesList(viewTree->rootIndex(), textSearchWorker.getListPaths());
searchThread.start();
}

Expand All @@ -625,6 +624,17 @@ void ViewsHandler::updateTextSearchViewHandler(QStandardItemModel *model, int ma

}

void ViewsHandler::textSearchResultPositionSelected(const QModelIndex &index)
{
QModelIndex parentIndex = viewTextSearchTree->model()->parent(index);
QString filePath = parentIndex.data(Qt::UserRole).toString();
int searchTextLength = index.data(Qt::UserRole).toInt();
int blockNumber = index.data(Qt::UserRole+1).toInt();
int positionInBlock = index.data(Qt::UserRole+2).toInt();

displayTextSearchedFilePosition(filePath, searchTextLength, blockNumber, positionInBlock);
}

void ViewsHandler::openRecentFilesDialogHandle(bool show)
{
if(show){
Expand Down
1 change: 1 addition & 0 deletions views_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private slots:
void checkIfCursorInBlockHandler(bool &isBlock, QTextCursor &cursor);
void textSearchChangedHandler(const QString &text);
void updateTextSearchViewHandler(QStandardItemModel *model, int matchCount);
void textSearchResultPositionSelected(const QModelIndex &index);
};

#endif // VIEWS_HANDLER_H

0 comments on commit 115c7be

Please sign in to comment.