diff --git a/sources/diagram.h b/sources/diagram.h index 5fbd41dd0..95397fdb7 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -19,10 +19,13 @@ #define DIAGRAM_H #include #include +#include #include "bordertitleblock.h" #include "conductorproperties.h" #include "exportproperties.h" #include "qgimanager.h" +#include "numerotationcontext.h" + class Conductor; class CustomElement; class DiagramContent; @@ -60,6 +63,8 @@ class Diagram : public QGraphicsScene { * Columns: display columns */ enum BorderOptions { EmptyBorder, TitleBlock, Columns }; + /// Represents available option of Numerotation type. + enum NumerotationType { Conductors }; /// Default properties for new conductors ConductorProperties defaultConductorProperties; /// Diagram dimensions and title block @@ -85,6 +90,7 @@ class Diagram : public QGraphicsScene { QETProject *project_; bool read_only_; qreal diagram_qet_version_; + QHash numerotation_; // methods protected: @@ -94,6 +100,8 @@ class Diagram : public QGraphicsScene { public: static bool clipboardMayContainDiagram(); + bool setNumerotation (NumerotationType, NumerotationContext); + NumerotationContext getNumerotation (NumerotationType) const; // methods related to parent project QETProject *project() const; @@ -190,6 +198,31 @@ class Diagram : public QGraphicsScene { }; Q_DECLARE_METATYPE(Diagram *) +/** + * @brief Diagram::setNumerotation, store a numerotation type + * @return true if storage is available + */ +inline bool Diagram::setNumerotation(Diagram::NumerotationType type, NumerotationContext context) { + switch (type) { + case Conductors: + numerotation_.insert(type, context); + return true; + break; + default: + return false; + break; + } +} + +/** + * @brief Diagram::getNumerotation + * @return the NumerotationContext associated with the key. + * If numerotation_ contains no item with the key, the function returns a default-constructed NumerotationContext + */ +inline NumerotationContext Diagram::getNumerotation(Diagram::NumerotationType type) const { + return numerotation_.value(type); +} + /** Display or hide the conductor setter, i.e. a dashed conductor stub which appears when creating a conductor between two terminals. @param pf true pour ajouter le poseur de conducteur, false pour l'enlever diff --git a/sources/numerotationcontext.cpp b/sources/numerotationcontext.cpp new file mode 100644 index 000000000..61933ed87 --- /dev/null +++ b/sources/numerotationcontext.cpp @@ -0,0 +1,105 @@ +/* + Copyright 2006-2013 The QElectroTech team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "numerotationcontext.h" + +/** + * @brief NumerotationContext::clear, clear the content + */ +void NumerotationContext::clear () { + content_.clear(); +} + +/** + * @brief NumerotationContext::addValue, add a new value on the contexte + * @param type the type of value + * @param value the value itself + * @param increase the increase number of value + * @return true if value is append + */ +bool NumerotationContext::addValue(const QString &type, const QVariant &value, const int increase) { + if (!keyIsAcceptable(type) && !value.canConvert(QVariant::String)) return false; + if (keyIsNumber(type) && !value.canConvert(QVariant::Int)) return false; + + QString valuestr = value.toString(); + valuestr.remove("|"); + content_ << type + "|" + valuestr + "|" + QString::number(increase); + return true; +} + +/** + * @brief NumerotationContext::operator [] + * @return the string at position @i + */ +QString NumerotationContext::operator [] (const int &i) const { + return (content_.at(i)); +} + +/** + * @brief NumerotationContext::operator << , append other + */ +void NumerotationContext::operator << (const NumerotationContext &other) { + for (int i=0; i. +*/ +#ifndef NUMEROTATIONCONTEXT_H +#define NUMEROTATIONCONTEXT_H + +#include +#include +/** + This class represents a numerotation context, i.e. the data (type, value, increase) + of a numerotation at a given time. It is notably used by conductor + to store the informations they need to do their autonumerotation. + */ +class NumerotationContext +{ + public: + void clear(); + bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1); + QString operator[] (const int &) const; + void operator << (const NumerotationContext &); + int size() const; + QStringList itemAt(const int) const; + QString validRegExpNum () const; + QString validRegExpNumber() const; + bool keyIsAcceptable (const QString &) const; + bool keyIsNumber(const QString &) const; + + private: + QStringList content_; +}; + +#endif // NUMEROTATIONCONTEXT_H