00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "DocumentModelGeneral.h"
00009 #include "DocumentSerialize.h"
00010 #include "Logger.h"
00011 #include <QObject>
00012 #include <QSettings>
00013 #include <QTextStream>
00014 #include "QtToString.h"
00015 #include <QXmlStreamWriter>
00016 #include "Settings.h"
00017 #include "Xml.h"
00018
00019 const int DEFAULT_CURSOR_SIZE = 3;
00020 const int DEFAULT_EXTRA_PRECISION = 1;
00021
00022 DocumentModelGeneral::DocumentModelGeneral() :
00023 m_cursorSize (DEFAULT_CURSOR_SIZE),
00024 m_extraPrecision (DEFAULT_EXTRA_PRECISION)
00025 {
00026 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
00027 settings.beginGroup (SETTINGS_GROUP_GENERAL);
00028
00029 m_cursorSize = settings.value (SETTINGS_GENERAL_CURSOR_SIZE,
00030 QVariant (DEFAULT_CURSOR_SIZE)).toInt();
00031 m_extraPrecision = settings.value (SETTINGS_GENERAL_EXTRA_PRECISION,
00032 QVariant (DEFAULT_EXTRA_PRECISION)).toInt();
00033 settings.endGroup ();
00034 }
00035
00036 DocumentModelGeneral::DocumentModelGeneral(const Document &document) :
00037 m_cursorSize (document.modelGeneral().cursorSize()),
00038 m_extraPrecision (document.modelGeneral().extraPrecision())
00039 {
00040 }
00041
00042 DocumentModelGeneral::DocumentModelGeneral(const DocumentModelGeneral &other) :
00043 m_cursorSize (other.cursorSize()),
00044 m_extraPrecision (other.extraPrecision())
00045 {
00046 }
00047
00048 DocumentModelGeneral &DocumentModelGeneral::operator=(const DocumentModelGeneral &other)
00049 {
00050 m_cursorSize = other.cursorSize();
00051 m_extraPrecision = other.extraPrecision();
00052
00053 return *this;
00054 }
00055
00056 int DocumentModelGeneral::cursorSize() const
00057 {
00058 return m_cursorSize;
00059 }
00060
00061 int DocumentModelGeneral::extraPrecision() const
00062 {
00063 return m_extraPrecision;
00064 }
00065
00066 void DocumentModelGeneral::loadXml(QXmlStreamReader &reader)
00067 {
00068 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGeneral::loadXml";
00069
00070 bool success = true;
00071
00072 QXmlStreamAttributes attributes = reader.attributes();
00073
00074 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE) &&
00075 attributes.hasAttribute(DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION)) {
00076
00077 setCursorSize (attributes.value(DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE).toInt());
00078 setExtraPrecision (attributes.value(DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION).toInt());
00079
00080
00081 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00082 (reader.name() != DOCUMENT_SERIALIZE_GENERAL &&
00083 reader.name() != DOCUMENT_SERIALIZE_COMMON)){
00084 loadNextFromReader(reader);
00085 if (reader.atEnd()) {
00086 success = false;
00087 break;
00088 }
00089 }
00090 }
00091
00092 if (!success) {
00093 reader.raiseError (QObject::tr ("Cannot read general data"));
00094 }
00095 }
00096
00097 void DocumentModelGeneral::printStream(QString indentation,
00098 QTextStream &str) const
00099 {
00100 str << indentation << "DocumentModelGeneral\n";
00101
00102 indentation += INDENTATION_DELTA;
00103
00104 str << indentation << "cursorSize=" << m_cursorSize << "\n";
00105 str << indentation << "extraPrecision=" << m_extraPrecision << "\n";
00106 }
00107
00108 void DocumentModelGeneral::saveXml(QXmlStreamWriter &writer) const
00109 {
00110 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGeneral::saveXml";
00111
00112 writer.writeStartElement(DOCUMENT_SERIALIZE_GENERAL);
00113 writer.writeAttribute(DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE, QString::number (m_cursorSize));
00114 writer.writeAttribute(DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION, QString::number (m_extraPrecision));
00115 writer.writeEndElement();
00116 }
00117
00118 void DocumentModelGeneral::setCursorSize(int cursorSize)
00119 {
00120 m_cursorSize = cursorSize;
00121 }
00122
00123 void DocumentModelGeneral::setExtraPrecision (int extraPrecision)
00124 {
00125 m_extraPrecision = extraPrecision;
00126 }