]> gitweb.hamatoma.de Git - reqt/commitdiff
ReStateStorage
authorhama <hama@siduction.net>
Thu, 23 Apr 2015 22:23:04 +0000 (00:23 +0200)
committerhama <hama@siduction.net>
Thu, 23 Apr 2015 22:23:04 +0000 (00:23 +0200)
gui/ReGuiValidator.cpp
gui/ReGuiValidator.hpp
gui/ReStateStorage.cpp
gui/ReStateStorage.hpp

index 9e9ebf02677affc1c878d46c4fe9b2548295b8ac..d7a145fbaa17559c800b6998772bc503405a30bf 100644 (file)
@@ -16,7 +16,7 @@
  * Constructor.
  */
 ReGuiValidator::ReGuiValidator() :
-         m_statusLine(NULL), m_errors(0){
+         m_errors(0){
 }
 
 /**
@@ -148,20 +148,4 @@ void ReGuiValidator::setInHistory(QComboBox* combo, const QString& value){
          combo->removeItem(20);
    }
 }
-/**
- * Returns the status line.
- * @return  the status line
- */
-QStatusBar* ReGuiValidator::statusLine() const{
-   return m_statusLine;
-}
-
-/**
- * Sets the status line.
- *
- * @param statusLine    the status line to set
- */
-void ReGuiValidator::setStatusLine(QStatusBar* statusLine){
-   m_statusLine = statusLine;
-}
 
index 4abdde113c3d87319216ba4a9720a730ac2ac5e0..59e669763d6c418a8771b569862c0327c4ed8752 100644 (file)
@@ -26,12 +26,9 @@ public:
    QString comboText(QComboBox* combo);
    virtual void guiError(QWidget* widget, const QString& message);
    void setInHistory(QComboBox* combo, const QString& value);
-   void setStatusLine(QStatusBar* statusLine);
    virtual void setStatusMessage(bool error, const QString& message) = 0;
-   QStatusBar* statusLine() const;
 
 protected:
-   QStatusBar* m_statusLine;
    int m_errors;
 };
 
index 95cc8470fba08c85b80665b17c962f4da61cea44..dde832210128518a2d861837e1b2d6af6911be52 100644 (file)
@@ -8,20 +8,80 @@
  * You also can use the license from http://www.wtfpl.net/.
  * The latest sources: https://github.com/republib
  */
-
+#include "QIODevice"
 #include "base/rebase.hpp"
 #include "gui/regui.hpp"
 
 /**
  * Constructor.
  *
- * @param file
+ * @param filename  filename with path of the storage file
  */
-ReStateStorage::ReStateStorage(const QString& file){
-
+ReStateStorage::ReStateStorage(const QString& filename) :
+         m_filename(filename), m_fp(NULL), m_stream(NULL), m_form(){
 }
 
+/**
+ * Destructor.
+ */
 ReStateStorage::~ReStateStorage(){
+   delete m_stream;
+   if (m_fp != NULL){
+      fclose(m_fp);
+      m_fp = NULL;
+   }
+}
 
+/**
+ * Initializes the instance for writing the storage information.
+ */
+bool ReStateStorage::initForWrite(){
+   if (m_fp == NULL)
+      m_fp = fopen(m_filename.toUtf8().constData(), "wb");
+   if (m_fp != NULL)
+      m_stream = new QTextStream(m_fp, QIODevice::ReadOnly);
+   return m_stream != NULL;
+}
+/**
+ * Returns the name of the current form.
+ *
+ * @return  the name of the current form
+ */
+QString ReStateStorage::form() const{
+   return m_form;
+}
+
+/**
+ * Sets the name of the current form.
+ *
+ * @param form  the name of the current form
+ */
+void ReStateStorage::setForm(const QString& form){
+   m_form = form;
+}
+
+/**
+ * Stores the data of a combobox.
+ *
+ * @param combo             the combobox to store
+ * @param name              the name of the combobox
+ * @param withCurrentText   <code>true</code>: the current text will be saved too
+ */
+void ReStateStorage::store(const QComboBox* combo, const QString& name,
+   bool withCurrentText){
+   if (initForWrite()){
+      QString fullname;
+      if (!m_form.isEmpty())
+         fullname = m_form + ".";
+      fullname += name;
+      for (int ii = 0; ii < combo->count(); ii++){
+         *m_stream << fullname << ".item:" << ii << "=" << combo->itemText(ii)
+            << endl;
+      }
+      if (withCurrentText){
+         *m_stream << fullname << ".text=" << combo->currentText() << endl;
+      }
+   }
+   m_stream->flush();
 }
 
index 8a2b012bed8ff1281ebd53a7eb019c080f3e203c..9f3837b5f60483ef2563ca23cabc332c07bdf1ed 100644 (file)
 #ifndef GUI_RESTATESTORAGE_HPP_
 #define GUI_RESTATESTORAGE_HPP_
 
+#include <QComboBox>
+#include <QTextStream>
+
 class ReStateStorage {
 public:
-   ReStateStorage(const QString& file);
+   ReStateStorage(const QString& filename);
    virtual ~ReStateStorage();
+public:
+   QString form() const;
+   bool initForWrite();
+   void store(const QComboBox* combo, const QString& name,
+      bool withCurrentText = false);
+   void setForm(const QString& form);
+
+private:
+   QString m_filename;
+   FILE* m_fp;
+   QTextStream* m_stream;
+   QString m_form;
 };
 
 #endif /* GUI_RESTATESTORAGE_HPP_ */