]> gitweb.hamatoma.de Git - reqt/commitdiff
ReEditor, ReMatcher
authorhama <hama@siduction.net>
Sat, 29 Aug 2015 00:06:29 +0000 (02:06 +0200)
committerhama <hama@siduction.net>
Sat, 29 Aug 2015 00:06:29 +0000 (02:06 +0200)
* ReEditor: open last file/project works
* ReMatcher works

appl/reditor/mainwindow.cpp
appl/reditor/projectselection.cpp
appl/reditor/projectselection.hpp
appl/reditor/projectselection.ui
appl/reditor/workspace.cpp
appl/refind/dialogoptions.ui
base/ReQStringUtils.cpp
base/ReQStringUtils.hpp
cunit/allTests.cpp
cunit/cuReQStringUtils.cpp

index 37c08fb302c69292a41312690c4b784d55530b7b..98d517589a8505050fdcda39b3d1e086d252acc7 100644 (file)
@@ -64,7 +64,8 @@ void MainWindow::changeProject(const QString& path) {
        delete m_project;
        m_project = new Project(path, m_logger);
        int maxEntries = m_workspace->intValue("history.max_projects");
-       m_workspace->addHistoryEntry("projects", path, ';', maxEntries);
+       m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_PROJECTS, path, ';',
+           maxEntries);
 }
 
 /**
@@ -87,7 +88,8 @@ void MainWindow::openFile(const QString& name) {
        edit->setLines(m_file);
        edit->setCursorLine(0);
        int maxEntries = m_workspace->intValue("history.max_files");
-       m_workspace->addHistoryEntry("files", name, ';', maxEntries);
+       m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_FILES, name, ';',
+           maxEntries);
 }
 
 /**
index d6a496a6aeafa2aba2dd909537179c4fa8d35333..7124e104aeb8e8970897c6d2fb3a8fbf98cbcd2a 100644 (file)
@@ -34,13 +34,29 @@ ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
            SLOT(openLastFile()));
        connect(ui->pushButtonOpenLastProject, SIGNAL(clicked()), this,
            SLOT(openLastProject()));
+       connect(ui->lineEditFilterLastFile, SIGNAL(textChanged(QString))), this, SLOT(
+           textChanged(QString));
        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);
+       buildTable(QString(""), m_projects, ui->tableWidgetProjects);
 }
+
+/**
+ * Destructor.
+ */
+ProjectSelection::~ProjectSelection() {
+       delete ui;
+}
+void ProjectSelection::textChangedFilterFiles(const QString& text) {
+
+}
+void ProjectSelection::textChangedFilterProjects(const QString& text) {
+
+}
+
 /**
  * Builds the table from the table using a filter expression.
  *
@@ -48,23 +64,48 @@ ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
  * @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,
+void ProjectSelection::buildTable(const QString& filter, QStringList& lines,
     QTableWidget* table) {
        QStringList::const_iterator it;
+       int rowCount = 0;
        for (it = lines.cbegin(); it != lines.cend(); ++it) {
-               bool matches = filter->isEmpty();
+               bool matches = filter.isEmpty();
                if (!matches) {
-                       if (filter->startsWith("*")) {
+                       //@ToDo: coding
+                       if (filter.startsWith("*")) {
+
+                       } else {
+
+                       }
+               }
+               if (matches)
+                       rowCount++;
+       }
+       table->setRowCount(rowCount);
+       int row = -1;
+       for (it = lines.cbegin(); it != lines.cend(); ++it) {
+               bool matches = filter.isEmpty();
+               if (!matches) {
+                       //@ToDo: coding
+                       if (filter.startsWith("*")) {
 
                        } else {
 
                        }
                }
                if (matches) {
+                       row++;
                        QStringList cols = it->split('\t');
-
+                       for (int col = 0; col < cols.size(); col++) {
+                               QTableWidgetItem* item = table->item(row, col);
+                               if (item != NULL)
+                                       item->setText(cols.at(col));
+                               else {
+                                       item = new QTableWidgetItem(cols.at(col));
+                                       table->setItem(row, col, item);
+                               }
+                       }
                }
-
        }
 }
 
@@ -80,6 +121,7 @@ void ProjectSelection::buildTable(const QString* filter, QStringList& lines,
  */
 void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
     bool withDate, QStringList& tableContent) {
+       QStringList files;
        settings->historyAsList(key, files);
        QStringList::const_iterator it;
        for (it = files.cbegin(); it != files.cend(); ++it) {
@@ -89,17 +131,12 @@ void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
                        if (withDate)
                                info.append("\t").append(
                                    file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
-                       info.append(file.dir());
+                       info.append("\t").append(file.path());
+                       tableContent.append(info);
                }
        }
 }
 
-/**
- * Destructor.
- */
-ProjectSelection::~ProjectSelection() {
-       delete ui;
-}
 /**
  * Shows an error message.
  *
@@ -136,15 +173,27 @@ void ProjectSelection::open() {
  * Opens the selected recently opened file.
  */
 void ProjectSelection::openLastFile() {
-
+       openSelectedItem(ui->tableWidgetFiles);
 }
+
 /**
  * Opens the selected recently opened project (project directory).
  */
 void ProjectSelection::openLastProject() {
-
+       openSelectedItem(ui->tableWidgetProjects);
 }
 
+QString ProjectSelection::openSelectedItem(QTableWidget* table) {
+       int row = max(0, table->currentRow());
+       if (row < table->rowCount()) {
+               QString file;
+               int colPath = table->columnCount() - 1;
+               file = table->item(row, colPath)->text() + OS_SEPARATOR_STR
+                   + table->item(row, 0)->text();
+               ui->lineEditOpen->setText(file);
+               open();
+       }
+}
 /**
  * Selects a directory (project directory) with an open dialog.
  */
index 32b459e538d18a8bdc4e8cadd103bd8a9b986def..c0ee0dd7cb8e09890350f2fe38cc7fe12ad64ece 100644 (file)
@@ -11,9 +11,9 @@
 
 #ifndef PROJECTSELECTION_HPP
 #define PROJECTSELECTION_HPP
-
+#include "reditor.hpp"
 #include <QDialog>
-
+#include <QTableWidget>
 namespace Ui {
 class ProjectSelection;
 }
@@ -32,10 +32,13 @@ public slots:
        void selectDir();
        void selectFile();
 protected:
-       void buildTable(const QString* filter, QStringList& lines,
+       void buildTable(const QString& filter, QStringList& lines,
            QTableWidget* table);
        void buildTableInfo(ReSettings* settings, const char* key, bool withDate,
            QStringList& tableContent);
+       QString openSelectedItem(QTableWidget* table);
+       void textChangedFilterFiles(const QString& text);
+       void textChangedFilterProjecs(const QString& text);
 private:
        void error(const QString& message);
 private:
index baf7cd2fe63444f12758645af7992b871b578e54..5897074c1cdc9b4939bb4bc4b7b5d6e9cd2a3d5e 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>982</width>
+    <width>1034</width>
     <height>703</height>
    </rect>
   </property>
@@ -77,6 +77,9 @@
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
+     <property name="handleWidth">
+      <number>3</number>
+     </property>
      <widget class="QWidget" name="layoutWidget">
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
@@ -113,6 +116,12 @@ Use wildcards: '*' (any string) and '?' (any character)</string>
        </item>
        <item>
         <widget class="QTableWidget" name="tableWidgetFiles">
+         <property name="mouseTracking">
+          <bool>false</bool>
+         </property>
+         <property name="editTriggers">
+          <set>QAbstractItemView::NoEditTriggers</set>
+         </property>
          <property name="columnCount">
           <number>3</number>
          </property>
@@ -124,7 +133,7 @@ Use wildcards: '*' (any string) and '?' (any character)</string>
          </attribute>
          <column>
           <property name="text">
-           <string>Name</string>
+           <string>File</string>
           </property>
          </column>
          <column>
@@ -134,7 +143,7 @@ Use wildcards: '*' (any string) and '?' (any character)</string>
          </column>
          <column>
           <property name="text">
-           <string>Parent</string>
+           <string>Directory</string>
           </property>
          </column>
         </widget>
@@ -262,7 +271,7 @@ Use wildcards: '*' (any string) and '?' (any character)</string>
             <string>Opens the selected last opened project (Control-P)</string>
            </property>
            <property name="text">
-            <string>Open project</string>
+            <string>Open Project</string>
            </property>
            <property name="shortcut">
             <string>Ctrl+P</string>
index f13799709ee3fe5242a54aaa135434b83ac4b543..809c0114ed9445fcec5da4385c0d7893ceac47ff 100644 (file)
@@ -11,8 +11,8 @@
 
 #include "reditor.hpp"
 
-const char* Workspace::KEY_HISTORY_FILES = "history.files";
-const char* Workspace::KEY_HISTORY_PROJECTS = "history.projecs";
+const char* Workspace::KEY_HISTORY_FILES = "files";
+const char* Workspace::KEY_HISTORY_PROJECTS = "projecs";
 
 /**
  * Constructor.
index 03fa9a72e554e47c51185424569ad941bf00df5a..55660461016e8772abb61c12bbc48b4783f61684 100644 (file)
                <string>...</string>
               </property>
               <property name="icon">
-               <iconset resource="refind.qrc">
+               <iconset resource="../reditor/editor.qrc">
                 <normaloff>:/main/icons/layout_add.png</normaloff>:/main/icons/layout_add.png</iconset>
               </property>
              </widget>
    </item>
   </layout>
  </widget>
- <resources>
-  <include location="refind.qrc"/>
- </resources>
+ <resources/>
  <connections>
   <connection>
    <sender>buttonBox</sender>
index e1f5d25f2ae01c3cd31436e578a987f56deda4ef..312a5b94503909f949c64c9d2102ba5b9ed2337c 100644 (file)
@@ -179,7 +179,8 @@ int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix,
  * @return      0: no date found<br>
  *              otherwise: the length of the date in the string
  */
-int ReQStringUtils::lengthOfDate(const ReString& text, int start, QDate* value) {
+int ReQStringUtils::lengthOfDate(const ReString& text, int start,
+    QDate* value) {
        uint day = 0;
        uint month = 0;
        uint year = 0;
@@ -290,7 +291,8 @@ int ReQStringUtils::lengthOfDateTime(const ReString& text, int start,
  * @return  0: no date found<br>
  *          otherwise: the length of the date in the string
  */
-int ReQStringUtils::lengthOfTime(const ReString& text, int start, QTime* value) {
+int ReQStringUtils::lengthOfTime(const ReString& text, int start,
+    QTime* value) {
        uint hour = 0;
        uint minute = 0;
        uint sec = 0;
@@ -809,3 +811,72 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) {
        return rc;
 }
 
+/**
+ * Constructor.
+ *
+ * @param pattern      a pattern with wildcards '*' (any string)
+ * @param anchored     <code>true<code>: the pattern starts at the strings start<br>
+ *                                     <code>false<code>: the pattern can start anywhere in the string<br>
+ */
+
+ReMatcher::ReMatcher(const QString& pattern, bool anchored) :
+           m_needles(pattern.split(QChar('*'))),
+           m_restLengths(),
+           m_anchored(anchored) {
+       for (int ix = 0; ix < m_needles.size(); ix++) {
+               m_restLengths.append(0);
+       }
+       int sum = 0;
+       for (int ix = m_needles.size() - 1; ix >= 0; ix--) {
+               int size = m_needles.at(ix).size();
+               m_restLengths.append(size + sum);
+               sum += size;
+       }
+}
+
+/**
+ * Destructor.
+ */
+ReMatcher::~ReMatcher() {
+}
+
+/**
+ * Tests whether the given string matches the pattern.
+ *
+ * @param text the text to test
+ * @return             <code>true</code>: the pattern matches
+ */
+bool ReMatcher::matches(const QString& text) {
+       bool found = false;
+       if (m_anchored)
+               found = matches(text, 0, 0);
+       else {
+               found = text.startsWith(m_needles.at(0));
+               if (found && m_needles.size() > 1)
+                       found = matches(text, m_needles.at(0).length(), 1);
+       }
+       return found;
+}
+
+/**
+ * Recursive matching test.
+ *
+ * @param text                 text to inspect
+ * @param textIndex            the first index in <code>text</code> to inspect
+ * @param needleIndex  the index of the pattern part to test
+ * @return                             <code>true</code>: the needles from the given index
+ *                                             up to the last index matches
+ */
+bool ReMatcher::matches(const QString& text, int textIndex, int needleIndex) {
+       int ix = textIndex;
+       QString needle = m_needles.at(needleIndex);
+       bool found = text.size() - textIndex >= m_restLengths.at(needleIndex);
+       while (!found && (ix = text.indexOf(needle, textIndex)) >= 0) {
+               textIndex = ix;
+               if (needleIndex >= m_needles.size() - 1)
+                       found = true;
+               else
+                       found = matches(text, ix + needle.length(), needleIndex);
+       }
+       return found;
+}
index 0552f9d15aa8e6a6acaf10bf30d4ace5b36527cf..e92915020ef87d5b8fdd8683daa589a7cc816800 100644 (file)
@@ -31,6 +31,7 @@ public:
            10, uint64_t* value = NULL);
        static int lengthOfUInt(const ReString& text, int start, int radix,
            uint* pValue);
+       static bool match(const QString& heap, const QStringList& needles);
        /**
         * Returns the path with native path separators.
         *
@@ -102,4 +103,19 @@ private:
        QDateTime m_dateTime;
 };
 
+class ReMatcher {
+public:
+       ReMatcher(const QString& pattern, bool anchored = false);
+       virtual ~ReMatcher();
+public:
+       virtual bool matches(const QString& text);
+protected:
+       bool matches(const QString& text, int textIndex, int needleIndex);
+protected:
+       QStringList m_needles;
+       // m_restLengths[ix] = sum(m_needles[ix..last].size()
+       QList<int> m_restLengths;
+       bool m_anchored;
+};
+
 #endif // RPLQSTRING_HPP
index 2010274b2c4acdaeae4e950d4a13b1c712abea8e..749e4ff763aeea3012150d377ea0cc92cfb0b052 100644 (file)
@@ -39,10 +39,10 @@ static void testBase() {
        void testReWriter();
        void testReFile();
        void testReFileUtils();
+       testReQStringUtil();
        testReFile();
        testReFileUtils();
        if (s_allTest) {
-               testReQStringUtil();
                testReByteStorage();
                testReCharPtrMap();
                testReConfig();
@@ -85,8 +85,8 @@ static void testOs() {
 
 }
 void allTests() {
-       testGui();
        testBase();
+       testGui();
        if (s_allTest) {
                testBase();
                testMath();
index 3c06e38bd584c6597d700fa9df47a08a137cd31f..513cb5266ef827ea04a9da8e0e025d993383f0c9 100644 (file)
@@ -17,7 +17,7 @@
 class TestReQStringUtil: public ReTest {
 public:
        TestReQStringUtil() :
-                       ReTest("ReQStringUtil") {
+                   ReTest("ReQStringUtil") {
                doIt();
        }
 
@@ -35,19 +35,20 @@ public:
        void testLengthOfUInt64() {
                quint64 value = -3;
                checkEqu(1,
-                       ReQStringUtils::lengthOfUInt64(ReString("0"), 0, 10, &value));
+                   ReQStringUtils::lengthOfUInt64(ReString("0"), 0, 10, &value));
                checkEqu(int64_t(0), value);
                checkEqu(3, ReQStringUtils::lengthOfUInt64("x432", 1, 10, &value));
                checkEqu(int64_t(432LL), value);
                checkEqu(3, ReQStringUtils::lengthOfUInt64("x432 x", 1, 10, &value));
                checkEqu(int64_t(432LL), value);
-               checkEqu(3, ReQStringUtils::lengthOfUInt64("x432fabc x", 1, 10, &value));
+               checkEqu(3,
+                   ReQStringUtils::lengthOfUInt64("x432fabc x", 1, 10, &value));
                checkEqu(int64_t(432LL), value);
                checkEqu(16,
-                       ReQStringUtils::lengthOfUInt64("a1234567890123567", 1, 10, &value));
+                   ReQStringUtils::lengthOfUInt64("a1234567890123567", 1, 10, &value));
                checkEqu(int64_t(1234567890123567LL), value);
                checkEqu(10,
-                       ReQStringUtils::lengthOfUInt64("x1234abcdef", 1, 16, &value));
+                   ReQStringUtils::lengthOfUInt64("x1234abcdef", 1, 16, &value));
                checkEqu(int64_t(0x1234abcdefLL), value);
                checkEqu(3, ReQStringUtils::lengthOfUInt64("432", 0, 8, &value));
                checkEqu(int64_t(0432LL), value);
@@ -84,24 +85,27 @@ public:
                checkEqu(1, ReQStringUtils::lengthOfReal(ReString(" 0"), 1, &value));
                checkEqu(0.0, value);
                checkEqu(17,
-                       ReQStringUtils::lengthOfReal(ReString("X12345678901234567"), 1,
-                               &value));
+                   ReQStringUtils::lengthOfReal(ReString("X12345678901234567"), 1,
+                       &value));
                checkEqu(12345678901234567.0, value);
                checkEqu(2, ReQStringUtils::lengthOfReal(ReString(".5"), 0, &value));
                checkEqu(0.5, value);
-               checkEqu(5, ReQStringUtils::lengthOfReal(ReString("2.5e2x"), 0, &value));
+               checkEqu(5,
+                   ReQStringUtils::lengthOfReal(ReString("2.5e2x"), 0, &value));
                checkEqu(250.0, value);
-               checkEqu(6, ReQStringUtils::lengthOfReal(ReString("2.5e+2"), 0, &value));
+               checkEqu(6,
+                   ReQStringUtils::lengthOfReal(ReString("2.5e+2"), 0, &value));
                checkEqu(250.0, value);
                checkEqu(7,
-                       ReQStringUtils::lengthOfReal(ReString("2.5E-33"), 0, &value));
+                   ReQStringUtils::lengthOfReal(ReString("2.5E-33"), 0, &value));
                checkEqu(2.5e-33, value);
 
                checkEqu(3, ReQStringUtils::lengthOfReal(ReString("2.5E"), 0, &value));
                checkEqu(2.5, value);
                checkEqu(3, ReQStringUtils::lengthOfReal(ReString("2.5E+"), 0, &value));
                checkEqu(2.5, value);
-               checkEqu(3, ReQStringUtils::lengthOfReal(ReString("2.5E-a"), 0, &value));
+               checkEqu(3,
+                   ReQStringUtils::lengthOfReal(ReString("2.5E-a"), 0, &value));
                checkEqu(2.5, value);
        }
 
@@ -124,7 +128,7 @@ public:
                ReString name = "Heinz Müller";
                char buffer[32];
                checkEqu("Heinz Müller",
-                       ReQStringUtils::utf8(name, buffer, sizeof buffer));
+                   ReQStringUtils::utf8(name, buffer, sizeof buffer));
                memset(buffer, 'x', sizeof buffer);
                checkEqu("Heinz", ReQStringUtils::utf8(name, buffer, (size_t)(5 + 1)));
                checkEqu(buffer[6], 'x');
@@ -182,8 +186,20 @@ public:
                checkEqu(8, ReQStringUtils::lengthOfTime("301:02:09x", 1, &time));
                checkEqu(QTime(1, 2, 9), time);
        }
+       void testReMatcher() {
+               ReMatcher m1("a*b*c", true);
+               checkT(m1.matches("a b c d"));
+               checkT(m1.matches("abc d"));
+               checkF(m1.matches("ababc"));
+               ReMatcher m2("a*b*c", false);
+
+               checkT(m2.matches("a b c d"));
+               checkT(m2.matches("ababc"));
+               checkT(m2.matches("a b a b c"));
+       }
 
        virtual void run(void) {
+               testReMatcher();
                testLengtOfTime();
                testLengtOfDate();
                testDateTimeParser();