]> gitweb.hamatoma.de Git - reqt/commitdiff
View "Project Tree"
authorhama <hama@siduction.net>
Sun, 30 Aug 2015 11:00:57 +0000 (13:00 +0200)
committerhama <hama@siduction.net>
Sun, 30 Aug 2015 11:00:57 +0000 (13:00 +0200)
* new ReFileTree
* changeProject() opens dock "project tree"
* fix: filename in "open files/projects" project table

14 files changed:
appl/reditor/mainwindow.cpp
appl/reditor/mainwindow.hpp
appl/reditor/project.cpp
appl/reditor/project.hpp
appl/reditor/projectselection.cpp
appl/reditor/reditor.hpp
appl/reditor/reditor.pro
cunit/cuReSettings.cpp
gui/ReFileTree.cpp [new file with mode: 0644]
gui/ReFileTree.hpp [new file with mode: 0644]
gui/ReSettings.cpp
gui/ReSettings.hpp
gui/regui.hpp
remodules.hpp

index 98d517589a8505050fdcda39b3d1e086d252acc7..17e4bda9f2d09522e58942d634ec50d02fe157e4 100644 (file)
@@ -19,7 +19,9 @@ MainWindow::MainWindow(const char* workspace, const char* project,
            ui(new Ui::MainWindow),
            m_project(NULL),
            m_workspace(NULL),
-           m_logger(logger) {
+           m_logger(logger),
+           m_fileTree(NULL),
+           m_dockProjectTree(NULL) {
        if (workspace == NULL)
                workspace = QDir::homePath().toUtf8();
        changeWorkspace(workspace == NULL ? QDir::homePath() : workspace);
@@ -60,12 +62,24 @@ MainWindow::~MainWindow() {
  *
  * @param path the directory containing the project data
  */
-void MainWindow::changeProject(const QString& path) {
+void MainWindow::changeProject(QString path) {
        delete m_project;
-       m_project = new Project(path, m_logger);
+       if (path.endsWith(OS_SEPARATOR_STR))
+               path.remove(path.size() - 1, 1);
+       m_project = new Project(path, this);
        int maxEntries = m_workspace->intValue("history.max_projects");
        m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_PROJECTS, path, ';',
            maxEntries);
+       if (m_fileTree == NULL) {
+               m_fileTree = new ReFileTree(path, m_logger, this);
+               m_dockProjectTree = new QDockWidget("", this);
+               m_dockProjectTree->setWidget(m_fileTree);
+               addDockWidget(Qt::LeftDockWidgetArea, m_dockProjectTree);
+       }
+       m_fileTree->setPath(path);
+       m_dockProjectTree->setWindowTitle(
+           tr("Project") + " " + ReQStringUtils::nodeOf(path));
+
 }
 
 /**
index b9485f6e8e71ade35c2feef0ca882723d19321ce..d80c6f930c4f35b6316ca935fe40fb678bd8dbf3 100644 (file)
@@ -27,7 +27,7 @@ public:
        explicit MainWindow(const char* workspace, const char* project,
            ReLogger* logger, QWidget *parent = 0);
        ~MainWindow();
-       void changeProject(const QString& path);
+       void changeProject(QString path);
        void changeWorkspace(const QString& path);
        void closeProject();
        void openFile(const QString& name);
@@ -43,6 +43,8 @@ private:
        Project* m_project;
        Workspace* m_workspace;
        ReLogger* m_logger;
+       ReFileTree* m_fileTree;
+       QDockWidget* m_dockProjectTree;
 };
 
 #endif // MAINWINDOW_HPP
index 52629d87a9e5656b81e2dd2ec5fd78f1b579efe0..ffda4ee26f23cc71239aa2b050e6c8e64fd83b1f 100644 (file)
 
 #include "reditor.hpp"
 
+const char* Project::KEY_HISTORY_OPEN_FILES = "openFiles";
 /**
  * Constructor.
  *
  * @param path         the directory containing the configuration
  * @param logger       the logger
  */
-Project::Project(const QString& path, ReLogger* logger) :
-           ReSettings(path, ".reditor.proj", logger) {
+Project::Project(const QString& path, MainWindow* mainWindow) :
+           ReSettings(path, ".reditor.proj", mainWindow->logger()),
+           m_mainWindow(mainWindow) {
+       QString filename = topOfHistory(KEY_HISTORY_OPEN_FILES);
+       QFileInfo info(filename);
+       if (!filename.isEmpty() && info.exists() && !info.isDir()) {
+               m_mainWindow->openFile(filename);
+       }
+}
+
+/**
+ * Opens a file in the project directory.
+ *
+ * @param filename     the filename relative to the project directory
+ */
+void Project::openFile(const QString& filename) {
+       QString full = m_path + OS_SEPARATOR_STR + filename;
+       addHistoryEntry(KEY_HISTORY_OPEN_FILES, filename, ';', 1);
+       m_mainWindow->openFile(full);
 }
 
index 6bca375713480f56b004426b412e513ba5510013..dc0b2677784f77a0a495f5d14227e0721bc47fca 100644 (file)
 #ifndef PROJECT_HPP
 #define PROJECT_HPP
 
+class MainWindow;
+
 class Project: public ReSettings {
 public:
-       Project(const QString& path, ReLogger* logger);
+       static const char* KEY_HISTORY_OPEN_FILES;
+public:
+       Project(const QString& path, MainWindow* mainWindow);
+public:
+       void openFile(const QString& filename);
+
+private:
+       MainWindow* m_mainWindow;
 };
 
 #endif // PROJECT_HPP
index df22c557e69c741d7e03682b7bcf72087664fac5..1d7fd7248b2eda5584138454f9a95bb8d2b7abf7 100644 (file)
@@ -41,7 +41,7 @@ ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
        buildTableInfo(workspace, Workspace::KEY_HISTORY_PROJECTS, false,
            m_projects);
        buildTable("", m_files, ui->tableWidgetFiles);
-       buildTable(QString(""), m_projects, ui->tableWidgetProjects);
+       buildTable("", m_projects, ui->tableWidgetProjects);
 }
 
 /**
index 2088b69e6a638f834c35b3240c00b68a4302ff1c..e60607263258d0c0179dce347ac4f885041bec64 100644 (file)
@@ -11,6 +11,7 @@
 
 #ifndef REDITOR_HPP
 #define REDITOR_HPP
+#include <QDockWidget>
 #include "base/rebase.hpp"
 #include "gui/regui.hpp"
 #include "workspace.hpp"
index 2d6441f81394a5114411ddf71358ec3225ccc420..a47db111c59c423414d7a0ebfbc2046fdda29485 100644 (file)
@@ -18,6 +18,7 @@ SOURCES += \
         ../../gui/ReStateStorage.cpp \
         ../../gui/ReSettings.cpp \
         ../../base/ReFile.cpp \
+        ../../gui/ReFileTree.cpp \
        mainwindow.cpp \
        ../../base/ReLogger.cpp \
        ../../base/ReQStringUtils.cpp \
index 6f96ead9ec2b8fee94a9025f0658a5e0bec0fe4d..4900459555b99108eccf8fc9f07507d8d708c7e0 100644 (file)
@@ -85,7 +85,21 @@ public:
                checkEqu("pretty woman", settings.stringValue("level2.strVal"));
        }
 
+       void testTopOfHistory() {
+               QByteArray dir(ReFile::tempDir("resettings", NULL, false));
+               ReFile::deleteTree((QString) dir, false, &m_logger);
+               {
+                       ReSettings settings(dir, "test", &m_logger);
+                       settings.addHistoryEntry("fluid", "beer", ' ', 3);
+                       settings.addHistoryEntry("fluid", "wine", ' ', 3);
+               }
+               ReSettings settings(dir, "test", &m_logger);
+               checkEqu("wine", settings.topOfHistory("fluid"));
+               checkEqu("???", settings.topOfHistory("unknown", "???"));
+       }
+
        virtual void run() {
+               testTopOfHistory();
                testBasic();
                testAddHistoryEntry();
        }
diff --git a/gui/ReFileTree.cpp b/gui/ReFileTree.cpp
new file mode 100644 (file)
index 0000000..ea589d3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * storage.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 this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+enum {
+       LOC_BOOL_VALUE_1 = LOC_FIRST_OF(LOC_FILETREE), // 11901
+};
+
+/**
+ * Constructor.
+ *
+ * @param path
+ * @param logger
+ * @param parent
+ */
+ReFileTree::ReFileTree(const QString& path, ReLogger* logger, QWidget* parent) :
+           QTreeView(parent),
+           m_path(path),
+           m_logger(logger),
+           m_model() {
+       setPath(path);
+       setModel(&m_model);
+}
+
+/**
+ * Sets the directory path of the widget.
+ *
+ * @param path the path of the base directory shown in the tree widget
+ */
+void ReFileTree::setPath(const QString& path) {
+       m_model.setRootPath(path);
+       QModelIndex idx = m_model.index(path);
+       setRootIndex(idx);
+}
diff --git a/gui/ReFileTree.hpp b/gui/ReFileTree.hpp
new file mode 100644 (file)
index 0000000..8af9ec0
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * storage.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 this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef REFILETREE_HPP
+#define REFILETREE_HPP
+#include <QTreeView>
+#include <QFileSystemModel>
+
+/**
+ * Displays a directory with its files and subdirectories in a tree view.
+ */
+class ReFileTree: public QTreeView {
+public:
+       ReFileTree(const QString& path, ReLogger* logger, QWidget* parent = NULL);
+
+public:
+       void setPath(const QString& path);
+
+protected:
+       QString m_path;
+       ReLogger* m_logger;
+       QFileSystemModel m_model;
+};
+
+#endif // REFILETREE_HPP
index fcea3be057d294194f0f2a6458cc65c5a898c4e7..2f042b785a28e53f1e198ba8532b53ef4e2c7b62 100644 (file)
@@ -134,6 +134,37 @@ void ReSettings::addHistoryEntry(const char* key, const QString& value,
        store.flushMap();
 }
 
+/*
+ * Returns the first item of a history entry.
+ *
+ * A history entry contains a list of items.
+ *
+ * @param key                  the key in the map
+ * @param defaultValue if the key does not exist this value is returned
+ * @return                             <code>defaultValue</code>: the key does not exist<br>
+ *                                             otherwise: the first item of the history entry
+ */
+QString ReSettings::topOfHistory(const char* key, const QString& defaultValue) {
+       ReStateStorage store(m_fileHistory);
+       store.initForRead();
+       QString rc = store.map().value(key, "\t");
+       if (rc == "\t")
+               rc = defaultValue;
+       else if (rc.isEmpty())
+               rc = "";
+       else {
+               QChar separator = rc.at(0);
+               int end = rc.indexOf(separator, 1);
+               if (end < 0)
+                       rc = rc.mid(1);
+               else
+                       rc = rc.mid(1, end - 1);
+       }
+       store.close();
+       store.flushMap();
+       return rc;
+}
+
 /**
  * Returns the value of a boolean property.
  *
@@ -233,7 +264,7 @@ int ReSettings::intValue(const char* name) {
  *
  * @return the name of the storage's directory
  */
-QString ReSettings::path() const {
+const QString& ReSettings::path() const {
        return m_path;
 }
 
index 3523d1f0d9ccb024f1a38db6db02f17f2e76c89b..85fb008f2ee0332b7ae4b4292658820964acba35 100644 (file)
@@ -51,9 +51,10 @@ public:
            const char* form = NULL);
        void insertProperty(ReProperty* property);
        int intValue(const char* name);
-       QString path() const;
+       const QString& path() const;
        void readSettings();
        QString stringValue(const char* name);
+       QString topOfHistory(const char* key, const QString& defaultValue = "");
        void writeSettings();
 protected:
        QString m_path;
index f5dc636ab1fa6d4776093a8216b62ac9e9e42012..129b90bc7d1b1551aeb59c85d774fbb5a44ba551 100644 (file)
@@ -16,6 +16,7 @@
 #include "gui/ReGuiValidator.hpp"
 #include "gui/ReEdit.hpp"
 #include "gui/ReSettings.hpp"
+#include "gui/ReFileTree.hpp"
 /**
  * Tests whether a point is inside the rectangle (including border).
  * @param rect  rectangle to test
  * @return      <code>true</code>: the point lays inside the rectangle
  */
 inline bool rectContains(const QRect& rect, const QPoint& point,
-       const char* what = "") {
+    const char* what = "") {
 #if 1
        ReUseParameter(what);
        return point.x() >= rect.x() && point.y() >= rect.y()
-               && point.x() < rect.x() + rect.width()
-               && point.y() < rect.y() + rect.height();
+           && point.x() < rect.x() + rect.width()
+           && point.y() < rect.y() + rect.height();
 #else
        bool rc = point.x() >= rect.x();
        char reason = ' ';
index af5562c0f32c0b725e8a093e4b1893b134c584d9..491ccc02705cf47e48a380105e96ae183aa3523d 100644 (file)
@@ -30,6 +30,7 @@ enum {
        LOC_TRAVERSER,
        LOC_SETTINGS,
        LOC_FILE,
+       LOC_FILETREE,
 };
 #define LOC_FIRST_OF(moduleNo) (moduleNo*100+1)
 class RplModules {