[qet] [2138] add class to store numerotation context and add methode to use it on diagram

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2138
Author:   blacksun
Date:     2013-05-02 13:47:14 +0200 (Thu, 02 May 2013)
Log Message:
-----------
add class to store numerotation context and add methode to use it on diagram

Modified Paths:
--------------
    trunk/sources/diagram.h

Added Paths:
-----------
    trunk/sources/numerotationcontext.cpp
    trunk/sources/numerotationcontext.h

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2013-05-01 23:10:26 UTC (rev 2137)
+++ trunk/sources/diagram.h	2013-05-02 11:47:14 UTC (rev 2138)
@@ -19,10 +19,13 @@
 #define DIAGRAM_H
 #include <QtGui>
 #include <QtXml>
+#include <QHash>
 #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 @@
 		 * 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 @@
 	QETProject *project_;
 	bool read_only_;
 	qreal diagram_qet_version_;
+	QHash <NumerotationType, NumerotationContext > numerotation_;
 	
 	// methods
 	protected:
@@ -94,6 +100,8 @@
 	
 	public:
 	static bool clipboardMayContainDiagram();
+	bool setNumerotation (NumerotationType, NumerotationContext);
+	NumerotationContext getNumerotation (NumerotationType) const;
 	
 	// methods related to parent project
 	QETProject *project() const;
@@ -191,6 +199,31 @@
 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
 */

Added: trunk/sources/numerotationcontext.cpp
===================================================================
--- trunk/sources/numerotationcontext.cpp	                        (rev 0)
+++ trunk/sources/numerotationcontext.cpp	2013-05-02 11:47:14 UTC (rev 2138)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#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<other.size(); ++i) content_.append(other[i]);
+}
+
+/**
+ * @brief NumerotationContext::size
+ * @return size of context
+ */
+int NumerotationContext::size() const {
+	return (content_.size());
+}
+
+/**
+ * @brief NumerotationContext::itemAt
+ * @return the content at position @i 1:type 2:value 3:increase
+ */
+QStringList NumerotationContext::itemAt(const int i) const {
+	return (content_.at(i).split("|"));
+}
+
+/**
+ * @brief validRegExpNum
+ * @return all type use to numerotation
+ */
+QString NumerotationContext::validRegExpNum () const {
+	return ("unit|ten|hundred|string|folio");
+}
+
+/**
+ * @brief NumerotationContext::validRegExpNumber
+ * @return all type represents a number
+ */
+QString NumerotationContext::validRegExpNumber() const {
+	return ("unit|ten|hundred");
+}
+
+/**
+ * @brief NumerotationContext::keyIsAcceptable
+ * @return true if @type is acceptable
+ */
+bool NumerotationContext::keyIsAcceptable(const QString &type) const {
+	return (type.contains(QRegExp(validRegExpNum())));
+}
+
+/**
+ * @brief NumerotationContext::keyIsNumber
+ * @return true if @type represent a number
+ */
+bool NumerotationContext::keyIsNumber(const QString &type) const {
+	return (type.contains(QRegExp(validRegExpNumber())));
+}

Added: trunk/sources/numerotationcontext.h
===================================================================
--- trunk/sources/numerotationcontext.h	                        (rev 0)
+++ trunk/sources/numerotationcontext.h	2013-05-02 11:47:14 UTC (rev 2138)
@@ -0,0 +1,46 @@
+/*
+	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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef NUMEROTATIONCONTEXT_H
+#define NUMEROTATIONCONTEXT_H
+
+#include <QStringList>
+#include <QVariant>
+/**
+	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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/