mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
add class to store numerotation context and add methode to use it on diagram
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2138 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -19,10 +19,13 @@
|
|||||||
#define DIAGRAM_H
|
#define DIAGRAM_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtXml>
|
#include <QtXml>
|
||||||
|
#include <QHash>
|
||||||
#include "bordertitleblock.h"
|
#include "bordertitleblock.h"
|
||||||
#include "conductorproperties.h"
|
#include "conductorproperties.h"
|
||||||
#include "exportproperties.h"
|
#include "exportproperties.h"
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
|
#include "numerotationcontext.h"
|
||||||
|
|
||||||
class Conductor;
|
class Conductor;
|
||||||
class CustomElement;
|
class CustomElement;
|
||||||
class DiagramContent;
|
class DiagramContent;
|
||||||
@@ -60,6 +63,8 @@ class Diagram : public QGraphicsScene {
|
|||||||
* Columns: display columns
|
* Columns: display columns
|
||||||
*/
|
*/
|
||||||
enum BorderOptions { EmptyBorder, TitleBlock, Columns };
|
enum BorderOptions { EmptyBorder, TitleBlock, Columns };
|
||||||
|
/// Represents available option of Numerotation type.
|
||||||
|
enum NumerotationType { Conductors };
|
||||||
/// Default properties for new conductors
|
/// Default properties for new conductors
|
||||||
ConductorProperties defaultConductorProperties;
|
ConductorProperties defaultConductorProperties;
|
||||||
/// Diagram dimensions and title block
|
/// Diagram dimensions and title block
|
||||||
@@ -85,6 +90,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
QETProject *project_;
|
QETProject *project_;
|
||||||
bool read_only_;
|
bool read_only_;
|
||||||
qreal diagram_qet_version_;
|
qreal diagram_qet_version_;
|
||||||
|
QHash <NumerotationType, NumerotationContext > numerotation_;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
protected:
|
protected:
|
||||||
@@ -94,6 +100,8 @@ class Diagram : public QGraphicsScene {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static bool clipboardMayContainDiagram();
|
static bool clipboardMayContainDiagram();
|
||||||
|
bool setNumerotation (NumerotationType, NumerotationContext);
|
||||||
|
NumerotationContext getNumerotation (NumerotationType) const;
|
||||||
|
|
||||||
// methods related to parent project
|
// methods related to parent project
|
||||||
QETProject *project() const;
|
QETProject *project() const;
|
||||||
@@ -190,6 +198,31 @@ class Diagram : public QGraphicsScene {
|
|||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(Diagram *)
|
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.
|
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
|
@param pf true pour ajouter le poseur de conducteur, false pour l'enlever
|
||||||
|
|||||||
105
sources/numerotationcontext.cpp
Normal file
105
sources/numerotationcontext.cpp
Normal file
@@ -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())));
|
||||||
|
}
|
||||||
46
sources/numerotationcontext.h
Normal file
46
sources/numerotationcontext.h
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user