]> gitweb.hamatoma.de Git - reqt/commitdiff
cuReEdit, cuReSettings without errors
authorhama <hama@siduction.net>
Tue, 25 Aug 2015 22:20:59 +0000 (00:20 +0200)
committerhama <hama@siduction.net>
Tue, 25 Aug 2015 22:20:59 +0000 (00:20 +0200)
12 files changed:
appl/reditor/mainwindow.cpp
appl/reditor/mainwindow.hpp
appl/reditor/project.hpp
appl/reditor/projectselection.cpp
appl/reditor/projectselection.hpp
appl/reditor/reditor.pro
appl/reditor/workspace.cpp
appl/reditor/workspace.hpp
cunit/cuReEdit.cpp
cunit/cuReSettings.cpp
gui/ReSettings.cpp
gui/ReSettings.hpp

index 341dd7f5568e1b12f113abdec0484e9d3d4d81e8..37c08fb302c69292a41312690c4b784d55530b7b 100644 (file)
@@ -114,11 +114,11 @@ ReLogger* MainWindow::logger() const {
  *
  * @return the current workspace
  */
-ReSettings* MainWindow::project() const {
+Project* MainWindow::project() const {
        return m_project;
 }
 
-ReSettings* MainWindow::workspace() const {
+Workspace* MainWindow::workspace() const {
        return m_workspace;
 }
 
index bb5757c16ceeb88ea975eddaf66526d47531e348..b9485f6e8e71ade35c2feef0ca882723d19321ce 100644 (file)
@@ -31,8 +31,8 @@ public:
        void changeWorkspace(const QString& path);
        void closeProject();
        void openFile(const QString& name);
-       Storage* project() const;
-       Storage* workspace() const;
+       Project* project() const;
+       Workspace* workspace() const;
        ReLogger* logger() const;
 
 public slots:
@@ -40,8 +40,8 @@ public slots:
 private:
        Ui::MainWindow *ui;
        ReFile* m_file;
-       Storage* m_project;
-       Storage* m_workspace;
+       Project* m_project;
+       Workspace* m_workspace;
        ReLogger* m_logger;
 };
 
index e088f47eb22b16618eb24ba7eebe7536abde116e..6bca375713480f56b004426b412e513ba5510013 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef PROJECT_HPP
 #define PROJECT_HPP
 
-class Project: public Storage {
+class Project: public ReSettings {
 public:
        Project(const QString& path, ReLogger* logger);
 };
index 8550f569a6659ec64d33e9718a574df7bf7ac079..d6a496a6aeafa2aba2dd909537179c4fa8d35333 100644 (file)
@@ -34,6 +34,64 @@ ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
            SLOT(openLastFile()));
        connect(ui->pushButtonOpenLastProject, SIGNAL(clicked()), this,
            SLOT(openLastProject()));
+       Workspace* workspace = mainWindow->workspace();
+       buildTableInfo(workspace, Workspace::KEY_HISTORY_FILES, true, m_files);
+       buildTableInfo(workspace, Workspace::KEY_HISTORY_PROJECTS, false,
+           m_projects);
+       buildTable("", m_files, ui->tableWidgetFiles);
+       buildTable("", m_projects, ui->tableWidgetProjects);
+}
+/**
+ * Builds the table from the table using a filter expression.
+ *
+ * @param filter       a filter expression with wildcards '*'
+ * @param lines                the full table info
+ * @param table                OUT: will be filled with all lines matching the filter
+ */
+void ProjectSelection::buildTable(const QString* filter, QStringList& lines,
+    QTableWidget* table) {
+       QStringList::const_iterator it;
+       for (it = lines.cbegin(); it != lines.cend(); ++it) {
+               bool matches = filter->isEmpty();
+               if (!matches) {
+                       if (filter->startsWith("*")) {
+
+                       } else {
+
+                       }
+               }
+               if (matches) {
+                       QStringList cols = it->split('\t');
+
+               }
+
+       }
+}
+
+/**
+ * Build the info for a table (last opened files or last opened projects).
+ *
+ * Note: the table shows a filtered part of this info.
+ *
+ * @param settings             the history container
+ * @param key                  the name of the history entry
+ * @param withDate             the file's name is part of the info
+ * @param tableContent OUT: the list containing the table info
+ */
+void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
+    bool withDate, QStringList& tableContent) {
+       settings->historyAsList(key, files);
+       QStringList::const_iterator it;
+       for (it = files.cbegin(); it != files.cend(); ++it) {
+               QFileInfo file(*it);
+               if (file.exists()) {
+                       QString info = file.baseName();
+                       if (withDate)
+                               info.append("\t").append(
+                                   file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
+                       info.append(file.dir());
+               }
+       }
 }
 
 /**
index 0c4913bc4129c90b5ea322685bf373b1d66f66b4..32b459e538d18a8bdc4e8cadd103bd8a9b986def 100644 (file)
@@ -31,11 +31,18 @@ public slots:
        void openLastProject();
        void selectDir();
        void selectFile();
+protected:
+       void buildTable(const QString* filter, QStringList& lines,
+           QTableWidget* table);
+       void buildTableInfo(ReSettings* settings, const char* key, bool withDate,
+           QStringList& tableContent);
 private:
        void error(const QString& message);
 private:
        Ui::ProjectSelection *ui;
        MainWindow* m_mainWindow;
+       QStringList m_files;
+       QStringList m_projects;
 };
 
 #endif // PROJECTSELECTION_HPP
index ede1294f0ff3783bd5dd0db3230fa3c6ac085bec..2d6441f81394a5114411ddf71358ec3225ccc420 100644 (file)
@@ -16,7 +16,7 @@ INCLUDEPATH += ../..
 SOURCES += \
         ../../gui/ReEdit.cpp \
         ../../gui/ReStateStorage.cpp \
-        ../../gui/ReStorage.cpp \
+        ../../gui/ReSettings.cpp \
         ../../base/ReFile.cpp \
        mainwindow.cpp \
        ../../base/ReLogger.cpp \
index 5b5c64e4cf5700806740bf101c6c907f57cb6e78..f13799709ee3fe5242a54aaa135434b83ac4b543 100644 (file)
@@ -11,6 +11,9 @@
 
 #include "reditor.hpp"
 
+const char* Workspace::KEY_HISTORY_FILES = "history.files";
+const char* Workspace::KEY_HISTORY_PROJECTS = "history.projecs";
+
 /**
  * Constructor.
  *
index 4be110b4820c1a92a9ffa862d51f4a3ad7f31a78..8776fed01a406dce083b9cecb512c38ba680f6d6 100644 (file)
 #ifndef WORKSPACE_HPP
 #define WORKSPACE_HPP
 
-class Workspace: public Storage {
+class Workspace: public ReSettings {
+public:
+       static const char* KEY_HISTORY_FILES;
+       static const char* KEY_HISTORY_PROJECTS;
 public:
        Workspace(const QString& path, ReLogger* logger);
 };
index 9fabc5ec00706f43c5c1c444caff81e99f43da46..ea7f7ebbd681cedda78b83ea051c2c27135a03e7 100644 (file)
@@ -18,8 +18,8 @@
 class TestReEdit: public ReTest, protected ReEdit {
 public:
        TestReEdit() :
-                       ReTest("ReEdit"),
-                       ReEdit(NULL) {
+                   ReTest("ReEdit"),
+                   ReEdit(NULL) {
                doIt();
        }
 
@@ -31,7 +31,7 @@ public:
                setLines(&m_lines);
        }
        void pushKey(int key, const QString& text = "",
-               Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
+           Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
                QKeyEvent event(QEvent::KeyPress, key, modifiers, text);
                keyPressEvent(&event);
        }
@@ -69,7 +69,7 @@ public:
                checkEqu(expectedCol, m_cursorCol);
        }
        void checkCursorPos(EditorAction action, int expectedLineNo,
-               int expectedCol) {
+           int expectedCol) {
                editorAction(action);
                checkEqu(expectedLineNo, m_cursorLineNo);
                checkEqu(expectedCol, m_cursorCol);
@@ -294,7 +294,7 @@ public:
                checkEqu("abcd", m_lines.lineAt(0));
                checkEqu("1234", m_lines.lineAt(1));
                checkEqu(-1, m_cursorCol);
-               checkEqu(2, m_cursorLineNo);
+               checkEqu(1, m_cursorLineNo);
 
                // wrong line numbers:
                init("abcd\n1234\nxy");
@@ -313,7 +313,7 @@ public:
                checkEqu("xy", m_lines.lineAt(2));
 
                log("ok");
-}
+       }
        virtual void run() {
                testDeleteLine();
                testDeleteText();
index f79c3f4795b5ececd810796c48bd32701c7a4e15..6f96ead9ec2b8fee94a9025f0658a5e0bec0fe4d 100644 (file)
 class TestReSettings: public ReTest {
 public:
        TestReSettings() :
-                       ReTest("ReSettings") {
+                   ReTest("ReSettings") {
                doIt();
        }
 
 public:
-       void testAddHistoryEntry(){
+       void testAddHistoryEntry() {
                QByteArray dir(ReFile::tempDir("resettings", NULL, false));
                ReFile::deleteTree((QString) dir, false, &m_logger);
                {
@@ -40,17 +40,19 @@ public:
                settings.historyAsList("digits", list);
                checkEqu("1 2 3", list.join(' '));
        }
-       void setSettings(ReSettings& settings){
-               settings.insertProperty(new ReProperty("level1.boolVal", "Boolean",
-                                                                                          "Boolean value for test", ReSettings::TRUE, PT_BOOL));
-               settings.insertProperty(new ReProperty("level1.intVal", "Integer",
-                                                                                          "Integer value for test", "4711", PT_INT, "[0,9999]"));
-               settings.insertProperty(new ReProperty("level2.strVal", "String",
-                                                                                          "String value for test", "crazy horse", PT_STRING));
-
+       void setSettings(ReSettings& settings) {
+               settings.insertProperty(
+                   new ReProperty("level1.boolVal", "Boolean",
+                       "Boolean value for test", ReSettings::TRUE, PT_BOOL));
+               settings.insertProperty(
+                   new ReProperty("level1.intVal", "Integer", "Integer value for test",
+                       "4711", PT_INT, "[0,9999]"));
+               settings.insertProperty(
+                   new ReProperty("level2.strVal", "String", "String value for test",
+                       "crazy horse", PT_STRING));
        }
 
-       void testBasic(){
+       void testBasic() {
                QByteArray dir(ReFile::tempDir("resettings", NULL, false));
                ReFile::deleteTree((QString) dir, false, &m_logger);
                ReSettings settings(dir, "test", &m_memoryLogger);
@@ -74,7 +76,7 @@ public:
                setSettings(settings2);
                settings2.changeValue("level1.boolVal", ReSettings::FALSE);
                settings2.changeValue("level1.intVal", "1234");
-               settings2.changeValue("level2.strVal", "pretty women");
+               settings2.changeValue("level2.strVal", "pretty woman");
                settings2.writeSettings();
 
                settings.readSettings();
index 2133768aef6e2b094d49dc93644538825d25fd10..fcea3be057d294194f0f2a6458cc65c5a898c4e7 100644 (file)
@@ -40,14 +40,16 @@ QString ReSettings::FALSE = "";
  * @param type the type of the property
  * @param limits       NULL or some rules for the property value
  */
-ReProperty::ReProperty(const char* name, const QString& title, const QString& description, const QString& defaultValue, RePropertyType type, const char* limits) :
-       m_name(name),
-       m_title(title),
-       m_description(description),
-       m_value(defaultValue),
-       m_defaultValue(defaultValue),
-       m_type(type),
-       m_limits(limits) {
+ReProperty::ReProperty(const char* name, const QString& title,
+    const QString& description, const QString& defaultValue,
+    RePropertyType type, const char* limits) :
+           m_name(name),
+           m_title(title),
+           m_description(description),
+           m_value(defaultValue),
+           m_defaultValue(defaultValue),
+           m_type(type),
+           m_limits(limits) {
 }
 
 /**
@@ -56,30 +58,27 @@ ReProperty::ReProperty(const char* name, const QString& title, const QString& de
  * @param error        OUT: NULL or the error message
  * @return <code>true</code>: the value is allowed<br>
  */
-bool ReProperty::isValid(const QString& value, QString* error)
-{
+bool ReProperty::isValid(const QString& value, QString* error) {
        bool rc = true;
        if (error != NULL)
                *error = "";
-       if (m_limits != NULL){
-               switch(m_type){
+       if (m_limits != NULL) {
+               switch (m_type) {
                case PT_BOOL:
                        break;
-               case PT_INT:
-               {
+               case PT_INT: {
                        int nValue = value.toInt(&rc);
-                       if (! rc){
+                       if (!rc) {
                                if (error != NULL)
                                        *error = QObject::tr("not an integer: ") + value;
                        } else {
                                int minimum, maximum;
-                               if (sscanf(m_limits, "[%d,%d]", &minimum, &maximum) == 2)
-                               {
-                                       if (nValue < minimum){
+                               if (sscanf(m_limits, "[%d,%d]", &minimum, &maximum) == 2) {
+                                       if (nValue < minimum) {
                                                rc = false;
                                                if (error != NULL)
                                                        *error = value + " < " + minimum;
-                                       } else if (nValue > maximum){
+                                       } else if (nValue > maximum) {
                                                rc = false;
                                                if (error != NULL)
                                                        *error = value + " < " + maximum;
@@ -103,14 +102,14 @@ bool ReProperty::isValid(const QString& value, QString* error)
  * @param path         the parent directory for the storage files
  * @param prefix       type of the storage: "proj" or "ws" (workspace)
  */
-ReSettings::ReSettings(const QString& path, const QString prefix, ReLogger* logger) :
-               m_path(path),
-               m_fileHistory(path + OS_SEPARATOR + prefix + ".history"),
-               m_fileSettings(
-                       path + OS_SEPARATOR + prefix + ".settings"),
-               m_settings(),
-               m_chapters(),
-               m_logger(logger) {
+ReSettings::ReSettings(const QString& path, const QString prefix,
+    ReLogger* logger) :
+           m_path(path),
+           m_fileHistory(path + OS_SEPARATOR + prefix + ".history"),
+           m_fileSettings(path + OS_SEPARATOR + prefix + ".settings"),
+           m_settings(),
+           m_chapters(),
+           m_logger(logger) {
 
 }
 
@@ -127,8 +126,9 @@ ReSettings::ReSettings(const QString& path, const QString prefix, ReLogger* logg
  * @param form the prefix of the key. If NULL the current form will be taken
  */
 void ReSettings::addHistoryEntry(const char* key, const QString& value,
-       char separator, int maxEntries) {
+    char separator, int maxEntries) {
        ReStateStorage store(m_fileHistory);
+       store.initForRead();
        store.addHistoryEntry(key, value, separator, maxEntries);
        store.close();
        store.flushMap();
@@ -145,10 +145,10 @@ bool ReSettings::boolValue(const char* name) {
        ReProperty* property = m_settings.value(name, NULL);
        if (property == NULL)
                m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_1, "missing bool property %s",
-                       name);
+                   name);
        else if (property->m_type != PT_BOOL)
                m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_2, "not a  bool property %s",
-                       name);
+                   name);
        else
                rc = !property->m_value.isEmpty();
        return rc;
@@ -160,17 +160,16 @@ bool ReSettings::boolValue(const char* name) {
  * @param name the name of the property
  * @param value        the new value
  */
-void ReSettings::changeValue(const char* name, const QString& value)
-{
+void ReSettings::changeValue(const char* name, const QString& value) {
        QString error;
        ReProperty* property = m_settings.value(name, NULL);
        if (property == NULL)
                m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_1, "unknown property: %s",
-                                          name);
+                   name);
        else if (!property->isValid(value, &error))
-               m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_2, "invalid value for %s: %s\n+++ %s",
-                                       name, value.toUtf8().constData(),
-                                          error.toUtf8().constData());
+               m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_2,
+                   "invalid value for %s: %s\n+++ %s", name,
+                   value.toUtf8().constData(), error.toUtf8().constData());
        else
                property->m_value = value;
 }
@@ -184,8 +183,9 @@ void ReSettings::changeValue(const char* name, const QString& value)
  * @return <code>list</code> (for chaining)
  */
 QStringList&ReSettings::historyAsList(const char* key, QStringList& list,
-       const char* form) {
+    const char* form) {
        ReStateStorage store(m_fileHistory);
+       store.initForRead();
        QStringList& rc = store.historyAsList(key, list, form);
        store.close();
        return rc;
@@ -219,10 +219,10 @@ int ReSettings::intValue(const char* name) {
        ReProperty* property = m_settings.value(name, NULL);
        if (property == NULL)
                m_logger->logv(LOG_ERROR, LOC_INT_VALUE_1, "missing int property %s",
-                       name);
+                   name);
        else if (property->m_type != PT_INT)
                m_logger->logv(LOG_ERROR, LOC_INT_VALUE_2, "not a  int property %s",
-                       name);
+                   name);
        else
                rc = property->m_value.toInt();
        return rc;
@@ -240,13 +240,12 @@ QString ReSettings::path() const {
 /**
  * Reads the configuration file.
  */
-void ReSettings::readSettings()
-{
+void ReSettings::readSettings() {
        QFile file(m_fileSettings);
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
-                       m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_1, "cannot open (%d): ",
-                                                  errno, m_fileSettings.toUtf8().constData());
-       else{
+               m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_1, "cannot open (%d): ",
+                   errno, m_fileSettings.toUtf8().constData());
+       else {
                QTextStream input(&file);
                int lineNo = 0;
                while (!input.atEnd()) {
@@ -254,31 +253,34 @@ void ReSettings::readSettings()
                        QString line = input.readLine();
                        int ix = line.indexOf('=');
                        if (ix < 0)
-                               m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_2, "missing '=': %s-%d: %s",
-                                       m_fileSettings.toUtf8().constData(), lineNo,
-                                                          line.mid(0, 20).toUtf8().constData());
-                       else if (ix == 0 || ix == 1 && line.at(0) == '!')
-                               m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_3, "line starts with '=': %s-%d: %s",
-                                       m_fileSettings.toUtf8().constData(), lineNo,
-                                                          line.mid(0, 20).toUtf8().constData());
+                               m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_2,
+                                   "missing '=': %s-%d: %s",
+                                   m_fileSettings.toUtf8().constData(), lineNo,
+                                   line.mid(0, 20).toUtf8().constData());
+                       else if (ix == 0 || (ix == 1 && line.at(0) == '!'))
+                               m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_3,
+                                   "line starts with '=': %s-%d: %s",
+                                   m_fileSettings.toUtf8().constData(), lineNo,
+                                   line.mid(0, 20).toUtf8().constData());
                        else {
                                QByteArray name;
                                QString value;
-                               if (line.at(ix-1) == '!'){
+                               if (line.at(ix - 1) == '!') {
                                        name = line.left(ix - 1).toUtf8();
                                        value = line.mid(ix + 1);
-                                       value.replace("\\\\", "\01").replace("\\n", "\n")
-                                                       .replace("\\r", "\r").replace('\01', '\\');
+                                       value.replace("\\\\", "\01").replace("\\n", "\n").replace(
+                                           "\\r", "\r").replace('\01', '\\');
                                } else {
                                        name = line.left(ix).toUtf8();
                                        value = line.mid(ix + 1);
                                }
                                ReProperty* property = m_settings.value(name, NULL);
-                               if (property != NULL){
-                                       switch(property->m_type){
+                               if (property != NULL) {
+                                       switch (property->m_type) {
                                        case PT_BOOL:
-                                               property->m_value = value.isEmpty() ? ReSettings::FALSE
-                                                                                                                 : ReSettings::TRUE;
+                                               property->m_value =
+                                                   value.isEmpty() ?
+                                                       ReSettings::FALSE : ReSettings::TRUE;
                                                break;
                                        case PT_INT:
                                                if (property->isValid(value))
@@ -309,10 +311,10 @@ QString ReSettings::stringValue(const char* name) {
        ReProperty* property = m_settings.value(name, NULL);
        if (property == NULL)
                m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_1,
-                       "missing string property %s", name);
+                   "missing string property %s", name);
        else if (property->m_type != PT_STRING)
                m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_2,
-                       "not a string property %s", name);
+                   "not a string property %s", name);
        else
                rc = property->m_value;
        return rc;
@@ -321,29 +323,28 @@ QString ReSettings::stringValue(const char* name) {
 /**
  * Writes the values into the configuration file.
  */
-void ReSettings::writeSettings()
-{
+void ReSettings::writeSettings() {
        QFile file(m_fileSettings);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
-                       m_logger->logv(LOG_ERROR, LOC_WRITE_SETTINGS_1, "cannot open (%d): ",
-                                                  errno, m_fileSettings.toUtf8().constData());
-       else{
+               m_logger->logv(LOG_ERROR, LOC_WRITE_SETTINGS_1, "cannot open (%d): ",
+                   errno, m_fileSettings.toUtf8().constData());
+       else {
                QTextStream out(&file);
-               QMap<const char*, ReProperty*>::const_iterator it;
-               for (it = m_settings.cbegin(); it != m_settings.cend(); ++it){
+               QMap<QByteArray, ReProperty*>::const_iterator it;
+               for (it = m_settings.cbegin(); it != m_settings.cend(); ++it) {
                        ReProperty* property = it.value();
-                       if (property->m_value == property->m_defaultValue){
+                       if (property->m_value == property->m_defaultValue) {
                                // we do not write the default value
                        } else if (it.value()->m_value.indexOf('\n') <= 0)
                                out << it.key() << "=" << it.value()->m_value << "\n";
-                       else{
+                       else {
                                QString value = it.value()->m_value;
-                               out << it.key() << "!=" << value.replace("\\", "\\\\")
-                                          .replace("\n", "\\n").replace("\r", "\\r") << "\n";
+                               out << it.key() << "!="
+                                   << value.replace("\\", "\\\\").replace("\n", "\\n").replace(
+                                       "\r", "\\r") << "\n";
                        }
                }
                file.close();
        }
 }
 
-
index 210c7bd5f95f09a76c1e051efbdc0cf78e21ef7c..3523d1f0d9ccb024f1a38db6db02f17f2e76c89b 100644 (file)
@@ -21,9 +21,9 @@ enum RePropertyType {
 
 class ReProperty {
 public:
-       ReProperty(const char* name, const QString& title, const QString& description,
-               const QString& defaultValue, RePropertyType type, const char* limits =
-                       NULL);
+       ReProperty(const char* name, const QString& title,
+           const QString& description, const QString& defaultValue,
+           RePropertyType type, const char* limits = NULL);
 public:
        bool isValid(const QString& value, QString* error = NULL);
 public:
@@ -44,11 +44,11 @@ public:
        ReSettings(const QString& path, const QString prefix, ReLogger* logger);
 public:
        void addHistoryEntry(const char* key, const QString& value, char separator,
-               int maxEntries);
+           int maxEntries);
        bool boolValue(const char* name);
        void changeValue(const char* name, const QString& value);
        QStringList& historyAsList(const char* key, QStringList& list,
-               const char* form = NULL);
+           const char* form = NULL);
        void insertProperty(ReProperty* property);
        int intValue(const char* name);
        QString path() const;
@@ -59,7 +59,7 @@ protected:
        QString m_path;
        QString m_fileHistory;
        QString m_fileSettings;
-       QMap<const char*, ReProperty*> m_settings;
+       QMap<QByteArray, ReProperty*> m_settings;
        QMap<QByteArray, QList<ReProperty*>*> m_chapters;
        ReLogger* m_logger;
 };