Skip to content

Commit

Permalink
added a nifty progressbar that displays files searched
Browse files Browse the repository at this point in the history
  • Loading branch information
AmericanEnglish committed Nov 23, 2017
1 parent 1f0d331 commit eb361e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 25 additions & 2 deletions cpp/widgets/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QApplication>
#include <QClipboard>
#include <QAbstractItemView>
#include <QProgressBar>
#include "search.h"
#include "rsearch.h"

Expand All @@ -42,7 +43,9 @@ Reader::Reader(QString basepath, QStringList Files, QStringList Dates, QMap<QStr

void Reader::newSearch(QString basepath, QStringList Files, QStringList Dates, QMap<QString, QRegularExpression> 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];
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -227,13 +247,15 @@ 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);
}
// This should stop the tree from being rebuilt if everything is done
if (currentComplete == files.length()) {
poll->stop();
progWidget->hide();
// delete searchObj;
// delete searchThd;
}
Expand All @@ -254,6 +276,7 @@ void Reader::tRefresh() {
}
}
totalComplete = currentComplete;
filesSearched->setValue(totalComplete);
// Eventually add a progress bar, then update that here
// Rebuild tree
// newTree();
Expand Down
6 changes: 4 additions & 2 deletions headers/widgets/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QList>
#include <QVariant>
#include <QThread>
#include <QProgressBar>
#include "rsearch.h"

class ChatTable : public QAbstractTableModel {
Expand Down Expand Up @@ -68,6 +69,7 @@ class Reader : public QWidget {

private:
void initGui();
int len;
rSearch *searchObj;
QThread *searchThd;
// Variables
Expand Down Expand Up @@ -95,7 +97,7 @@ class Reader : public QWidget {
void appendToTree(QDate newDate);
int tickCount = 0;
bool *stopped;


QProgressBar *filesSearched;
QWidget *progWidget;
};

0 comments on commit eb361e7

Please sign in to comment.