From eb361e772de6cc56b484b2408e657c573e5d5a7c Mon Sep 17 00:00:00 2001 From: Carlos Barajas Date: Thu, 23 Nov 2017 08:02:07 -0500 Subject: [PATCH] added a nifty progressbar that displays files searched --- cpp/widgets/reader.cpp | 27 +++++++++++++++++++++++++-- headers/widgets/reader.h | 6 ++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cpp/widgets/reader.cpp b/cpp/widgets/reader.cpp index 97c5ba5..b8abc2c 100644 --- a/cpp/widgets/reader.cpp +++ b/cpp/widgets/reader.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "search.h" #include "rsearch.h" @@ -42,7 +43,9 @@ Reader::Reader(QString basepath, QStringList Files, QStringList Dates, QMap Params) { base = basepath; - int len = Files.length(); + len = Files.length(); + filesSearched->setMaximum(len); + progWidget->show(); files = Files; qDebug() << "+Reader: Building additional objects on the heap..."; entries = new QStringList[len]; @@ -107,6 +110,15 @@ void Reader::initGui() { logTitle = new QLabel("", this); + // Progress Bar + filesSearched = new QProgressBar(this); + filesSearched->setMinimum(0); + filesSearched->setFixedWidth(225); + filesSearched->setTextVisible(true); + filesSearched->setAlignment(Qt::AlignCenter); + QHBoxLayout *progBox = new QHBoxLayout(this); + progWidget = new QWidget(this); + progWidget->setLayout(progBox); // Setup QVBoxLayout *vbox = new QVBoxLayout(this); @@ -117,8 +129,16 @@ void Reader::initGui() { QHBoxLayout *hbox = new QHBoxLayout(this); hbox->addWidget(tree); hbox->addWidget(vboxWidget); + QWidget *hboxWidget = new QWidget(this); + hboxWidget->setLayout(hbox); + progBox->addWidget(filesSearched); + + QVBoxLayout *outerVBox = new QVBoxLayout(this); + outerVBox->setAlignment(Qt::AlignCenter); + outerVBox->addWidget(hboxWidget); + outerVBox->addWidget(progWidget); - setLayout(hbox); + setLayout(outerVBox); } void Reader::generateTree() { @@ -227,6 +247,7 @@ void Reader::tRefresh() { } if ((currentComplete > totalComplete) || (currentComplete == files.length())) { + filesSearched->setFormat("Searched: " + QString::number(totalComplete) + "/" + QString::number(len)); // Searching has finished! if (totalComplete == 0) { tree->setModel(treeModel); @@ -234,6 +255,7 @@ void Reader::tRefresh() { // This should stop the tree from being rebuilt if everything is done if (currentComplete == files.length()) { poll->stop(); + progWidget->hide(); // delete searchObj; // delete searchThd; } @@ -254,6 +276,7 @@ void Reader::tRefresh() { } } totalComplete = currentComplete; + filesSearched->setValue(totalComplete); // Eventually add a progress bar, then update that here // Rebuild tree // newTree(); diff --git a/headers/widgets/reader.h b/headers/widgets/reader.h index a1d9704..5e1ccbc 100644 --- a/headers/widgets/reader.h +++ b/headers/widgets/reader.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "rsearch.h" class ChatTable : public QAbstractTableModel { @@ -68,6 +69,7 @@ class Reader : public QWidget { private: void initGui(); + int len; rSearch *searchObj; QThread *searchThd; // Variables @@ -95,7 +97,7 @@ class Reader : public QWidget { void appendToTree(QDate newDate); int tickCount = 0; bool *stopped; - - + QProgressBar *filesSearched; + QWidget *progWidget; };