From: hama Date: Thu, 23 Apr 2015 20:06:38 +0000 (+0200) Subject: ReGuiValidator, About dialog works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=47f46592d01004438c69bf6bf86e192e4aa17601;p=reqt ReGuiValidator, About dialog works --- diff --git a/appl/refind/aboutdialog.ui b/appl/refind/aboutdialog.ui index d9a70ea..e5ba02f 100644 --- a/appl/refind/aboutdialog.ui +++ b/appl/refind/aboutdialog.ui @@ -13,6 +13,9 @@ Dialog + + true + @@ -50,29 +53,18 @@ p, li { white-space: pre-wrap; } &OK - - - &Ok - - - Close the dialog - - - Ctrl+X - - - actionOk - triggered() + pushButtonOK + clicked() AboutDialog close() - -1 - -1 + 196 + 183 199 diff --git a/appl/refind/filefinder.cpp b/appl/refind/filefinder.cpp index d0f6899..419fc49 100644 --- a/appl/refind/filefinder.cpp +++ b/appl/refind/filefinder.cpp @@ -8,6 +8,7 @@ #include #include "base/rebase.hpp" +#include "gui/regui.hpp" #include "mainwindow.hpp" #include "filefinder.hpp" #include "textfinder.hpp" diff --git a/appl/refind/main.cpp b/appl/refind/main.cpp index c4d1af3..3e01aff 100644 --- a/appl/refind/main.cpp +++ b/appl/refind/main.cpp @@ -11,6 +11,7 @@ #include #include "base/rebase.hpp" +#include "gui/regui.hpp" #include "mainwindow.hpp" int main(int argc, char *argv[]){ diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index fa01bc0..f21da77 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include "base/rebase.hpp" +#include "gui/regui.hpp" #include "textfinder.hpp" #include "mainwindow.hpp" #include "ui_mainwindow.h" @@ -30,7 +31,6 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : ui(new Ui::MainWindow), m_statusMessage(NULL), m_stdLabelBackgroundRole(NULL), - m_errors(0), m_textFinder(), m_lastBaseDir(), m_horizontalHeader(NULL), @@ -56,8 +56,7 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : SLOT(fullNameToClipboard())); connect(ui->actionGetFullName, SIGNAL(triggered()), this, SLOT(fullNameToClipboard())); - connect(ui->actionReset, SIGNAL(triggered()), this, - SLOT(resetParameters())); + connect(ui->actionReset, SIGNAL(triggered()), this, SLOT(resetParameters())); connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int, int))); m_horizontalHeader = ui->tableWidget->horizontalHeader(); connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ), @@ -96,8 +95,7 @@ MainWindow::~MainWindow(){ */ void MainWindow::about(){ AboutDialog dialog; - dialog.setModal(true); - dialog.show(); + dialog.exec(); } /** @@ -161,95 +159,6 @@ void MainWindow::fullNameToClipboard(){ } } -/** - * Returns the date given as formula in a combobox. - * - * @param combo the combobox with the date/time formula - * - * @return the date resulting from the formula or begin of the epoch (error case) - */ -QDateTime MainWindow::comboDate(QComboBox* combo){ - QDateTime rc; - QString value = combo->currentText(); - if (value.isEmpty()) - rc.setMSecsSinceEpoch(0); - else{ - ReDateTimeParser parser(value); - if (parser.isValid()){ - rc = parser.asDateTime(); - setInHistory(combo, value); - combo->setCurrentText(rc.toString("yyyy.MM.dd/hh:mm")); - }else{ - guiError(combo, parser.errorMessage()); - rc.setMSecsSinceEpoch(0); - } - } - return rc; -} -/** - * Returns an integer given in a combobox. - * - * @param combo the combobox with the integer - * @param defaultValue the value if the combobox is empty or invalid - * @return defaultValue: empty or invalid input
- * otherwise: or the size resulting from the formula - */ -int MainWindow::comboInt(QComboBox* combo, int defaultValue){ - QString value = combo->currentText(); - int rc = defaultValue; - if (!value.isEmpty()){ - uint nValue = 0; - if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0) - guiError(combo, QObject::tr("not an integer: ") + value); - else{ - setInHistory(combo, value); - rc = (int) nValue; - } - } - return rc; -} - -/** - * Returns the size (in bytes) given as formula in a combobox. - * - * @param combo the combobox with the size formula - * - * @return -1: empty or invalid input
- * otherwise: or the size resulting from the formula - */ -int64_t MainWindow::comboSize(QComboBox* combo){ - QString value = combo->currentText(); - int64_t rc = -1; - if (!value.isEmpty()){ - ReSizeParser parser(value); - rc = parser.asInt64(-1); - if (rc >= 0){ - setInHistory(combo, value); - combo->setCurrentText(QString("").sprintf("%ld", rc)); - }else - guiError(combo, parser.errorMessage()); - } - return rc; -} - -/** - * Handles an error found in an interactive widget. - * - * @param widget the widget where the error was found - * @param message the error message - */ -void MainWindow::guiError(QWidget* widget, const QString& message){ - widget->setFocus(Qt::OtherFocusReason); - setStatusMessage(true, message); - m_errors++; -} - -QString MainWindow::comboText(QComboBox* combo){ - QString rc = combo->currentText(); - setInHistory(combo, rc); - return rc; -} - /** * Converts the checkbox states to a filetype mask. * @return the filetypes selected by the checkboxes @@ -318,8 +227,8 @@ void MainWindow::resetParameters(){ */ void MainWindow::search(){ m_errors = 0; - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - QString path = ui->comboBoxDirectory->currentText(); + QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString + path = ui->comboBoxDirectory->currentText(); QFileInfo dir(path); if (!dir.exists()) guiError(ui->comboBoxDirectory, tr("directory not found: ") + path); @@ -377,34 +286,6 @@ void MainWindow::selectDirectory(){ ui->comboBoxDirectory->setCurrentText(dir); } -/** - * @brief Sets a text in a combobox uses as history. - * - * Sets the text as the first entry. If the text can be found in other entries - * of the combobox it will be deleted there. - * - * @param combo the combobox to change - * @param value the text to set - */ -void MainWindow::setInHistory(QComboBox* combo, const QString& value){ - if (value.isEmpty()){ - // nothing to do - }else if (combo->count() == 0) - combo->addItem(value); - else{ - if (value != combo->itemText(0)){ - combo->insertItem(0, value); - } - for (int ii = 1; ii < combo->count(); ii++){ - if (value == combo->itemText(ii)){ - combo->removeItem(ii); - } - } - if (combo->count() > 20) - combo->removeItem(20); - } -} - /** * Writes a text to the status line. * diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index 0e915fe..6f0df88 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -22,6 +22,9 @@ #if ! defined TEXTFINDER_HPP #include "textfinder.hpp" #endif +#if ! defined GUI_REGUI_HPP_ +#include "gui/regui.hpp" +#endif namespace Ui { class MainWindow; } @@ -29,7 +32,7 @@ enum TableColumns { TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH }; -class MainWindow: public QMainWindow { +class MainWindow: public QMainWindow, public ReGuiValidator { Q_OBJECT @@ -45,26 +48,19 @@ private slots: void headerClicked(int col); void resetParameters(); void search(); - void up(); void selectDirectory(); + void up(); private: QString buildAbsPath(int row); QDir::Filters buildFileTypes(); QString cellAsText(int row, int col); - QDateTime comboDate(QComboBox* combo); - int comboInt(QComboBox* combo, int defaultValue); - int64_t comboSize(QComboBox* combo); - QString comboText(QComboBox* combo); - void guiError(QWidget* widget, const QString& message); void prepareTextFind(); - void setInHistory(QComboBox* combo, const QString& value); - void setStatusMessage(bool error, const QString& message); + virtual void setStatusMessage(bool error, const QString& message); private: Ui::MainWindow *ui; QLabel* m_statusMessage; QPalette::ColorRole* m_stdLabelBackgroundRole; - int m_errors; TextFinder m_textFinder; // the directory of the last search QDir m_lastBaseDir; diff --git a/appl/refind/refind.pro b/appl/refind/refind.pro index b139d1f..130a549 100644 --- a/appl/refind/refind.pro +++ b/appl/refind/refind.pro @@ -14,25 +14,30 @@ TEMPLATE = app INCLUDEPATH = ../.. /usr/include/c++/4.9 SOURCES += main.cpp\ - mainwindow.cpp \ - ../../base/ReException.cpp \ - ../../base/ReQStringUtil.cpp \ - ../../base/ReLogger.cpp \ - filefinder.cpp \ - textfinder.cpp \ - aboutdialog.cpp + mainwindow.cpp \ + ../../base/ReException.cpp \ + ../../base/ReQStringUtil.cpp \ + ../../base/ReLogger.cpp \ + filefinder.cpp \ + textfinder.cpp \ + aboutdialog.cpp \ + ../../gui/ReStateStorage.cpp \ + ../../gui/ReGuiValidator.cpp HEADERS += mainwindow.hpp \ - ../../base/rebase.hpp \ - filefinder.hpp \ - ../../base/ReQStringUtil.hpp \ - textfinder.hpp \ - aboutdialog.hpp + ../../base/rebase.hpp \ + filefinder.hpp \ + ../../base/ReQStringUtil.hpp \ + textfinder.hpp \ + ../../gui/ReStateStorage.hpp \ + aboutdialog.hpp \ + ../../gui/ReGuiValidator.hpp \ + ../../gui/regui.hpp FORMS += mainwindow.ui \ - aboutdialog.ui + aboutdialog.ui RESOURCES += \ - refind.qrc + refind.qrc diff --git a/appl/refind/textfinder.cpp b/appl/refind/textfinder.cpp index 06431ec..c3055b0 100644 --- a/appl/refind/textfinder.cpp +++ b/appl/refind/textfinder.cpp @@ -43,10 +43,10 @@ TextFinder::TextFinder(const QString& fullName, int64_t length) : * Destructor. */ TextFinder::~TextFinder(){ - if (m_ownsRegExpr){ - delete m_regExpr; - m_regExpr = NULL; - } + if (m_ownsRegExpr){ + delete m_regExpr; + m_regExpr = NULL; + } } /** @@ -219,10 +219,10 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase, m_ignoreCase = ignoreCase; m_isRegExpr = isRegExpr; m_ignoreBinary = ignoreBinary; - if (! isRegExpr || text.isEmpty()){ - delete m_regExpr; - m_regExpr = NULL; - } else { + if (!isRegExpr || text.isEmpty()){ + delete m_regExpr; + m_regExpr = NULL; + }else{ QRegularExpression::PatternOption option = ignoreCase ? QRegularExpression::CaseInsensitiveOption : @@ -240,7 +240,7 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase, */ QString TextFinder::regExprError(){ QString rc; - if (m_regExpr != NULL && ! m_regExpr->isValid()) + if (m_regExpr != NULL && !m_regExpr->isValid()) rc = m_regExpr->errorString(); return rc; } diff --git a/gui/ReGuiValidator.cpp b/gui/ReGuiValidator.cpp new file mode 100644 index 0000000..9e9ebf0 --- /dev/null +++ b/gui/ReGuiValidator.cpp @@ -0,0 +1,167 @@ +/* + * ReGuiValidator.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use the license from http://www.wtfpl.net/. + * The latest sources: https://github.com/republib + */ + +#include "base/rebase.hpp" +#include "gui/regui.hpp" + +/** + * Constructor. + */ +ReGuiValidator::ReGuiValidator() : + m_statusLine(NULL), m_errors(0){ +} + +/** + * Destructor. + */ +ReGuiValidator::~ReGuiValidator(){ +} + +/** + * Returns the date given as formula in a combobox. + * + * @param combo the combobox with the date/time formula + * + * @return the date resulting from the formula or begin of the epoch (error case) + */ +QDateTime ReGuiValidator::comboDate(QComboBox* combo){ + QDateTime rc; + QString value = combo->currentText(); + if (value.isEmpty()) + rc.setMSecsSinceEpoch(0); + else{ + ReDateTimeParser parser(value); + if (parser.isValid()){ + rc = parser.asDateTime(); + setInHistory(combo, value); + combo->setCurrentText(rc.toString("yyyy.MM.dd/hh:mm")); + }else{ + guiError(combo, parser.errorMessage()); + rc.setMSecsSinceEpoch(0); + } + } + return rc; +} +/** + * Returns an integer given in a combobox. + * + * @param combo the combobox with the integer + * @param defaultValue the value if the combobox is empty or invalid + * @return defaultValue: empty or invalid input
+ * otherwise: or the size resulting from the formula + */ +int ReGuiValidator::comboInt(QComboBox* combo, int defaultValue){ + QString value = combo->currentText(); + int rc = defaultValue; + if (!value.isEmpty()){ + uint nValue = 0; + if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0) + guiError(combo, QObject::tr("not an integer: ") + value); + else{ + setInHistory(combo, value); + rc = (int) nValue; + } + } + return rc; +} + +/** + * Returns the size (in bytes) given as formula in a combobox. + * + * @param combo the combobox with the size formula + * + * @return -1: empty or invalid input
+ * otherwise: or the size resulting from the formula + */ +int64_t ReGuiValidator::comboSize(QComboBox* combo){ + QString value = combo->currentText(); + int64_t rc = -1; + if (!value.isEmpty()){ + ReSizeParser parser(value); + rc = parser.asInt64(-1); + if (rc >= 0){ + setInHistory(combo, value); + combo->setCurrentText(QString("").sprintf("%ld", rc)); + }else + guiError(combo, parser.errorMessage()); + } + return rc; +} + +/** + * Returns the current text from a combobox and puts it into the history. + * + * @param combo combobox to handle + * + * @return the current text + */ +QString ReGuiValidator::comboText(QComboBox* combo){ + QString rc = combo->currentText(); + setInHistory(combo, rc); + return rc; +} + +/** + * Handles an error found in an interactive widget. + * + * @param widget the widget where the error was found + * @param message the error message + */ +void ReGuiValidator::guiError(QWidget* widget, const QString& message){ + widget->setFocus(Qt::OtherFocusReason); + setStatusMessage(true, message); + m_errors++; +} + +/** + * @brief Sets a text in a combobox uses as history. + * + * Sets the text as the first entry. If the text can be found in other entries + * of the combobox it will be deleted there. + * + * @param combo the combobox to change + * @param value the text to set + */ +void ReGuiValidator::setInHistory(QComboBox* combo, const QString& value){ + if (value.isEmpty()){ + // nothing to do + }else if (combo->count() == 0) + combo->addItem(value); + else{ + if (value != combo->itemText(0)){ + combo->insertItem(0, value); + } + for (int ii = 1; ii < combo->count(); ii++){ + if (value == combo->itemText(ii)){ + combo->removeItem(ii); + } + } + if (combo->count() > 20) + combo->removeItem(20); + } +} +/** + * Returns the status line. + * @return the status line + */ +QStatusBar* ReGuiValidator::statusLine() const{ + return m_statusLine; +} + +/** + * Sets the status line. + * + * @param statusLine the status line to set + */ +void ReGuiValidator::setStatusLine(QStatusBar* statusLine){ + m_statusLine = statusLine; +} + diff --git a/gui/ReGuiValidator.hpp b/gui/ReGuiValidator.hpp new file mode 100644 index 0000000..4abdde1 --- /dev/null +++ b/gui/ReGuiValidator.hpp @@ -0,0 +1,38 @@ +/* + * ReGuiUtils.hpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use the license from http://www.wtfpl.net/. + * The latest sources: https://github.com/republib + */ + +#ifndef GUI_REVALIDATOR_HPP_ +#define GUI_REVALIDATOR_HPP_ + +#include +#include + +class ReGuiValidator { +public: + ReGuiValidator(); + ~ReGuiValidator(); +public: + QDateTime comboDate(QComboBox* combo); + int comboInt(QComboBox* combo, int defaultValue); + int64_t comboSize(QComboBox* combo); + QString comboText(QComboBox* combo); + virtual void guiError(QWidget* widget, const QString& message); + void setInHistory(QComboBox* combo, const QString& value); + void setStatusLine(QStatusBar* statusLine); + virtual void setStatusMessage(bool error, const QString& message) = 0; + QStatusBar* statusLine() const; + +protected: + QStatusBar* m_statusLine; + int m_errors; +}; + +#endif /* GUI_REVALIDATOR_HPP_ */ diff --git a/gui/ReStateStorage.cpp b/gui/ReStateStorage.cpp new file mode 100644 index 0000000..95cc847 --- /dev/null +++ b/gui/ReStateStorage.cpp @@ -0,0 +1,27 @@ +/* + * ReStateStorage.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use the license from http://www.wtfpl.net/. + * The latest sources: https://github.com/republib + */ + +#include "base/rebase.hpp" +#include "gui/regui.hpp" + +/** + * Constructor. + * + * @param file + */ +ReStateStorage::ReStateStorage(const QString& file){ + +} + +ReStateStorage::~ReStateStorage(){ + +} + diff --git a/gui/ReStateStorage.hpp b/gui/ReStateStorage.hpp new file mode 100644 index 0000000..8a2b012 --- /dev/null +++ b/gui/ReStateStorage.hpp @@ -0,0 +1,21 @@ +/* + * ReStateStorage.hpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use the license from http://www.wtfpl.net/. + * The latest sources: https://github.com/republib + */ + +#ifndef GUI_RESTATESTORAGE_HPP_ +#define GUI_RESTATESTORAGE_HPP_ + +class ReStateStorage { +public: + ReStateStorage(const QString& file); + virtual ~ReStateStorage(); +}; + +#endif /* GUI_RESTATESTORAGE_HPP_ */ diff --git a/gui/regui.hpp b/gui/regui.hpp new file mode 100644 index 0000000..d0d2c58 --- /dev/null +++ b/gui/regui.hpp @@ -0,0 +1,17 @@ +/* + * regui.hpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use the license from http://www.wtfpl.net/. + * The latest sources: https://github.com/republib + */ + +#ifndef GUI_REGUI_HPP_ +#define GUI_REGUI_HPP_ + +#include "gui/ReStateStorage.hpp" +#include "gui/ReGuiValidator.hpp" +#endif /* GUI_REGUI_HPP_ */