scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Double2StringFilter.cpp
Go to the documentation of this file.
1 
11 
30 #include "Double2StringFilter.h"
31 #include "lib/XmlStreamReader.h"
32 #include <QXmlStreamWriter>
33 
34 void Double2StringFilter::writeExtraAttributes(QXmlStreamWriter * writer) const
35 {
36  writer->writeAttribute("format", QString(QChar(numericFormat())));
37  writer->writeAttribute("digits", QString::number(numDigits()));
38 }
39 
41 {
42  QXmlStreamAttributes attribs = reader->attributes();
43  QString format_str = attribs.value(reader->namespaceUri().toString(), "format").toString();
44  QString digits_str = attribs.value(reader->namespaceUri().toString(), "digits").toString();
45 
46  if (AbstractSimpleFilter::load(reader))
47  {
48  bool ok;
49  int digits = digits_str.toInt(&ok);
50  if( (format_str.size() != 1) || !ok )
51  reader->raiseError(tr("missing or invalid format attribute(s)"));
52  else
53  {
54  setNumericFormat( format_str.at(0).toLatin1() );
55  setNumDigits( digits );
56  }
57  }
58  else
59  return false;
60 
61  return !reader->hasError();
62 }
63 
65 {
66  exec(new Double2StringFilterSetFormatCmd(this, format));
67 }
68 
70 {
71  exec(new Double2StringFilterSetDigitsCmd(this, digits));
72 }
73 
75  : d_target(target), d_other_format(new_format)
76 {
77  if(d_target->parentAspect())
78  setText(QObject::tr("%1: set numeric format to '%2'").arg(d_target->parentAspect()->name()).arg(new_format));
79  else
80  setText(QObject::tr("set numeric format to '%1'").arg(new_format));
81 }
82 
84 {
85  char tmp = d_target->d_format;
87  d_other_format = tmp;
88  emit d_target->formatChanged();
89 }
90 
92 {
93  redo();
94 }
95 
97  : d_target(target), d_other_digits(new_digits)
98 {
99  if(d_target->parentAspect())
100  setText(QObject::tr("%1: set decimal digits to %2").arg(d_target->parentAspect()->name()).arg(new_digits));
101  else
102  setText(QObject::tr("set decimal digits to %1").arg(new_digits));
103 }
104 
106 {
107  int tmp = d_target->d_digits;
109  d_other_digits = tmp;
110  emit d_target->formatChanged();
111 }
112 
114 {
115  redo();
116 }
117 
118 
119 
Double2StringFilter::load
virtual bool load(XmlStreamReader *reader)
Load from XML.
Definition: Double2StringFilter.cpp:40
Double2StringFilter::d_format
char d_format
Format character as in QString::number.
Definition: Double2StringFilter.h:64
Double2StringFilterSetDigitsCmd::Double2StringFilterSetDigitsCmd
Double2StringFilterSetDigitsCmd(Double2StringFilter *target, int new_digits)
Definition: Double2StringFilter.cpp:96
AbstractAspect::exec
void exec(QUndoCommand *command)
Execute the given command, pushing it on the undoStack() if available.
Definition: AbstractAspect.cpp:203
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
Double2StringFilterSetFormatCmd::Double2StringFilterSetFormatCmd
Double2StringFilterSetFormatCmd(Double2StringFilter *target, char new_format)
Definition: Double2StringFilter.cpp:74
XmlStreamReader
XML stream parser that supports errors as well as warnings.
Definition: XmlStreamReader.h:42
Double2StringFilter::numericFormat
char numericFormat() const
Get format character as in QString::number.
Definition: Double2StringFilter.h:50
Double2StringFilterSetDigitsCmd::undo
virtual void undo()
Definition: Double2StringFilter.cpp:113
Double2StringFilter.h
Double2StringFilterSetFormatCmd::d_other_format
char d_other_format
Definition: Double2StringFilter.h:100
Double2StringFilter::setNumDigits
void setNumDigits(int digits)
Set number of displayed digits.
Definition: Double2StringFilter.cpp:69
Double2StringFilterSetFormatCmd::d_target
Double2StringFilter * d_target
Definition: Double2StringFilter.h:99
Double2StringFilterSetFormatCmd::undo
virtual void undo()
Definition: Double2StringFilter.cpp:91
Double2StringFilterSetDigitsCmd::d_target
Double2StringFilter * d_target
Definition: Double2StringFilter.h:112
Double2StringFilter::writeExtraAttributes
virtual void writeExtraAttributes(QXmlStreamWriter *writer) const
Definition: Double2StringFilter.cpp:34
Double2StringFilter::formatChanged
void formatChanged()
Double2StringFilter::setNumericFormat
void setNumericFormat(char format)
Set format character as in QString::number.
Definition: Double2StringFilter.cpp:64
Double2StringFilterSetDigitsCmd::redo
virtual void redo()
Definition: Double2StringFilter.cpp:105
Double2StringFilterSetFormatCmd::redo
virtual void redo()
Definition: Double2StringFilter.cpp:83
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
XmlStreamReader.h
AbstractAspect::parentAspect
AbstractAspect * parentAspect() const
Return my parent Aspect or 0 if I currently don't have one.
Definition: AbstractAspect.cpp:109
Double2StringFilter::numDigits
int numDigits() const
Get number of displayed digits.
Definition: Double2StringFilter.h:52
AbstractSimpleFilter::load
virtual bool load(XmlStreamReader *reader)
Load from XML.
Definition: AbstractSimpleFilter.cpp:135
Double2StringFilter::Double2StringFilterSetDigitsCmd
friend class Double2StringFilterSetDigitsCmd
Definition: Double2StringFilter.h:62
Double2StringFilterSetDigitsCmd::d_other_digits
int d_other_digits
Definition: Double2StringFilter.h:113
Double2StringFilter::d_digits
int d_digits
Display digits or precision as in QString::number
Definition: Double2StringFilter.h:66
Double2StringFilter::Double2StringFilterSetFormatCmd
friend class Double2StringFilterSetFormatCmd
Definition: Double2StringFilter.h:61
Double2StringFilter
Locale-aware conversion filter double -> QString.
Definition: Double2StringFilter.h:39