Fetch Strings asynchronously

This commit is contained in:
Florian Märkl 2018-05-28 22:06:24 +02:00
parent 2e26ead446
commit cc3ad67096
6 changed files with 54 additions and 3 deletions

View File

@ -166,7 +166,8 @@ SOURCES += \
widgets/StackWidget.cpp \ widgets/StackWidget.cpp \
widgets/RegistersWidget.cpp \ widgets/RegistersWidget.cpp \
widgets/BacktraceWidget.cpp \ widgets/BacktraceWidget.cpp \
dialogs/OpenFileDialog.cpp dialogs/OpenFileDialog.cpp \
utils/StringsTask.cpp
HEADERS += \ HEADERS += \
Cutter.h \ Cutter.h \
@ -247,7 +248,8 @@ HEADERS += \
widgets/StackWidget.h \ widgets/StackWidget.h \
widgets/RegistersWidget.h \ widgets/RegistersWidget.h \
widgets/BacktraceWidget.h \ widgets/BacktraceWidget.h \
dialogs/OpenFileDialog.h dialogs/OpenFileDialog.h \
utils/StringsTask.h
FORMS += \ FORMS += \
dialogs/AboutDialog.ui \ dialogs/AboutDialog.ui \

View File

@ -4,6 +4,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qRegisterMetaType<QList<StringDescription>>();
CutterApplication a(argc, argv); CutterApplication a(argc, argv);
int ret = a.exec(); int ret = a.exec();

View File

@ -0,0 +1,8 @@
#include "StringsTask.h"
void StringsTask::runTask()
{
auto strings = Core()->getAllStrings();
emit stringSearchFinished(strings);
}

22
src/utils/StringsTask.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef STRINGSASYNCTASK_H
#define STRINGSASYNCTASK_H
#include "utils/AsyncTask.h"
#include "Cutter.h"
class StringsTask : public AsyncTask
{
Q_OBJECT
public:
QString getTitle() override { return tr("Searching for Strings"); }
signals:
void stringSearchFinished(const QList<StringDescription> &strings);
protected:
void runTask() override;
};
#endif //STRINGSASYNCTASK_H

View File

@ -172,12 +172,25 @@ void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index)
} }
void StringsWidget::refreshStrings() void StringsWidget::refreshStrings()
{
if (task) {
task->wait();
}
task = QSharedPointer<StringsTask>(new StringsTask());
connect(task.data(), &StringsTask::stringSearchFinished, this, &StringsWidget::stringSearchFinished);
Core()->getAsyncTaskManager()->start(task);
}
void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings)
{ {
model->beginReload(); model->beginReload();
strings = Core()->getAllStrings(); this->strings = strings;
model->endReload(); model->endReload();
qhelpers::adjustColumns(ui->stringsTreeView, 5, 0); qhelpers::adjustColumns(ui->stringsTreeView, 5, 0);
if (ui->stringsTreeView->columnWidth(1) > 300) if (ui->stringsTreeView->columnWidth(1) > 300)
ui->stringsTreeView->setColumnWidth(1, 300); ui->stringsTreeView->setColumnWidth(1, 300);
task = nullptr;
} }

View File

@ -5,6 +5,7 @@
#include "Cutter.h" #include "Cutter.h"
#include "CutterDockWidget.h" #include "CutterDockWidget.h"
#include "utils/StringsTask.h"
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -66,10 +67,13 @@ private slots:
void on_stringsTreeView_doubleClicked(const QModelIndex &index); void on_stringsTreeView_doubleClicked(const QModelIndex &index);
void refreshStrings(); void refreshStrings();
void stringSearchFinished(const QList<StringDescription> &strings);
private: private:
std::unique_ptr<Ui::StringsWidget> ui; std::unique_ptr<Ui::StringsWidget> ui;
QSharedPointer<StringsTask> task;
StringsModel *model; StringsModel *model;
StringsSortFilterProxyModel *proxy_model; StringsSortFilterProxyModel *proxy_model;
QList<StringDescription> strings; QList<StringDescription> strings;