Skip to content

Commit

Permalink
QDateTime mChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
mugiseyebrows committed Mar 1, 2019
1 parent 653ba37 commit b5adccb
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 48 deletions.
43 changes: 33 additions & 10 deletions widget/searchbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <QDebug>

SearchBrowser::SearchBrowser(QWidget* parent)
: QTextBrowser(parent), mSearchId(-1), mCacheFileList(false), mLinesBefore(0), mLinesAfter(0),
mNotBinary(false) {
: QTextBrowser(parent), mSearchId(-1), mLinesBefore(0), mLinesAfter(0), mCacheFileList(false),
mNotBinary(false), mChanged(QDateTime::currentDateTime()) {
setOpenLinks(false);
//@todo external stylesheet
#ifdef Q_OS_LINUX
Expand All @@ -18,12 +18,24 @@ SearchBrowser::SearchBrowser(QWidget* parent)
SearchBrowser::~SearchBrowser() {
qDebug() << "~SearchBrowser()";
}
int SearchBrowser::searchId() const {
return mSearchId;
}

void SearchBrowser::setSearchId(int searchId) {
mSearchId = searchId;
mChanged = QDateTime::currentDateTime();
qDebug() << "searchId changed";
}

RegExp SearchBrowser::exp() const {
return mExp;
}

void SearchBrowser::setExp(const RegExp& exp) {
mExp = exp;
mChanged = QDateTime::currentDateTime();
qDebug() << "exp changed";
}

RegExpPath SearchBrowser::filter() const {
Expand All @@ -32,6 +44,8 @@ RegExpPath SearchBrowser::filter() const {

void SearchBrowser::setFilter(const RegExpPath& filter) {
mFilter = filter;
mChanged = QDateTime::currentDateTime();
qDebug() << "filter changed";
}

int SearchBrowser::linesBefore() const {
Expand All @@ -40,6 +54,8 @@ int SearchBrowser::linesBefore() const {

void SearchBrowser::setLinesBefore(int linesBefore) {
mLinesBefore = linesBefore;
mChanged = QDateTime::currentDateTime();
qDebug() << "linesBefore changed";
}

int SearchBrowser::linesAfter() const {
Expand All @@ -48,6 +64,8 @@ int SearchBrowser::linesAfter() const {

void SearchBrowser::setLinesAfter(int linesAfter) {
mLinesAfter = linesAfter;
mChanged = QDateTime::currentDateTime();
qDebug() << "linesAfter changed";
}

bool SearchBrowser::cacheFileList() const {
Expand All @@ -56,14 +74,8 @@ bool SearchBrowser::cacheFileList() const {

void SearchBrowser::setCacheFileList(bool cacheFileList) {
mCacheFileList = cacheFileList;
}

int SearchBrowser::searchId() const {
return mSearchId;
}

void SearchBrowser::setSearchId(int searchId) {
mSearchId = searchId;
mChanged = QDateTime::currentDateTime();
qDebug() << "cacheFileList changed";
}

bool SearchBrowser::notBinary() const {
Expand All @@ -72,6 +84,16 @@ bool SearchBrowser::notBinary() const {

void SearchBrowser::setNotBinary(bool notBinary) {
mNotBinary = notBinary;
mChanged = QDateTime::currentDateTime();
qDebug() << "notBinary changed";
}

QDateTime SearchBrowser::changed() const {
return mChanged;
}

void SearchBrowser::setChanged(const QDateTime& changed) {
mChanged = changed;
}

bool SearchBrowser::isExecuted() const {
Expand All @@ -85,4 +107,5 @@ void SearchBrowser::copy(SearchBrowser* dest) {
dest->setLinesAfter(mLinesAfter);
dest->setCacheFileList(mCacheFileList);
dest->setNotBinary(mNotBinary);
dest->setChanged(mChanged);
}
11 changes: 8 additions & 3 deletions widget/searchbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define SEARCHBROWSER_H
#include "regexp.h"
#include "regexppath.h"
#include <QDate>
#include <QDateTime>
#include <QTextBrowser>

class QDebug;
Expand All @@ -10,6 +12,8 @@ class SearchBrowser : public QTextBrowser {
public:
SearchBrowser(QWidget* parent = 0);
~SearchBrowser();
int searchId() const;
void setSearchId(int searchId);
RegExp exp() const;
void setExp(const RegExp& exp);
RegExpPath filter() const;
Expand All @@ -20,20 +24,21 @@ class SearchBrowser : public QTextBrowser {
void setLinesAfter(int linesAfter);
bool cacheFileList() const;
void setCacheFileList(bool cacheFileList);
int searchId() const;
void setSearchId(int searchId);
bool notBinary() const;
void setNotBinary(bool notBinary);
QDateTime changed() const;
void setChanged(const QDateTime& changed);
bool isExecuted() const;
void copy(SearchBrowser* dest);

protected:
int mSearchId;
RegExp mExp;
RegExpPath mFilter;
int mLinesBefore;
int mLinesAfter;
bool mCacheFileList;
int mSearchId;
bool mNotBinary;
QDateTime mChanged;
};
#endif // SEARCHBROWSER_H
5 changes: 4 additions & 1 deletion widget/searchoptionswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include "anchorclickhandler.h"
#include "selectfilesdialog.h"


SearchOptionsWidget::SearchOptionsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SearchOptionsWidget)
{
ui->setupUi(this);

}

SearchOptionsWidget::~SearchOptionsWidget()
Expand All @@ -41,7 +43,8 @@ void SearchOptionsWidget::setBrowser(SearchBrowser *browser, bool setValues)
ui->cacheFileList->setChecked(browser->cacheFileList());
ui->notBinary->setChecked(browser->notBinary());

//ui->path->setText(path);
ui->filter->hide();
ui->filter->show(); // force layout to recalculate
}

mActive = true;
Expand Down
1 change: 0 additions & 1 deletion widget/searchprogresswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void SearchProgressWidget::started() {
ui->status1->setText(QString("Building path list"));
ui->status2->setText(QString());
ui->status1->setVisible(true);
ui->cancel->setVisible(true);
}

void SearchProgressWidget::aborted() {
Expand Down
50 changes: 24 additions & 26 deletions widget/sessionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ void SessionWidget::onSearch() {
ui->progress->started();
}

int SessionWidget::oldestTabIndex() {
int SessionWidget::oldestTabIndex() { // todo test me
int count = ui->results->count();
int searchId = -1;
int index = -1;
for(int i=0;i<count;i++) {
if (count < 1) {
return -1;
}
QDateTime dateTime = tab(0)->changed();
int index = 0;
for(int i=1;i<count;i++) {
SearchBrowser* browser = tab(i);
int searchId_ = browser->searchId();
if (searchId_ > -1) {
if (searchId == -1 || searchId_ < searchId) {
searchId = searchId_;
index = i;
}
QDateTime dateTime_ = browser->changed();
if (dateTime > dateTime_) {
dateTime = dateTime_;
index = i;
}
}
return index;
Expand Down Expand Up @@ -175,34 +176,31 @@ void SessionWidget::save(const QString &path, const QString &text)
file.close();
}

SearchBrowser *SessionWidget::currentResult() const
{
QWidget* w = ui->results->widget(ui->results->currentIndex());
return qobject_cast<SearchBrowser*>(w);
}

void SessionWidget::onCanceled() {
mCancel = true;
}

void SessionWidget::on_saveText_clicked()
{
if (!currentResult())
return;
QString path = QFileDialog::getSaveFileName(this,QString(),QString(),"Text (*.txt)");
if (path.isEmpty())
return;
save(path,currentResult()->toPlainText());
save(true);
}

void SessionWidget::on_saveHtml_clicked()
{
if (!currentResult())
save(false);
}

void SessionWidget::save(bool plain) {
SearchBrowser* browser = currentTab();
if (!browser) {
return;
QString path = QFileDialog::getSaveFileName(this,QString(),QString(),"Html (*.html)");
if (path.isEmpty())
}
QString filter = plain ? "Text (*.txt)" : "Html (*.html)";
QString path = QFileDialog::getSaveFileName(this,QString(),QString(),filter);
if (path.isEmpty()) {
return;
save(path,currentResult()->toHtml());
}
save(path,plain ? browser->toPlainText() : browser->toHtml());
}

SearchBrowser* SessionWidget::find(int searchId) {
Expand Down
10 changes: 3 additions & 7 deletions widget/sessionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class SessionWidget : public QWidget

static void save(const QString& path, const QString& text);

SearchBrowser* currentResult() const;

bool mCancel;

QTabWidget* mTabWidget;
Expand All @@ -63,15 +61,13 @@ class SessionWidget : public QWidget

SearchBrowser *createTab(const QString &name, SearchBrowser *browser = 0, bool append = true, bool select = true);

//bool mListenResultCurrentChanged;

bool mSetValues;
void save(bool plain);
signals:

void setEditor();
void search(int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, int linesBofore, int linesAfter,bool cacheFileList);
void searchMore(int id);
void finishSearch(int id);
void searchMore(int searchId);
void finishSearch(int searchId);

public slots:
void onCanceled();
Expand Down

0 comments on commit b5adccb

Please sign in to comment.