* Constructor.
*/
ReGuiValidator::ReGuiValidator() :
- m_statusLine(NULL), m_errors(0){
+ m_errors(0){
}
/**
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;
-}
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;
};
* 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();
}
#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_ */