]> gitweb.hamatoma.de Git - reqt/commitdiff
Storage settings
authorhama <hama@siduction.net>
Thu, 20 Aug 2015 22:21:50 +0000 (00:21 +0200)
committerhama <hama@siduction.net>
Thu, 20 Aug 2015 22:21:50 +0000 (00:21 +0200)
18 files changed:
appl/reditor/main.cpp
appl/reditor/mainwindow.cpp
appl/reditor/mainwindow.hpp
appl/reditor/project.cpp
appl/reditor/project.hpp
appl/reditor/projectselection.cpp
appl/reditor/projectselection.hpp
appl/reditor/reditor.hpp
appl/reditor/storage.cpp
appl/reditor/storage.hpp
appl/reditor/workspace.cpp
appl/reditor/workspace.hpp
base/ReFile.cpp
base/ReQStringUtil.cpp
cunit/cuReEdit.cpp
gui/ReEdit.cpp
gui/ReStateStorage.cpp
remodules.hpp

index a145881404946267fd4372e529876366c19eedc9..e11e6654181c9aff482d903d8e97469141b87eda 100644 (file)
@@ -32,7 +32,7 @@ int main(int argc, char *argv[]) {
        ReDebugAppender appender;
        appender.setAutoDelete(false);
        logger.addAppender(&appender);
-       MainWindow w(workspace, project);
+       MainWindow w(workspace, project, &logger);
        logger.log(LOG_INFO, 1, "start");
        w.show();
 
index 9c6e099733d66dd6b234f25be151e9b3db2d7498..9a847642e1c746748bdaaa87489368aacc6a9454 100644 (file)
 #include <QFileDialog>
 
 MainWindow::MainWindow(const char* workspace, const char* project,
-    QWidget *parent) :
+    ReLogger* logger, QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow),
+           m_project(NULL),
            m_workspace(NULL),
-           m_project(NULL) {
+           m_logger(logger) {
        if (workspace == NULL)
                workspace = QDir::homePath().toUtf8();
        changeWorkspace(workspace == NULL ? QDir::homePath() : workspace);
 
        QString proj(project == NULL ? "" : project);
        if (project == NULL) {
-               QStringList lastProjects = m_workspace->historyAsList("projects");
+               QStringList lastProjects;
+               m_workspace->historyAsList("projects", lastProjects);
                int ix = 0;
                while (proj.isEmpty() && ix < lastProjects.size()) {
                        QFileInfo dir(lastProjects.at(ix));
@@ -33,7 +35,7 @@ MainWindow::MainWindow(const char* workspace, const char* project,
                                proj = lastProjects.at(ix);
                }
                if (!proj.isEmpty())
-                       m_project = new Project(proj);
+                       changeProject(proj);
        }
 
        ui->setupUi(this);
@@ -60,7 +62,9 @@ MainWindow::~MainWindow() {
  */
 void MainWindow::changeProject(const QString& path) {
        delete m_project;
-       m_project = new Project(path);
+       m_project = new Project(path, m_logger);
+       int maxEntries = m_workspace->intValue("history.max_projects");
+       m_workspace->addHistoryEntry("projects", path, ';', maxEntries);
 }
 
 /**
@@ -70,7 +74,7 @@ void MainWindow::changeProject(const QString& path) {
  */
 void MainWindow::changeWorkspace(const QString& path) {
        delete m_workspace;
-       m_workspace = new Workspace(path);
+       m_workspace = new Workspace(path, m_logger);
 }
 
 /**
@@ -82,23 +86,16 @@ void MainWindow::openFile(const QString& name) {
        ReEdit* edit = ui->widget;
        edit->setLines(m_file);
        edit->setCursorLine(0);
+       int maxEntries = m_workspace->intValue("history.max_files");
+       m_workspace->addHistoryEntry("files", name, ';', maxEntries);
 }
 
 /**
  * Closes the current project.
  */
 void MainWindow::closeProject() {
-       if (!m_project.isEmpty()) {
-
-       }
-}
-
-/**
- * Opens a project.
- */
-void MainWindow::openProject(const QString& name) {
-       closeProject();
-       m_project = name;
+       delete m_project;
+       m_project = NULL;
 }
 
 /**
@@ -108,6 +105,9 @@ void MainWindow::open() {
        ProjectSelection dialog(this);
        dialog.exec();
 }
+ReLogger* MainWindow::logger() const {
+       return m_logger;
+}
 
 /**
  * Returns the current workspace.
index a80d532048fe0fbbfdf2eb87e2031e02b8e2c294..bb5757c16ceeb88ea975eddaf66526d47531e348 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <QMainWindow>
 #ifndef REBASE_HPP
-#include "base/rebase.hpp"
+#include "reditor.hpp"
 #endif
 namespace Ui {
 class MainWindow;
@@ -25,15 +25,15 @@ class MainWindow: public QMainWindow {
 
 public:
        explicit MainWindow(const char* workspace, const char* project,
-           QWidget *parent = 0);
+           ReLogger* logger, QWidget *parent = 0);
        ~MainWindow();
        void changeProject(const QString& path);
        void changeWorkspace(const QString& path);
        void closeProject();
        void openFile(const QString& name);
-       void openProject(const QString& name);
        Storage* project() const;
        Storage* workspace() const;
+       ReLogger* logger() const;
 
 public slots:
        void open();
@@ -42,6 +42,7 @@ private:
        ReFile* m_file;
        Storage* m_project;
        Storage* m_workspace;
+       ReLogger* m_logger;
 };
 
 #endif // MAINWINDOW_HPP
index b64f6d0f94efc3e551762c52eae1a44d743ef1fe..314cb1f6d81af9f3a0039dc7a4182254d57319b6 100644 (file)
@@ -1,14 +1,23 @@
 /*
- * Licence:
+ * project.cpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #include "reditor.hpp"
 
-Project::Project(const QString& path) :
-           Storage(path, "proj") {
+/**
+ * Constructor.
+ *
+ * @param path         the directory containing the configuration
+ * @param logger       the logger
+ */
+Project::Project(const QString& path, ReLogger* logger) :
+           Storage(path, "proj", logger) {
 }
 
index 776860235d10f9aabfcba0e77002cf01985808e2..e088f47eb22b16618eb24ba7eebe7536abde116e 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * project.hpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #ifndef PROJECT_HPP
@@ -11,7 +14,7 @@
 
 class Project: public Storage {
 public:
-       Project(const QString& path);
+       Project(const QString& path, ReLogger* logger);
 };
 
 #endif // PROJECT_HPP
index 8ccc1dc4918c81affccb82137da4c00f4216ac4f..8550f569a6659ec64d33e9718a574df7bf7ac079 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * projectselection.cpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #include "reditor.hpp"
@@ -63,7 +66,7 @@ void ProjectSelection::open() {
                        error("does not exists: " + name);
                else {
                        if (file.isDir())
-                               m_mainWindow->openProject(name);
+                               m_mainWindow->changeProject(name);
                        else
                                m_mainWindow->openFile(name);
                        close();
@@ -89,8 +92,8 @@ void ProjectSelection::openLastProject() {
  */
 void ProjectSelection::selectDir() {
        QString name = ui->lineEditOpen->text();
-       if (name.isEmpty())
-               name = m_mainWindow->project();
+       if (name.isEmpty() && m_mainWindow->project() != NULL)
+               name = m_mainWindow->project()->path();
        name = QFileDialog::getExistingDirectory(this,
            tr("Select Project Directory"), name);
        if (!name.isEmpty()) {
index 0439acc2385812c26ddd92c15f3d982681796b8b..0c4913bc4129c90b5ea322685bf373b1d66f66b4 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * projectselection.hpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #ifndef PROJECTSELECTION_HPP
index 47c57123be88664935c0da3f74bba43c12b1f158..4d083d1e10045b7f25a4fe9ef2b2a7b190ef7f6f 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * reditor.hpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #ifndef REDITOR_HPP
index 0acd8d97e145b2cc474cb56a62aa8907431844c7..f13c302c082aecbc00b9ac353b4eb09a4ac9eaa9 100644 (file)
 /*
- * Licence:
+ * storage.cpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #include "reditor.hpp"
 
+enum {
+       LOC_BOOL_VALUE_1 = LOC_FIRST_OF(LOC_STORAGE), // 11701
+       LOC_BOOL_VALUE_2,       // 11702
+       LOC_INT_VALUE_1,        // 11703
+       LOC_INT_VALUE_2,        // 11704
+       LOC_STRING_VALUE_1,     // 11705
+       LOC_STRING_VALUE_2,     // 11706
+};
+
 /**
  * Constructor.
  *
  * @param path         the parent directory for the storage files
  * @param prefix       type of the storage: "proj" or "ws" (workspace)
  */
-Storage::Storage(const QString& path, const QString prefix) :
+Storage::Storage(const QString& path, const QString prefix, ReLogger* logger) :
            m_path(path),
-           m_history(path + OS_SEPARATOR + ".reditor." + prefix + ".history"),
-           m_settings(path + OS_SEPARATOR + ".reditor." + prefix + ".settings") {
+           m_fileHistory(path + OS_SEPARATOR + ".reditor." + prefix + ".history"),
+           m_fileSettings(
+               path + OS_SEPARATOR + ".reditor." + prefix + ".settings"),
+           m_settings(),
+           m_chapters(),
+           m_logger(logger) {
 
 }
 
+/*
+ * Adds an entry to a history item at the first position.
+ *
+ * The entry will removed from the other positions.
+ *
+ * @param key          the key in the map
+ * @param value                the value to add
+ * @param separator    separates the entries in the history item
+ * @param maxEntries   the maximal count of entries in the history item.<br>
+ * If the number exceeds the last entries will be removed
+ * @param form the prefix of the key. If NULL the current form will be taken
+ */
 void Storage::addHistoryEntry(const char* key, const QString& value,
     char separator, int maxEntries) {
-       ReStateStorage store(m_history);
+       ReStateStorage store(m_fileHistory);
        store.addHistoryEntry(key, value, separator, maxEntries);
        store.close();
        store.flushMap();
 }
 
+/**
+ * Returns the value of a boolean property.
+ *
+ * @param name the name of the property
+ * @return the value of the property
+ */
+bool Storage::boolValue(const char* name) {
+       bool rc = false;
+       Property* property = m_settings.value(name, NULL);
+       if (property == NULL)
+               m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_1, "missing bool property %s",
+                   name);
+       else if (property->m_type != PT_BOOL)
+               m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_2, "not a  bool property %s",
+                   name);
+       else
+               rc = !property->m_value.isEmpty();
+       return rc;
+}
+/**
+ * Returns a history item as a list.
+ *
+ * @param key  key of the history item
+ * @param list OUT: the list is filled with the history entries
+ * @param form a common prefix of the key. If NULL the current form is used
+ * @return <code>list</code> (for chaining)
+ */
+QStringList&Storage::historyAsList(const char* key, QStringList& list,
+    const char* form) {
+       ReStateStorage store(m_fileHistory);
+       QStringList& rc = store.historyAsList(key, list, form);
+       store.close();
+       return rc;
+}
+
+/**
+ * Returns the value of an integer property.
+ *
+ * @param name the name of the property
+ * @return the value of the property
+ */
+int Storage::intValue(const char* name) {
+       int rc = 0;
+       Property* property = m_settings.value(name, NULL);
+       if (property == NULL)
+               m_logger->logv(LOG_ERROR, LOC_INT_VALUE_1, "missing int property %s",
+                   name);
+       else if (property->m_type != PT_INT)
+               m_logger->logv(LOG_ERROR, LOC_INT_VALUE_2, "not a  int property %s",
+                   name);
+       else
+               rc = property->m_value.toInt();
+       return rc;
+}
+
+/**
+ * Returns the directory containing the configuration data.
+ *
+ * @return the name of the storage's directory
+ */
+QString Storage::path() const {
+       return m_path;
+}
+
+/**
+ * Returns the value of a string property.
+ *
+ * @param name the name of the property
+ * @return the value of the property
+ */
+QString Storage::stringValue(const char* name) {
+       QString rc = "";
+       Property* property = m_settings.value(name, NULL);
+       if (property == NULL)
+               m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_1,
+                   "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);
+       else
+               rc = property->m_value;
+       return rc;
+}
+
+/**
+ * Inserts a property.
+ *
+ * @param property     the property to insert
+ */
+void Storage::insertProperty(Property* property) {
+       m_settings.insert(property->m_name, property);
+       QByteArray chapter(property->m_name);
+       int ix = chapter.lastIndexOf('.');
+       chapter = chapter.left(ix);
+       QList<Property*>* list = m_chapters.value(chapter, NULL);
+       if (list == NULL) {
+               m_chapters.insert(chapter, list = new QList<Property*>());
+       }
+       list->append(property);
+}
+
index 91475864b68b9674c00b318261f98ed39fbba22a..84f7c7bb2b1dad5ed905cc9a2483cb363b8d4347 100644 (file)
@@ -1,24 +1,69 @@
 /*
- * Licence:
+ * storage.hpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #ifndef STORAGE_HPP
 #define STORAGE_HPP
 
+enum PropertyType {
+       PT_UNDEF,
+       PT_INT,
+       PT_STRING,
+       PT_BOOL
+};
+
+class Property {
+public:
+       Property(const char* name, const QString& title, const QString& description,
+           const QString& defaultValue, PropertyType type, const char* limits =
+               NULL) :
+                   m_name(name),
+                   m_title(title),
+                   m_description(description),
+                   m_value(defaultValue),
+                   m_defaultValue(defaultValue),
+                   m_type(type),
+                   m_limits(limits) {
+       }
+
+public:
+       const char* m_name;
+       QString m_title;
+       QString m_description;
+       QString m_value;
+       QString m_defaultValue;
+       PropertyType m_type;
+       const char* m_limits;
+};
+
 class Storage {
 public:
-       Storage(const QString& path, const QString prefix);
+       Storage(const QString& path, const QString prefix, ReLogger* logger);
 public:
        void addHistoryEntry(const char* key, const QString& value, char separator,
            int maxEntries);
+       bool boolValue(const char* name);
+       QStringList& historyAsList(const char* key, QStringList& list,
+           const char* form = NULL);
+       int intValue(const char* name);
+       QString path() const;
+       QString stringValue(const char* name);
+protected:
+       void insertProperty(Property* property);
 protected:
        QString m_path;
-       QString m_history;
-       QString m_settings;
+       QString m_fileHistory;
+       QString m_fileSettings;
+       QMap<const char*, Property*> m_settings;
+       QMap<QByteArray, QList<Property*>*> m_chapters;
+       ReLogger* m_logger;
 };
 
 #endif // STORAGE_HPP
index 5f92d610e8f90b9a7b3bccca2ef469615a6e29ef..64d54a39c6e9a535b8860d5f007e97c59e8c5ec9 100644 (file)
@@ -1,15 +1,37 @@
 /*
- * Licence:
+ * workspace.cpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #include "reditor.hpp"
 
-Workspace::Workspace(const QString& path) :
-           Storage(path, "ws") {
-
+/**
+ * Constructor.
+ *
+ * @param path         the directory containing the configuration
+ * @param logger       the logger
+ */
+Workspace::Workspace(const QString& path, ReLogger* logger) :
+           Storage(path, "ws", logger) {
+       insertProperty(
+           new Property("editor.tabwidth", QObject::tr("Tabulator width"),
+               QObject::tr("Maximal length of the gap displaying a tabulator"),
+               "4", PT_INT, "[1,16]"));
+       insertProperty(
+           new Property("history.max_projects",
+               QObject::tr("Maximal project entries"),
+               QObject::tr(
+                   "Maximal number of projects in the 'last opened projects'"),
+               "20", PT_INT, "[1,100]"));
+       insertProperty(
+           new Property("history.max_files", QObject::tr("Maximal file entries"),
+               QObject::tr("Maximal number of files in the 'last opened files'"),
+               "20", PT_INT, "[1,100]"));
 }
 
index 460261988b52ccc20e9956af77ce9ceca2b129b5..4be110b4820c1a92a9ffa862d51f4a3ad7f31a78 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * workspace.hpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 
 #ifndef WORKSPACE_HPP
@@ -11,7 +14,7 @@
 
 class Workspace: public Storage {
 public:
-       Workspace(const QString& path);
+       Workspace(const QString& path, ReLogger* logger);
 };
 
 #endif // WORKSPACE_HPP
index 57efc9a52de79f9f7ed7de456b297ec144bd8c2d..31abc84ede59921826bb6f315fe74f0958a8c625 100644 (file)
@@ -142,9 +142,9 @@ void ReLines::insertPart(int lineNo, int col, const QString& text,
                if (col == 0)
                        replace(lineNo, text + current);
                else if (col < current.length())
-                       replace(lineNo, current.mid(0, col) + text + current.mid(col));
+                       replace(lineNo, current.left(col) + text + current.mid(col));
                else
-                       replace(lineNo, current.mid(0, col) + text);
+                       replace(lineNo, current.left(col) + text);
        }
 }
 
@@ -168,9 +168,9 @@ void ReLines::insertText(int lineNo, int col, const QString& text) {
                splitLine(lineNo, col, true);
                int newLines = 0;
                if (lineNo < length())
-                       insertPart(lineNo, col, text.mid(0, endOfLine), true);
+                       insertPart(lineNo, col, text.left(endOfLine), true);
                else
-                       insertLines(lineNo, text.mid(0, endOfLine), true);
+                       insertLines(lineNo, text.left(endOfLine), true);
                int lastEoLn = text.lastIndexOf('\n');
                if (lastEoLn != endOfLine) {
                        int oldCount = lineCount();
@@ -240,9 +240,9 @@ bool ReLines::removePart(int lineNo, int col, int count, bool withUndo) {
                        if (col == 0)
                                replace(lineNo, current.mid(count));
                        else if (col + count >= length)
-                               replace(lineNo, current.mid(0, col));
+                               replace(lineNo, current.left(col));
                        else
-                               replace(lineNo, current.mid(0, col) + current.mid(col + count));
+                               replace(lineNo, current.left(col) + current.mid(col + count));
                }
        }
        return rc;
@@ -297,8 +297,8 @@ void ReLines::splitLine(int lineNo, int col, bool withUndo) {
                                append(current.mid(col));
                        else
                                insert(lineNo + 1, current.mid(col));
-                       x = current.mid(0, col);
-                       replace(lineNo, current.mid(0, col));
+                       x = current.left(col);
+                       replace(lineNo, current.left(col));
                }
        }
 }
index 5773e1bd6b452eb5fef0ec1874b01b9f5388e23e..0b5b7c9186897e58dcf644e6b131b77c1e300aa6 100644 (file)
@@ -31,7 +31,7 @@ ReString ReQStringUtil::chomp(const ReString& text) {
        while (last >= 0 && (text[last] == '\n' || text[last] == '\r')) {
                last--;
        }
-       return last == text.length() - 1 ? text : text.mid(0, last + 1);
+       return last == text.length() - 1 ? text : text.left(last + 1);
 }
 
 /**
index 6ab65efdd39d53200693b3689f7b6ced4f46bbb2..9fabc5ec00706f43c5c1c444caff81e99f43da46 100644 (file)
@@ -1,9 +1,12 @@
 /*
- * Licence:
+ * cuReEdit.cpp
+ *
+ * License: Public Domain
  * You can use and modify this file without any restriction.
- * There is no warranty.
- * You also can use the licence from http://www.wtfpl.net/.
- * The original sources can be found on https://github.com/republib.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
  */
 #include "base/rebase.hpp"
 #include "gui/regui.hpp"
index b7dc779f41f550e823e3e5b515180474e751ac48..a787dc02d375be5d01aa4cd51006246759fd14cb 100644 (file)
@@ -36,11 +36,11 @@ inline int heightToFullHeight(int height) {
  * @param edit          the parent
  */
 ReLook::ReLook() :
-               m_font(NULL),
-               m_metrics(NULL),
-               m_foreground(FG_STANDARD),
-               m_background(BG_STANDARD),
-               m_edit(NULL) {
+           m_font(NULL),
+           m_metrics(NULL),
+           m_foreground(FG_STANDARD),
+           m_background(BG_STANDARD),
+           m_edit(NULL) {
 }
 
 /**
@@ -50,8 +50,8 @@ ReLook::ReLook() :
  * @param look  the presentation of the text
  */
 ReEditText::ReEditText(const QString& text, ReLook* look) :
-               m_text(text),
-               m_look(look) {
+           m_text(text),
+           m_look(look) {
 
 }
 
@@ -64,7 +64,7 @@ ReEditText::ReEditText(const QString& text, ReLook* look) :
  * @param edit      the edit field (parent)
  */
 void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
-       ReEdit* edit) {
+    ReEdit* edit) {
        if (lineNo == edit->cursorLineNo()) {
                for (int ix = 0; ix < paragraph.length(); ix++) {
                        ReEditText* text = paragraph.at(ix);
@@ -100,32 +100,32 @@ void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
  * @param parent    NULL or a widget which destroy the instance
  */
 ReEdit::ReEdit(QWidget* parent) :
-               QWidget(parent),
-               ReMouseCatcher(),
-               m_widthEdit(0),
-               m_heightEdit(0),
-               m_insertMode(true),
-               m_breakLines(false),
-               m_widthLineNumbers(50),
-               m_widthVScrollBar(16),
-               m_heightHScrollBar(16),
-               m_looks(),
-               m_standardBrush(new QBrush(Qt::SolidPattern)),
-               m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
-               m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
-               m_brushColors(),
-               m_standardPen(new QPen(Qt::SolidLine)),
-               m_standardFont(NULL),
-               m_standardMetrics(NULL),
-               m_fontColors(),
-               m_keyAlt(),
-               m_keyAltControl(),
-               m_keyAltControlShift(),
-               m_keyAltShift(),
-               m_keyControl(),
-               m_keyControlShift(),
-               m_keyRaw(),
-               m_keyShift() {
+           QWidget(parent),
+           ReMouseCatcher(),
+           m_widthEdit(0),
+           m_heightEdit(0),
+           m_insertMode(true),
+           m_breakLines(false),
+           m_widthLineNumbers(50),
+           m_widthVScrollBar(16),
+           m_heightHScrollBar(16),
+           m_looks(),
+           m_standardBrush(new QBrush(Qt::SolidPattern)),
+           m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
+           m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
+           m_brushColors(),
+           m_standardPen(new QPen(Qt::SolidLine)),
+           m_standardFont(NULL),
+           m_standardMetrics(NULL),
+           m_fontColors(),
+           m_keyAlt(),
+           m_keyAltControl(),
+           m_keyAltControlShift(),
+           m_keyAltShift(),
+           m_keyControl(),
+           m_keyControlShift(),
+           m_keyRaw(),
+           m_keyShift() {
        setFocusPolicy(Qt::WheelFocus);
        m_standardFont = new QFont("Courier");
        m_standardFont->setStyleHint(QFont::TypeWriter);
@@ -230,7 +230,7 @@ void ReEdit::assignKeysStandard() {
  * @param length        OUT: the slider length in pixel
  */
 void calcSliderSize(int size, int minSize, double sizeFactor, double posFactor,
-       int& position, int& length) {
+    int& position, int& length) {
        if (sizeFactor > 1.0)
                sizeFactor = 1.0;
        if (posFactor > 100)
@@ -277,8 +277,8 @@ int ReEdit::cursorLineNo() const {
  * @param posHorizontal     the position of the scrollbar as factor [0..1]
  */
 void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
-       double sizeVertical, double posVertical, double sizeHorizontal,
-       double posHorizontal) {
+    double sizeVertical, double posVertical, double sizeHorizontal,
+    double posHorizontal) {
        // We paint the vertical scrollbar:
        QBrush brush(*m_brushColors[ReLook::BG_SCROLLBAR], Qt::SolidPattern);
        painter.setBrush(brush);
@@ -287,14 +287,14 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
        static int width = 1;
        static int width2 = 2 * width;
        m_vScrollBar->setRect(x + width2, rect.top(), m_widthVScrollBar - width2,
-               rect.height() - m_heightHScrollBar - width);
+           rect.height() - m_heightHScrollBar - width);
        painter.drawRect(*m_vScrollBar);
 
        // We paint the horizontal scrollbar:
        m_hScrollBar->setRect(rect.left() + m_widthLineNumbers,
-               rect.bottom() - m_heightHScrollBar + width,
-               rect.width() - m_widthVScrollBar - m_widthLineNumbers,
-               m_heightHScrollBar - width2);
+           rect.bottom() - m_heightHScrollBar + width,
+           rect.width() - m_widthVScrollBar - m_widthLineNumbers,
+           m_heightHScrollBar - width2);
        painter.drawRect(*m_hScrollBar);
 
        // Slider (vertical)
@@ -303,36 +303,36 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
        int sliderSize = 0;
        int sliderPos = 0;
        calcSliderSize(rect.height() - m_heightHScrollBar, m_heightHScrollBar,
-               sizeVertical, posVertical, sliderPos, sliderSize);
+           sizeVertical, posVertical, sliderPos, sliderSize);
        m_vSlider->setRect(x + width2, rect.top() + sliderPos + width,
-               m_widthVScrollBar - width2, sliderSize - width2);
+           m_widthVScrollBar - width2, sliderSize - width2);
        painter.drawRect(*m_vSlider);
        int middle = m_vSlider->top() + m_vSlider->height() / 2;
        painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
-               middle);
+           middle);
        middle -= m_heightHScrollBar / 2 - 2;
        painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
-               middle);
+           middle);
        middle += m_heightHScrollBar - 4;
        painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
-               middle);
+           middle);
        // Slider (horizontal)
        calcSliderSize(rect.width() - m_widthLineNumbers - m_widthVScrollBar,
-               m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
-               sliderSize);
+           m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
+           sliderSize);
        m_hSlider->setRect(rect.left() + m_widthLineNumbers + sliderPos,
-               rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
-               m_heightHScrollBar - width2);
+           rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
+           m_heightHScrollBar - width2);
        painter.drawRect(*m_hSlider);
        middle = m_hSlider->left() + m_hSlider->width() / 2;
        painter.drawLine(middle, m_hSlider->top() + 2, middle,
-               m_hSlider->bottom() - 2);
+           m_hSlider->bottom() - 2);
        middle -= m_heightHScrollBar / 2 - 2;
        painter.drawLine(middle, m_hSlider->top() + 2, middle,
-               m_hSlider->bottom() - 2);
+           m_hSlider->bottom() - 2);
        middle += m_heightHScrollBar - 4;
        painter.drawLine(middle, m_hSlider->top() + 2, middle,
-               m_hSlider->bottom() - 2);
+           m_hSlider->bottom() - 2);
 }
 
 /**
@@ -420,7 +420,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                        m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1;
                }
                if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol), 1,
-                       true))
+                   true))
                        m_cursorLineNo = max(0, m_cursorLineNo - 1);
 
                break;
@@ -429,7 +429,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                int lastIx = lastColOfCurrent();
                if (m_cursorCol <= lastIx) {
                        m_lines->removePart(m_cursorLineNo, m_cursorCol + 1,
-                               lastIx - m_cursorCol, true);
+                           lastIx - m_cursorCol, true);
                        ensureCursorVisible();
                }
                break;
@@ -476,7 +476,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
  */
 void ReEdit::ensureCursorVisible() {
        if (m_cursorLineNo < m_firstLine
-               || m_cursorLineNo >= m_firstLine + pageSize()) {
+           || m_cursorLineNo >= m_firstLine + pageSize()) {
                reposition(m_cursorLineNo, m_cursorCol);
        }
        if (m_cursorCol < 0)
@@ -518,7 +518,7 @@ void ReEdit::keyPressEvent(QKeyEvent* event) {
                        break;
                }
        } else if (shift && !keyText.isEmpty() && key != Qt::Key_Delete
-               && key != Qt::Key_Backspace) {
+           && key != Qt::Key_Backspace) {
                m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText);
                m_cursorCol++;
        } else {
@@ -564,7 +564,7 @@ ReLines& ReEdit::lines() {
  * @return
  */
 ReLook* ReEdit::lookOf(ReLook::ForeGround foreground,
-       ReLook::BackGround background) {
+    ReLook::BackGround background) {
        int index = foreground * ReLook::BG_COUNT + background;
        ReLook* rc = m_looks[index];
        if (rc == NULL) {
@@ -591,8 +591,8 @@ ReLook* ReEdit::lookOf(ReLook::ForeGround foreground,
  */
 void ReEdit::mouseMoveEvent(QMouseEvent* event) {
        if (m_lastMousePosition.x() >= 0
-               && (handleHScrollBar(event, true, this)
-                       || handleVScrollBar(event, true, this))) {
+           && (handleHScrollBar(event, true, this)
+               || handleVScrollBar(event, true, this))) {
                emit repaint();
        }
 }
@@ -610,12 +610,12 @@ void ReEdit::mousePressEvent(QMouseEvent* event) {
        } else {
                QPoint position = event->pos();
                m_cursorLineNo = position.y()
-                       / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
+                   / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
                int x = position.x();
                int charWidth = m_standardMetrics->width('x');
                x -= m_widthLineNumbers;
                if (x >= 0
-                       && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
+                   && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
                        if (x <= +charWidth / 2)
                                m_cursorCol = m_firstCol - 1;
                        else
@@ -639,7 +639,7 @@ void ReEdit::mouseReleaseEvent(QMouseEvent* event) {
        m_lastMousePosition.setX(-1);
        m_lastMousePosition.setY(-1);
 }
-inline static double fraction(int a, int b, double exception){
+inline static double fraction(int a, int b, double exception) {
        double rc = b == 0 ? exception : (double) a / b;
        return rc;
 }
@@ -658,14 +658,14 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        int pageSize = (rect.height() - m_heightHScrollBar) / lineHeight;
        int charWidth = m_standardMetrics->averageCharWidth();
        int pageWidth = (rect.width() - m_widthVScrollBar - m_widthLineNumbers)
-               / charWidth;
+           / charWidth;
        int firstLine = m_firstLine;
        load(firstLine, pageSize, pageWidth, this);
        QPainter painter(this);
        ReLook* look = lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
        painter.setBrush(*look->m_brush);
        QRect editArea(rect.left() + m_widthLineNumbers, rect.top(),
-               rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
+           rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
        // Painting the frame of the edit field:
        painter.drawRect(editArea);
        // Painting the edit field area (text...)
@@ -680,13 +680,13 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        for (int ix = 0; ix < maxIx; ix++, lineNo++) {
                QString number = QString::number(lineNo) + ":";
                ReLook* look =
-                       lineNo == m_cursorLineNo + 1 ?
-                               lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
-                               lookStd;
+                   lineNo == m_cursorLineNo + 1 ?
+                       lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
+                       lookStd;
                int width = look->m_metrics->width(number);
                if (ix == 0)
                        y = rect.top() + look->m_metrics->height()
-                               - look->m_metrics->descent();
+                           - look->m_metrics->descent();
                painter.setFont(*look->m_font);
                painter.setPen(*look->m_pen);
                painter.drawText(left + m_widthLineNumbers - width - 5, y, number);
@@ -694,14 +694,14 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        }
        // We paint the cursor:
        if (m_cursorVisible && m_cursorLineNo >= firstLine
-               && m_cursorLineNo < firstLine + pageSize) {
+           && m_cursorLineNo < firstLine + pageSize) {
                ReParagraph* cursorPara = cursorParagraph();
                int col = min(m_cursorCol, cursorPara->m_columns - 1);
                if (col != -1)
                        col = indexToColumn(col, m_tabWidth,
-                               m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
+                           m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
                int x = rect.left() + m_widthLineNumbers + 1
-                       + (col + 1) * lookStd->m_metrics->width('x');
+                   + (col + 1) * lookStd->m_metrics->width('x');
                int y = rect.top() + (m_cursorLineNo - firstLine) * lineHeight;
                painter.setPen(*look->m_pen);
                painter.drawLine(x, y, x, y + lineHeight);
@@ -709,11 +709,11 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        int maxLines = max(1, m_lines->lineCount() - pageSize);
 
        drawScrollbars(painter, rect, fraction(pageSize, maxLines, 1.0),
-               fraction(m_firstLine, maxLines, 0.0),
-               fraction(m_screenWidth, m_maxCols, 1.0),
-               fraction(m_firstCol, max(0, m_maxCols - m_screenWidth), 0.0));
+           fraction(m_firstLine, maxLines, 0.0),
+           fraction(m_screenWidth, m_maxCols, 1.0),
+           fraction(m_firstCol, max(0, m_maxCols - m_screenWidth), 0.0));
        ReLogger::globalLogger()->logv(LOG_INFO, 3, "draw: %.4f",
-               double(clock() - start) / CLOCKS_PER_SEC);
+           double(clock() - start) / CLOCKS_PER_SEC);
 }
 
 /**
@@ -773,16 +773,16 @@ void ReEdit::setTabStrings(int tabWidth) {
  * Constructor.
  */
 ReParagraphs::ReParagraphs() :
-               m_builders(),
-               m_firstLine(0),
-               m_firstCol(0),
-               m_cursorLineNo(0),
-               m_cursorCol(-1),
-               m_lines(NULL),
-               m_list(),
-               m_maxCols(0),
-               m_screenWidth(0),
-               m_cursorVisible(true) {
+           m_builders(),
+           m_firstLine(0),
+           m_firstCol(0),
+           m_cursorLineNo(0),
+           m_cursorCol(-1),
+           m_lines(NULL),
+           m_list(),
+           m_maxCols(0),
+           m_screenWidth(0),
+           m_cursorVisible(true) {
 }
 
 /**
@@ -824,7 +824,7 @@ void ReParagraphs::clear() {
  *                                     expanded tabs
  */
 int ReParagraphs::columnToIndex(int column, int tabWidth,
-       const QString& string) {
+    const QString& string) {
        int rc = 0;
        if (column < 0)
                rc = -1;
@@ -854,7 +854,7 @@ int ReParagraphs::columnToIndex(int column, int tabWidth,
 ReParagraph* ReParagraphs::cursorParagraph() {
        ReParagraph* rc = NULL;
        if (m_cursorLineNo >= m_firstLine
-               && m_cursorLineNo < m_firstLine + m_list.length()) {
+           && m_cursorLineNo < m_firstLine + m_list.length()) {
                rc = m_list.at(m_cursorLineNo - m_firstLine);
        }
        return rc;
@@ -868,7 +868,7 @@ ReParagraph* ReParagraphs::cursorParagraph() {
  */
 int ReParagraphs::columnToIndex(int cursorCol) {
        int rc = columnToIndex(cursorCol, m_tabWidth,
-               m_lines->lineAt(m_cursorLineNo));
+           m_lines->lineAt(m_cursorLineNo));
        return rc;
 }
 
@@ -906,7 +906,7 @@ void ReParagraphs::draw(QPainter& painter, int top, int left) {
  * @return
  */
 int ReParagraphs::indexToColumn(int index, int tabWidth,
-       const QString& string) {
+    const QString& string) {
        int rc = 0;
        if (index >= 0) {
                int length = string.length();
@@ -973,13 +973,13 @@ void ReParagraphs::setLines(ReLines* lines) {
  * @param edit      the parent, the edit field
  */
 void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
-       ReEdit* edit) {
+    ReEdit* edit) {
        if (paragraph.length() == 0) {
                int firstCol = edit->m_firstCol;
                const QString& text = edit->lines().lineAt(lineNo);
                ReLook* look = edit->lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
                ReLook* lookTab = edit->lookOf(ReLook::FG_GREY_LIGHT,
-                       ReLook::BG_STANDARD);
+                   ReLook::BG_STANDARD);
                paragraph.m_columns = 0;
                int ixTab;
                ReEditText* part;
@@ -1006,7 +1006,7 @@ void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
                        length = tabs.length();
                        if (cursor + length > firstCol && cursor < maxCol) {
                                if (cursor < firstCol)
-                                       tabs = tabs.mid(0, length - firstCol - cursor);
+                                       tabs = tabs.left(length - firstCol - cursor);
                                paragraph.append(new ReEditText(tabs, lookTab));
                        }
                        cursor += length;
@@ -1066,14 +1066,14 @@ void ReParagraph::draw(QPainter& painter, int& top, int left) {
  * Constructor.
  */
 ReMouseCatcher::ReMouseCatcher() :
-               m_clickObjects(),
-               m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
-               m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
-               m_hSlider(new ClickPosition(CO_HSLIDER)),
-               m_vSlider(new ClickPosition(CO_VSLIDER)),
-               m_lastMousePosition(),
-               m_lastTopVSlider(0),
-               m_lastLeftHSlider(0) {
+           m_clickObjects(),
+           m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
+           m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
+           m_hSlider(new ClickPosition(CO_HSLIDER)),
+           m_vSlider(new ClickPosition(CO_VSLIDER)),
+           m_lastMousePosition(),
+           m_lastTopVSlider(0),
+           m_lastLeftHSlider(0) {
 
 }
 /**
@@ -1106,17 +1106,19 @@ void ReMouseCatcher::insertClickObject(ReMouseCatcher::ClickPosition* object) {
  * @return      <code>true</code>: the mouse click is inside the horizontal sb
  */
 bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
-       ReEdit* edit) {
+    ReEdit* edit) {
        QPoint pos = event->pos();
        bool rc = rectContains(*m_hScrollBar, pos, "hScrollBar")
-                       || (isDragged && m_hScrollBar->contains(m_lastMousePosition));
+           || (isDragged && m_hScrollBar->contains(m_lastMousePosition));
        if (rc) {
                if (isDragged) {
                        int distance = pos.x() - m_lastMousePosition.x();
                        int sliderPos = m_lastLeftHSlider + distance;
                        int moveGap = m_hScrollBar->width() - m_hSlider->width();
                        double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
-                       int col = roundInt((edit->m_maxCols - edit->m_screenWidth) * max(0.0, min(position, 1.0)));
+                       int col = roundInt(
+                           (edit->m_maxCols - edit->m_screenWidth)
+                               * max(0.0, min(position, 1.0)));
                        //ReLogger::globalLogger()->logv(LOG_INFO, 4,
                        //      "x: %d dist: %d last: %d slPos: %d pos: %.2f gap: %d col: %d / %d scw: %d",
                        //      pos.x(), distance, m_lastLeftHSlider, sliderPos, position, moveGap,
@@ -1141,10 +1143,10 @@ bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
  * @return          <code>true</code>: the mouse click is inside the vertical sb
  */
 bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged,
-       ReEdit* edit) {
+    ReEdit* edit) {
        QPoint pos = event->pos();
        bool rc = rectContains(*m_vScrollBar, pos, "vScrollBar")
-               || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
+           || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
        if (rc) {
                if (isDragged) {
                        int distance = pos.y() - m_lastMousePosition.y();
@@ -1152,8 +1154,8 @@ bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged,
                        int moveGap = m_vScrollBar->height() - m_vSlider->height();
                        double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
                        int line = roundInt(
-                               (edit->lines().lineCount() - edit->pageSize())
-                                       * max(0.0, min(position, 1.0)));
+                           (edit->lines().lineCount() - edit->pageSize())
+                               * max(0.0, min(position, 1.0)));
                        edit->reposition(line, edit->m_cursorCol);
                } else {
                        if (pos.y() < m_vSlider->top())
index b0c88c76cf395da4dd02c454366714062fff3ef9..94a4f386cc25584dbb0d955bf6823375c95ed958 100644 (file)
@@ -155,7 +155,7 @@ bool ReStateStorage::initForRead() {
                        int ixAssignment = line.indexOf('=');
                        if (ixAssignment > 0) {
                                value = line.mid(ixAssignment + 1);
-                               QByteArray key = line.mid(0, ixAssignment).toUtf8();
+                               QByteArray key = line.left(ixAssignment).toUtf8();
                                m_map.insert(key, value);
                        }
                }
index eeadd552d514f2dd2919a26bfa237218fb380fce..ee1cb35fcf5b616f0a98e3b3b12f2142ea15a0b3 100644 (file)
 #define RPLMODULES_HPP
 
 enum {
-   LOC_LOGGER = 101, LOC_CONFIG, LOC_CONTAINER, LOC_EXCEPTION, LOC_TEST, // 105
-      LOC_TCPSERVER,
-      LOC_TCPCLIENT,
-      LOC_TCPPEER,
-      LOC_TERMINATOR,
-      LOC_ASTREE, // 110
-      LOC_ASCLASSES,
-      LOC_LEXER,
-      LOC_SOURCE,
-      LOC_VM,
-      LOC_MFPARSER, // 115
-      LOC_TRAVERSER,
+       LOC_LOGGER = 101, LOC_CONFIG, LOC_CONTAINER, LOC_EXCEPTION, LOC_TEST, // 105
+       LOC_TCPSERVER,
+       LOC_TCPCLIENT,
+       LOC_TCPPEER,
+       LOC_TERMINATOR,
+       LOC_ASTREE, // 110
+       LOC_ASCLASSES,
+       LOC_LEXER,
+       LOC_SOURCE,
+       LOC_VM,
+       LOC_MFPARSER, // 115
+       LOC_TRAVERSER,
+       LOC_STORAGE
 };
 #define LOC_FIRST_OF(moduleNo) (moduleNo*100+1)
 class RplModules {