Mod doc, Improve code style

This commit is contained in:
Simon De Backer
2020-08-12 21:53:02 +02:00
parent 87db0e2020
commit 69ff437368
6 changed files with 558 additions and 363 deletions

View File

@@ -29,16 +29,18 @@
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation"); int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
/** /**
* @brief ElementsLocation::ElementsLocation @brief ElementsLocation::ElementsLocation
* Constructor Constructor
*/ */
ElementsLocation::ElementsLocation() ElementsLocation::ElementsLocation()
{} {}
/** /**
Constructeur @brief ElementsLocation::ElementsLocation
@param p Chemin de l'emplacement de l'element @param path :
@param pr Projet de l'emplacement de l'element Chemin de l'emplacement de l'element
@param project :
Projet de l'emplacement de l'element
*/ */
ElementsLocation::ElementsLocation(const QString &path, QETProject *project) : ElementsLocation::ElementsLocation(const QString &path, QETProject *project) :
m_project(project) m_project(project)
@@ -63,15 +65,17 @@ ElementsLocation::ElementsLocation(const ElementsLocation &other) :
{} {}
/** /**
* @brief ElementsLocation::ElementLocation @brief ElementsLocation::ElementLocation
* Constructor, build an ElementLocation from a QMimeData, the mime data format Constructor, build an ElementLocation from a QMimeData,
* must be "application/x-qet-element-uri" or "application/x-qet-category-uri". the mime data format must be "application/x-qet-element-uri"
* This location can be null even if format is valid. or "application/x-qet-category-uri".
* @param data This location can be null even if format is valid.
*/ @param data
*/
ElementsLocation::ElementsLocation(const QMimeData *data) ElementsLocation::ElementsLocation(const QMimeData *data)
{ {
if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri")) if (data->hasFormat("application/x-qet-element-uri")
|| data->hasFormat("application/x-qet-category-uri"))
setPath(data->text()); setPath(data->text());
} }
@@ -87,9 +91,11 @@ ElementsLocation &ElementsLocation::operator=(const ElementsLocation &other) {
} }
/** /**
@brief ElementsLocation::operator ==
Operateur de comparaison Operateur de comparaison
@param other Autre emplacement d'element a comparer @param other Autre emplacement d'element a comparer
@return true si other et cet ElementsLocation sont identiques, false sinon @return true si other et cet ElementsLocation sont identiques,
false sinon
*/ */
bool ElementsLocation::operator==(const ElementsLocation &other) const { bool ElementsLocation::operator==(const ElementsLocation &other) const {
return( return(
@@ -99,9 +105,11 @@ bool ElementsLocation::operator==(const ElementsLocation &other) const {
} }
/** /**
@brief ElementsLocation::operator !=
Operateur de comparaison Operateur de comparaison
@param other Autre emplacement d'element a comparer @param other Autre emplacement d'element a comparer
@return true si other et cet ElementsLocation sont differents, false sinon @return true si other et cet ElementsLocation sont differents,
false sinon
*/ */
bool ElementsLocation::operator!=(const ElementsLocation &other) const { bool ElementsLocation::operator!=(const ElementsLocation &other) const {
return( return(
@@ -111,11 +119,12 @@ bool ElementsLocation::operator!=(const ElementsLocation &other) const {
} }
/** /**
* @brief ElementsLocation::baseName @brief ElementsLocation::baseName
* @return The base name of the element or directory. @return The base name of the element or directory.
* Unlike ElementsLocation::fileName , this method don't return the extension name. Unlike ElementsLocation::fileName,
* For exemple if this location represent an element they return myElement. this method don't return the extension name.
* @see fileName() For exemple if this location represent an element they return myElement.
@see fileName()
*/ */
QString ElementsLocation::baseName() const { QString ElementsLocation::baseName() const {
QRegExp regexp("^.*([^/]+)\\.elmt$"); QRegExp regexp("^.*([^/]+)\\.elmt$");
@@ -126,13 +135,15 @@ QString ElementsLocation::baseName() const {
} }
/** /**
* @brief ElementsLocation::collectionPath @brief ElementsLocation::collectionPath
* Return the path of the represented element relative to collection Return the path of the represented element relative to collection
* if @protocol is true the path is prepended by the collection type (common://, custom:// or embed://) if protocol is true the path is prepended by
* else if false, only the collection path is returned without the collection type. the collection type (common://, custom:// or embed://)
* @param protocol else if false,
* @return the path only the collection path is returned without the collection type.
*/ @param protocol
@return the path
*/
QString ElementsLocation::collectionPath(bool protocol) const QString ElementsLocation::collectionPath(bool protocol) const
{ {
if (protocol) if (protocol)
@@ -145,23 +156,27 @@ QString ElementsLocation::collectionPath(bool protocol) const
} }
/** /**
* @brief ElementsLocation::projectCollectionPath @brief ElementsLocation::projectCollectionPath
* @return The path is in form : project0+embed://dir/subdir/myElement.elmt @return The path is in form : project0+embed://dir/subdir/myElement.elmt
* If this item represent a file system thing, return a null QString; If this item represent a file system thing, return a null QString;
*/ */
QString ElementsLocation::projectCollectionPath() const QString ElementsLocation::projectCollectionPath() const
{ {
if (isFileSystem()) if (isFileSystem())
return QString(); return QString();
else else
return QString("project" + QString::number(QETApp::projectId(m_project)) + "+" + collectionPath()); return QString("project"
+ QString::number(QETApp::projectId(m_project))
+ "+"
+ collectionPath());
} }
/** /**
* @brief ElementsLocation::fileSystemPath @brief ElementsLocation::fileSystemPath
* @return The file system path of this element, (the separator is always '/' see QDir::toNativeSeparators()) @return The file system path of this element,
* If this element is embedded in a project return an empty string; (the separator is always '/' see QDir::toNativeSeparators())
*/ If this element is embedded in a project return an empty string;
*/
QString ElementsLocation::fileSystemPath() const QString ElementsLocation::fileSystemPath() const
{ {
if (!m_project) if (!m_project)
@@ -171,20 +186,21 @@ QString ElementsLocation::fileSystemPath() const
} }
/** /**
* @brief ElementsLocation::path @brief ElementsLocation::path
* @return The path of this location. @return The path of this location.
* OBSOLETE, use instead collectionPath(true) @deprecated use instead collectionPath(true)
*/ */
QString ElementsLocation::path() const { QString ElementsLocation::path() const {
return(m_collection_path); return(m_collection_path);
} }
/** /**
* @brief ElementsLocation::setPath @brief ElementsLocation::setPath
* Set the path of this item. Set the path of this item.
* The path can be relative to a collection (start by common:// , custom:// or embed://) or not. The path can be relative to a collection
* @param path (start by common:// , custom:// or embed://) or not.
*/ @param path
*/
void ElementsLocation::setPath(const QString &path) void ElementsLocation::setPath(const QString &path)
{ {
QString tmp_path = path; QString tmp_path = path;
@@ -204,7 +220,7 @@ void ElementsLocation::setPath(const QString &path)
} }
//The path start with project, we get the project and the path from the string //The path start with project, we get the project and the path from the string
else if (tmp_path.startsWith("project")) else if (tmp_path.startsWith("project"))
{ {
QRegExp rx("^project([0-9]+)\\+(embed:\\/\\/.*)$", Qt::CaseInsensitive); QRegExp rx("^project([0-9]+)\\+(embed:\\/\\/.*)$", Qt::CaseInsensitive);
@@ -224,7 +240,8 @@ void ElementsLocation::setPath(const QString &path)
} }
} }
//The path is in file system, the given path is relative to common or custom collection // The path is in file system,
// the given path is relative to common or custom collection
else if (path.startsWith("common://") || path.startsWith("custom://")) else if (path.startsWith("common://") || path.startsWith("custom://"))
{ {
QString p; QString p;
@@ -242,7 +259,7 @@ void ElementsLocation::setPath(const QString &path)
m_file_system_path = p; m_file_system_path = p;
m_collection_path = path; m_collection_path = path;
} }
//In this case, the path is supposed to be relative to the file system. //In this case, the path is supposed to be relative to the file system.
else else
{ {
QString path_ = path; QString path_ = path;
@@ -282,11 +299,11 @@ void ElementsLocation::setPath(const QString &path)
} }
/** /**
* @brief ElementsLocation::addToPath @brief ElementsLocation::addToPath
* Add a string to the actual path of this location Add a string to the actual path of this location
* @param string @param string
* @return True if the operation success @return True if the operation success
*/ */
bool ElementsLocation::addToPath(const QString &string) bool ElementsLocation::addToPath(const QString &string)
{ {
if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive)) if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive))
@@ -308,6 +325,7 @@ bool ElementsLocation::addToPath(const QString &string)
} }
/** /**
@brief ElementsLocation::parent
@return the location of the parent category, or a copy of this location @return the location of the parent category, or a copy of this location
when it represents a root category. when it represents a root category.
*/ */
@@ -324,6 +342,7 @@ ElementsLocation ElementsLocation::parent() const {
} }
/** /**
@brief ElementsLocation::project
@return le projet de cet emplacement ou 0 si celui-ci n'est pas lie a @return le projet de cet emplacement ou 0 si celui-ci n'est pas lie a
un projet. un projet.
*/ */
@@ -332,7 +351,9 @@ QETProject *ElementsLocation::project() const {
} }
/** /**
@param project le nouveau projet pointe par cet emplacement @brief ElementsLocation::setProject
@param project :
le nouveau projet pointe par cet emplacement
Indiquer 0 pour que cet emplacement ne soit plus lie a un projet. Indiquer 0 pour que cet emplacement ne soit plus lie a un projet.
*/ */
void ElementsLocation::setProject(QETProject *project) { void ElementsLocation::setProject(QETProject *project) {
@@ -340,6 +361,7 @@ void ElementsLocation::setProject(QETProject *project) {
} }
/** /**
@brief ElementsLocation::isNull
@return true si l'emplacement semble utilisable (chemin virtuel non vide). @return true si l'emplacement semble utilisable (chemin virtuel non vide).
*/ */
bool ElementsLocation::isNull() const { bool ElementsLocation::isNull() const {
@@ -347,6 +369,7 @@ bool ElementsLocation::isNull() const {
} }
/** /**
@brief ElementsLocation::toString
@return Une chaine de caracteres representant l'emplacement @return Une chaine de caracteres representant l'emplacement
*/ */
QString ElementsLocation::toString() const { QString ElementsLocation::toString() const {
@@ -362,25 +385,25 @@ QString ElementsLocation::toString() const {
} }
/** /**
* @brief ElementsLocation::isElement @brief ElementsLocation::isElement
* @return true if this location represent an element @return true if this location represent an element
*/ */
bool ElementsLocation::isElement() const { bool ElementsLocation::isElement() const {
return m_collection_path.endsWith(".elmt"); return m_collection_path.endsWith(".elmt");
} }
/** /**
* @brief ElementsLocation::isDirectory @brief ElementsLocation::isDirectory
* @return true if this location represent a directory @return true if this location represent a directory
*/ */
bool ElementsLocation::isDirectory() const { bool ElementsLocation::isDirectory() const {
return (!isElement() && !m_collection_path.isEmpty()); return (!isElement() && !m_collection_path.isEmpty());
} }
/** /**
* @brief ElementsLocation::isFileSystem @brief ElementsLocation::isFileSystem
* @return @return true if
*/ */
bool ElementsLocation::isFileSystem() const bool ElementsLocation::isFileSystem() const
{ {
if (m_project) return false; if (m_project) return false;
@@ -389,27 +412,29 @@ bool ElementsLocation::isFileSystem() const
} }
/** /**
* @brief ElementsLocation::isCommonCollection @brief ElementsLocation::isCommonCollection
* @return True if this location represent an item from the common collection @return
*/ True if this location represent an item from the common collection
*/
bool ElementsLocation::isCommonCollection() const bool ElementsLocation::isCommonCollection() const
{ {
return fileSystemPath().startsWith(QETApp::commonElementsDirN()); return fileSystemPath().startsWith(QETApp::commonElementsDirN());
} }
/** /**
* @brief ElementsLocation::isCustomCollection @brief ElementsLocation::isCustomCollection
* @return True if this location represent an item from the custom collection @return
*/ True if this location represent an item from the custom collection
*/
bool ElementsLocation::isCustomCollection() const bool ElementsLocation::isCustomCollection() const
{ {
return fileSystemPath().startsWith(QETApp::customElementsDirN()); return fileSystemPath().startsWith(QETApp::customElementsDirN());
} }
/** /**
* @brief ElementsLocation::isProject @brief ElementsLocation::isProject
* @return True if this location represent an item from a project. @return True if this location represent an item from a project.
*/ */
bool ElementsLocation::isProject() const bool ElementsLocation::isProject() const
{ {
if (m_project && !m_collection_path.isEmpty()) if (m_project && !m_collection_path.isEmpty())
@@ -419,9 +444,10 @@ bool ElementsLocation::isProject() const
} }
/** /**
* @brief ElementsLocation::exist @brief ElementsLocation::exist
* @return True if this location represent an existing directory or element. @return
*/ True if this location represent an existing directory or element.
*/
bool ElementsLocation::exist() const bool ElementsLocation::exist() const
{ {
if (m_project) if (m_project)
@@ -445,9 +471,9 @@ bool ElementsLocation::exist() const
} }
/** /**
* @brief ElementsLocation::isWritable @brief ElementsLocation::isWritable
* @return True if this element can be writable (can use set xml) @return True if this element can be writable (can use set xml)
*/ */
bool ElementsLocation::isWritable() const bool ElementsLocation::isWritable() const
{ {
if (m_project) if (m_project)
@@ -463,10 +489,11 @@ bool ElementsLocation::isWritable() const
} }
/** /**
* @brief ElementsLocation::projectCollection @brief ElementsLocation::projectCollection
* @return If this location represente a item in an embedded project collection, return this collection @return
* else return nullptr. If this location represente a item in an embedded project collection,
*/ return this collection else return nullptr.
*/
XmlElementCollection *ElementsLocation::projectCollection() const XmlElementCollection *ElementsLocation::projectCollection() const
{ {
if (m_project) if (m_project)
@@ -476,10 +503,10 @@ XmlElementCollection *ElementsLocation::projectCollection() const
} }
/** /**
* @brief ElementsLocation::nameList @brief ElementsLocation::nameList
* @return the namelist of the represented element or directory. @return the namelist of the represented element or directory.
* If namelist can't be set, return a empty namelist If namelist can't be set, return a empty namelist
*/ */
NamesList ElementsLocation::nameList() NamesList ElementsLocation::nameList()
{ {
NamesList nl; NamesList nl;
@@ -514,10 +541,10 @@ NamesList ElementsLocation::nameList()
} }
/** /**
* @brief ElementsLocation::xml @brief ElementsLocation::xml
* @return The definition of this element or directory. @return The definition of this element or directory.
* The definition can be null. The definition can be null.
*/ */
QDomElement ElementsLocation::xml() const QDomElement ElementsLocation::xml() const
{ {
if (!m_project) if (!m_project)
@@ -546,15 +573,19 @@ QDomElement ElementsLocation::xml() const
} }
/** /**
* @brief ElementsLocation::pugiXml @brief ElementsLocation::pugiXml
* @return the xml document of this element or directory @return the xml document of this element or directory
* The definition can be null The definition can be null
*/ */
pugi::xml_document ElementsLocation::pugiXml() const pugi::xml_document ElementsLocation::pugiXml() const
{ {
//Except for linux OS (because linux keep in cache the file), we keep in memory the xml /* Except for linux OS (because linux keep in cache the file),
//to avoid multiple access to file. * we keep in memory the xml
//keep in memory the XML, consumes a little more RAM, for this reason we don't use it for linux to minimize the RAM footprint. * to avoid multiple access to file.
* keep in memory the XML,
* consumes a little more RAM,
* for this reason we don't use it for linux to minimize the RAM footprint.
*/
#ifndef Q_OS_LINUX #ifndef Q_OS_LINUX
if (!m_string_stream.str().empty()) if (!m_string_stream.str().empty())
{ {
@@ -579,7 +610,7 @@ pugi::xml_document ElementsLocation::pugiXml() const
QString str = m_collection_path; QString str = m_collection_path;
if (isElement()) if (isElement())
{ {
//Get the xml dom from Qt xml and copie to pugi xml //Get the xml dom from Qt xml and copie to pugi xml
QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://")); QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://"));
QDomDocument qdoc; QDomDocument qdoc;
qdoc.appendChild(qdoc.importNode(element.firstChildElement("definition"), true)); qdoc.appendChild(qdoc.importNode(element.firstChildElement("definition"), true));
@@ -604,13 +635,14 @@ pugi::xml_document ElementsLocation::pugiXml() const
} }
/** /**
* @brief ElementsLocation::setXml @brief ElementsLocation::setXml
* Replace the current xml description by @xml_element; Replace the current xml description by xml_document;
* The document element of @xml_document must have tagname "definition" to be written The document element of xml_document must have
* This definition must be writable tagname "definition" to be written
* @param xml_element This definition must be writable
* @return true if success @param xml_document
*/ @return true if success
*/
bool ElementsLocation::setXml(const QDomDocument &xml_document) const bool ElementsLocation::setXml(const QDomDocument &xml_document) const
{ {
if (!isWritable()) if (!isWritable())
@@ -666,10 +698,10 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
} }
/** /**
* @brief ElementsLocation::uuid @brief ElementsLocation::uuid
* @return The uuid of the pointed element @return The uuid of the pointed element
* Uuid can be null Uuid can be null
*/ */
QUuid ElementsLocation::uuid() const QUuid ElementsLocation::uuid() const
{ {
if (!isElement()) { if (!isElement()) {
@@ -685,16 +717,17 @@ QUuid ElementsLocation::uuid() const
} }
/** /**
* @brief ElementLocation::icon @brief ElementLocation::icon
* @return The icon of the represented element. @return The icon of the represented element.
* If icon can't be set, return a null QIcon If icon can't be set, return a null QIcon
*/ */
QIcon ElementsLocation::icon() const QIcon ElementsLocation::icon() const
{ {
if (!m_project) if (!m_project)
{ {
ElementsCollectionCache *cache = QETApp::collectionCache(); ElementsCollectionCache *cache = QETApp::collectionCache();
ElementsLocation loc(*this); //Make a copy of this to keep this method const // Make a copy of this to keep this method const
ElementsLocation loc(*this);
if (cache->fetchElement(loc)) if (cache->fetchElement(loc))
return QIcon(cache->pixmap()); return QIcon(cache->pixmap());
} }
@@ -706,9 +739,9 @@ QIcon ElementsLocation::icon() const
} }
/** /**
* @brief ElementLocation::name @brief ElementLocation::name
* @return The name of the represented element in the current local @return The name of the represented element in the current local
*/ */
QString ElementsLocation::name() const QString ElementsLocation::name() const
{ {
NamesList nl; NamesList nl;
@@ -717,13 +750,15 @@ QString ElementsLocation::name() const
} }
/** /**
* @brief ElementLocation::fileName @brief ElementLocation::fileName
* @return Return the file name of the represented item, whatever the storage system (file system, xml collection) @return Return the file name of the represented item,
* with is file extension. whatever the storage system (file system, xml collection)
* For example if this location represent an element, they return myElement.elmt. with is file extension.
* For a directory return myDirectory. For example if this location represent an element,
* @see baseName they return myElement.elmt.
*/ For a directory return myDirectory.
@see baseName
*/
QString ElementsLocation::fileName() const QString ElementsLocation::fileName() const
{ {
if (m_collection_path.isEmpty()) return QString(); if (m_collection_path.isEmpty()) return QString();
@@ -734,10 +769,11 @@ QString ElementsLocation::fileName() const
} }
/** /**
* @brief ElementsLocation::elementInformations @brief ElementsLocation::elementInformations
* @return the element information of the element represented by this location. @return
* If the location is a directory, the returned diagram context is empty the element information of the element represented by this location.
*/ If the location is a directory, the returned diagram context is empty
*/
DiagramContext ElementsLocation::elementInformations() const DiagramContext ElementsLocation::elementInformations() const
{ {
DiagramContext context; DiagramContext context;
@@ -745,10 +781,18 @@ DiagramContext ElementsLocation::elementInformations() const
return context; return context;
} }
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation"); context.fromXml(pugiXml().document_element().child(
"elementInformations"),
"elementInformation");
return context; return context;
} }
/**
@brief operator <<
@param debug
@param location
@return
*/
QDebug operator<< (QDebug debug, const ElementsLocation &location) QDebug operator<< (QDebug debug, const ElementsLocation &location)
{ {
QDebugStateSaver saver(debug); QDebugStateSaver saver(debug);
@@ -762,7 +806,8 @@ QDebug operator<< (QDebug debug, const ElementsLocation &location)
QString msg; QString msg;
msg += "ElementsLocation("; msg += "ElementsLocation(";
msg += (location.isProject()? location.projectCollectionPath() : location.collectionPath(true)); msg += (location.isProject()? location.projectCollectionPath()
: location.collectionPath(true));
msg += location.exist()? ", true" : ", false"; msg += location.exist()? ", true" : ", false";
msg +=")"; msg +=")";

View File

@@ -32,6 +32,7 @@ class QETProject;
class XmlElementCollection; class XmlElementCollection;
/** /**
@brief The ElementsLocation class
Cette classe represente la localisation, l'emplacement d'un element ou Cette classe represente la localisation, l'emplacement d'un element ou
d'une categorie, voire d'une collection... dans une collection. Elle d'une categorie, voire d'une collection... dans une collection. Elle
encapsule un chemin virtuel. encapsule un chemin virtuel.
@@ -40,7 +41,8 @@ class ElementsLocation
{ {
public: public:
ElementsLocation(); ElementsLocation();
ElementsLocation(const QString &path, QETProject *project = nullptr); ElementsLocation(const QString &path,
QETProject *project = nullptr);
ElementsLocation(const ElementsLocation &); ElementsLocation(const ElementsLocation &);
ElementsLocation(const QMimeData *data); ElementsLocation(const QMimeData *data);
virtual ~ElementsLocation(); virtual ~ElementsLocation();

View File

@@ -31,19 +31,19 @@ static int header = 5;
static int cross_min_heigth = 33; static int cross_min_heigth = 33;
/** /**
* @brief CrossRefItem::CrossRefItem @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref @param elmt : element to display the cross ref
*/ */
CrossRefItem::CrossRefItem(Element *elmt) : CrossRefItem::CrossRefItem(Element *elmt) :
QGraphicsObject(elmt), QGraphicsObject(elmt),
m_element(elmt) m_element(elmt)
{init();} {init();}
/** /**
* @brief CrossRefItem::CrossRefItem @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref @param elmt : element to display the cross ref
* @param text : If the Xref must be displayed under a text, the text. @param text : If the Xref must be displayed under a text, the text.
*/ */
CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) : CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) :
QGraphicsObject(text), QGraphicsObject(text),
m_element (elmt), m_element (elmt),
@@ -51,10 +51,10 @@ CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) :
{init();} {init();}
/** /**
* @brief CrossRefItem::CrossRefItem @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref @param elmt : element to display the cross ref
* @param group : If the Xref must be displayed under a group, the group. @param group : If the Xref must be displayed under a group, the group.
*/ */
CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) : CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
QGraphicsObject(group), QGraphicsObject(group),
m_element(elmt), m_element(elmt),
@@ -62,15 +62,15 @@ CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
{init();} {init();}
/** /**
* @brief CrossRefItem::~CrossRefItem @brief CrossRefItem::~CrossRefItem
* Default destructor Default destructor
*/ */
CrossRefItem::~CrossRefItem() {} CrossRefItem::~CrossRefItem() {}
/** /**
* @brief CrossRefItem::init @brief CrossRefItem::init
* init this Xref init this Xref
*/ */
void CrossRefItem::init() void CrossRefItem::init()
{ {
if(!m_element->diagram()) if(!m_element->diagram())
@@ -91,9 +91,9 @@ void CrossRefItem::init()
} }
/** /**
* @brief CrossRefItem::setUpConnection @brief CrossRefItem::setUpConnection
* Set up several connection to keep up to date the Xref Set up several connection to keep up to date the Xref
*/ */
void CrossRefItem::setUpConnection() void CrossRefItem::setUpConnection()
{ {
for(const QMetaObject::Connection& c : m_update_connection) for(const QMetaObject::Connection& c : m_update_connection)
@@ -123,47 +123,58 @@ void CrossRefItem::setUpConnection()
} }
/** /**
* @brief CrossRefItem::boundingRect @brief CrossRefItem::boundingRect
* @return the bounding rect of this item @return the bounding rect of this item
*/ */
QRectF CrossRefItem::boundingRect() const { QRectF CrossRefItem::boundingRect() const {
return m_bounding_rect; return m_bounding_rect;
} }
/** /**
* @brief CrossRefItem::shape @brief CrossRefItem::shape
* @return the shape of this item @return the shape of this item
*/ */
QPainterPath CrossRefItem::shape() const{ QPainterPath CrossRefItem::shape() const{
return m_shape_path; return m_shape_path;
} }
/** /**
* @brief CrossRefItem::elementPositionText @brief CrossRefItem::elementPositionText
* @param elmt @param elmt
* @return the string corresponding to the position of @elmt in the diagram. @param add_prefix
* if @add_prefix is true, prefix (for power and delay contact) is added to the poistion text. @return the string corresponding to the position of elmt in the diagram.
*/ if add_prefix is true,
QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const prefix (for power and delay contact) is added to the poistion text.
*/
QString CrossRefItem::elementPositionText(const Element *elmt,
const bool &add_prefix) const
{ {
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); XRefProperties xrp =
m_element->diagram()->project()->defaultXRefProperties(
m_element->kindInformations()["type"].toString());
QString formula = xrp.masterLabel(); QString formula = xrp.masterLabel();
autonum::sequentialNumbers seq; autonum::sequentialNumbers seq;
QString txt = autonum::AssignVariables::formulaToLabel(formula, seq, elmt->diagram(), elmt); QString txt = autonum::AssignVariables::formulaToLabel(
formula,
seq, elmt->diagram(),
elmt);
if (add_prefix) if (add_prefix)
{ {
if (elmt->kindInformations()["type"].toString() == "power") txt.prepend(m_properties.prefix("power")); if (elmt->kindInformations()["type"].toString() == "power")
else if (elmt->kindInformations()["type"].toString().contains("delay")) txt.prepend(m_properties.prefix("delay")); txt.prepend(m_properties.prefix("power"));
else if (elmt->kindInformations()["state"].toString() == "SW") txt.prepend(m_properties.prefix("switch")); else if (elmt->kindInformations()["type"].toString().contains("delay"))
txt.prepend(m_properties.prefix("delay"));
else if (elmt->kindInformations()["state"].toString() == "SW")
txt.prepend(m_properties.prefix("switch"));
} }
return txt; return txt;
} }
/** /**
* @brief CrossRefItem::updateProperties @brief CrossRefItem::updateProperties
* update the curent properties update the curent properties
*/ */
void CrossRefItem::updateProperties() void CrossRefItem::updateProperties()
{ {
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
@@ -183,9 +194,9 @@ void CrossRefItem::updateProperties()
} }
/** /**
* @brief CrossRefItem::updateLabel @brief CrossRefItem::updateLabel
* Update the content of the item Update the content of the item
*/ */
void CrossRefItem::updateLabel() void CrossRefItem::updateLabel()
{ {
//init the shape and bounding rect //init the shape and bounding rect
@@ -218,22 +229,31 @@ void CrossRefItem::updateLabel()
} }
/** /**
* @brief CrossRefItem::autoPos @brief CrossRefItem::autoPos
* Calculate and set position automaticaly. Calculate and set position automaticaly.
*/ */
void CrossRefItem::autoPos() { void CrossRefItem::autoPos() {
//We calcul the position according to the @snapTo of the xrefproperties //We calcul the position according to the @snapTo of the xrefproperties
if (m_properties.snapTo() == XRefProperties::Bottom) if (m_properties.snapTo() == XRefProperties::Bottom)
centerToBottomDiagram(this, m_element, m_properties.offset() <= 40 ? 5 : m_properties.offset()); centerToBottomDiagram(this,
m_element,
m_properties.offset() <= 40
? 5
: m_properties.offset());
else else
centerToParentBottom(this); centerToParentBottom(this);
} }
/**
@brief CrossRefItem::sceneEvent
@param event
@return
*/
bool CrossRefItem::sceneEvent(QEvent *event) bool CrossRefItem::sceneEvent(QEvent *event)
{ {
//By default when a QGraphicsItem is a child of a QGraphicsItemGroup //By default when a QGraphicsItem is a child of a QGraphicsItemGroup
//all events are forwarded to group. //all events are forwarded to group.
//We override it, when this Xref is in a group //We override it, when this Xref is in a group
if(m_group) if(m_group)
{ {
switch (event->type()) switch (event->type())
@@ -259,22 +279,24 @@ bool CrossRefItem::sceneEvent(QEvent *event)
} }
/** /**
* @brief CrossRefItem::paint @brief CrossRefItem::paint
* Paint this item Paint this item
* @param painter @param painter
* @param option @param option
* @param widget @param widget
*/ */
void CrossRefItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { void CrossRefItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) {
Q_UNUSED(option) Q_UNUSED(option)
Q_UNUSED(widget) Q_UNUSED(widget)
m_drawing.play(painter); m_drawing.play(painter);
} }
/** /**
* @brief CrossRefItem::mouseDoubleClickEvent @brief CrossRefItem::mouseDoubleClickEvent
* @param event @param event
*/ */
void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{ {
event->accept(); event->accept();
@@ -288,7 +310,8 @@ void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
m_hovered_contact->setSelected(true); m_hovered_contact->setSelected(true);
//Zoom to the linked slave element //Zoom to the linked slave element
foreach(QGraphicsView *view, m_hovered_contact->diagram()->views()) foreach(QGraphicsView *view,
m_hovered_contact->diagram()->views())
{ {
QRectF fit = m_hovered_contact->sceneBoundingRect(); QRectF fit = m_hovered_contact->sceneBoundingRect();
fit.adjust(-200, -200, 200, 200); fit.adjust(-200, -200, 200, 200);
@@ -297,12 +320,20 @@ void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
} }
} }
/**
@brief CrossRefItem::hoverEnterEvent
@param event
*/
void CrossRefItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void CrossRefItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
m_hovered_contact = nullptr; m_hovered_contact = nullptr;
QGraphicsObject::hoverEnterEvent(event); QGraphicsObject::hoverEnterEvent(event);
} }
/**
@brief CrossRefItem::hoverMoveEvent
@param event
*/
void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
QPointF pos = event->pos(); QPointF pos = event->pos();
@@ -311,7 +342,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
foreach(QRectF rect, m_hovered_contacts_map.values(m_hovered_contact)) foreach(QRectF rect, m_hovered_contacts_map.values(m_hovered_contact))
{ {
//Mouse hover the same rect than previous hover event //Mouse hover the same rect than previous hover event
if (rect.contains(pos)) if (rect.contains(pos))
{ {
QGraphicsObject::hoverMoveEvent(event); QGraphicsObject::hoverMoveEvent(event);
@@ -319,7 +350,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
} }
} }
//At this point, mouse don't hover previous rect //At this point, mouse don't hover previous rect
m_hovered_contact = nullptr; m_hovered_contact = nullptr;
foreach (Element *elmt, m_hovered_contacts_map.keys()) foreach (Element *elmt, m_hovered_contacts_map.keys())
@@ -344,7 +375,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
foreach(QRectF rect, m_hovered_contacts_map.values(elmt)) foreach(QRectF rect, m_hovered_contacts_map.values(elmt))
{ {
//Mouse hover a contact //Mouse hover a contact
if (rect.contains(pos)) if (rect.contains(pos))
{ {
m_hovered_contact = elmt; m_hovered_contact = elmt;
@@ -357,6 +388,10 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
} }
} }
/**
@brief CrossRefItem::hoverLeaveEvent
@param event
*/
void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
m_hovered_contact = nullptr; m_hovered_contact = nullptr;
@@ -364,6 +399,9 @@ void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsObject::hoverLeaveEvent(event); QGraphicsObject::hoverLeaveEvent(event);
} }
/**
@brief CrossRefItem::linkedChanged
*/
void CrossRefItem::linkedChanged() void CrossRefItem::linkedChanged()
{ {
for(const QMetaObject::Connection& c : m_slave_connection) for(const QMetaObject::Connection& c : m_slave_connection)
@@ -376,17 +414,23 @@ void CrossRefItem::linkedChanged()
for(Element *elmt : m_element->linkedElements()) for(Element *elmt : m_element->linkedElements())
{ {
m_slave_connection << connect(elmt, &Element::xChanged, this, &CrossRefItem::updateLabel); m_slave_connection << connect(elmt,
m_slave_connection << connect(elmt, &Element::yChanged, this, &CrossRefItem::updateLabel); &Element::xChanged,
this,
&CrossRefItem::updateLabel);
m_slave_connection << connect(elmt,
&Element::yChanged,
this,
&CrossRefItem::updateLabel);
} }
updateLabel(); updateLabel();
} }
/** /**
* @brief CrossRefItem::buildHeaderContact @brief CrossRefItem::buildHeaderContact
* Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc
*/ */
void CrossRefItem::buildHeaderContact() { void CrossRefItem::buildHeaderContact() {
if (!m_hdr_no_ctc.isNull() && !m_hdr_nc_ctc.isNull()) return; if (!m_hdr_no_ctc.isNull() && !m_hdr_nc_ctc.isNull()) return;
@@ -430,11 +474,13 @@ void CrossRefItem::buildHeaderContact() {
} }
/** /**
* @brief CrossRefItem::setUpCrossBoundingRect @brief CrossRefItem::setUpCrossBoundingRect
* Get the numbers of slaves elements linked to this parent element, Get the numbers of slaves elements linked to this parent element,
* for calculate the size of the cross bounding rect. for calculate the size of the cross bounding rect.
* The cross ref item is drawing according to the size of the cross bounding rect. The cross ref item is drawing according to the size of
*/ the cross bounding rect.
@param painter
*/
void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
{ {
//No need to calcul if nothing is linked //No need to calcul if nothing is linked
@@ -492,10 +538,10 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
} }
/** /**
* @brief CrossRefItem::drawAsCross @brief CrossRefItem::drawAsCross
* Draw this crossref with a cross Draw this crossref with a cross
* @param painter, painter to use @param painter: painter to use
*/ */
void CrossRefItem::drawAsCross(QPainter &painter) void CrossRefItem::drawAsCross(QPainter &painter)
{ {
//calcul the size of the cross //calcul the size of the cross
@@ -522,10 +568,10 @@ void CrossRefItem::drawAsCross(QPainter &painter)
} }
/** /**
* @brief CrossRefItem::drawAsContacts @brief CrossRefItem::drawAsContacts
* Draw this crossref with symbolic contacts Draw this crossref with symbolic contacts
* @param painter painter to use @param painter painter to use
*/ */
void CrossRefItem::drawAsContacts(QPainter &painter) void CrossRefItem::drawAsContacts(QPainter &painter)
{ {
if (m_element -> isFree()) if (m_element -> isFree())
@@ -567,13 +613,13 @@ void CrossRefItem::drawAsContacts(QPainter &painter)
} }
/** /**
* @brief CrossRefItem::drawContact @brief CrossRefItem::drawContact
* Draw one contact, the type of contact to draw is define in @flags. Draw one contact, the type of contact to draw is define in flags.
* @param painter, painter to use @param painter : painter to use
* @param flags, define how to draw the contact (see enul CONTACTS) @param flags : define how to draw the contact (see enul CONTACTS)
* @param elmt, the element to display text (the position of the contact) @param elmt : the element to display text (the position of the contact)
* @return The bounding rect of the draw (contact + text) @return The bounding rect of the draw (contact + text)
*/ */
QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt) QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
{ {
QString str = elementPositionText(elmt); QString str = elementPositionText(elmt);
@@ -735,8 +781,13 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
} }
//Draw position text //Draw position text
QRectF text_rect = painter.boundingRect(QRectF(30, offset+5, 5, 10), Qt::AlignLeft | Qt::AlignVCenter, str); QRectF text_rect = painter.boundingRect(
painter.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, str); QRectF(30, offset+5, 5, 10),
Qt::AlignLeft | Qt::AlignVCenter,
str);
painter.drawText(text_rect,
Qt::AlignLeft | Qt::AlignVCenter,
str);
bounding_rect = bounding_rect.united(text_rect); bounding_rect = bounding_rect.united(text_rect);
if (m_hovered_contacts_map.contains(elmt)) { if (m_hovered_contacts_map.contains(elmt)) {
@@ -754,10 +805,10 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
} }
/** /**
* @brief CrossRefItem::fillCrossRef @brief CrossRefItem::fillCrossRef
* Fill the content of the cross ref Fill the content of the cross ref
* @param painter painter to use. @param painter painter to use.
*/ */
void CrossRefItem::fillCrossRef(QPainter &painter) void CrossRefItem::fillCrossRef(QPainter &painter)
{ {
if (m_element->isFree()) return; if (m_element->isFree()) return;
@@ -773,7 +824,11 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
painter.setPen(pen); painter.setPen(pen);
QString str = elementPositionText(elmt, true); QString str = elementPositionText(elmt, true);
QRectF bounding = painter.boundingRect(QRectF(no_top_left, QSize(middle_cross, 1)), Qt::AlignLeft, str); QRectF bounding = painter.boundingRect(
QRectF(no_top_left,
QSize(middle_cross, 1)),
Qt::AlignLeft,
str);
painter.drawText(bounding, Qt::AlignLeft, str); painter.drawText(bounding, Qt::AlignLeft, str);
if (m_hovered_contacts_map.contains(elmt)) if (m_hovered_contacts_map.contains(elmt))
@@ -793,11 +848,16 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
foreach(Element *elmt, NCElements()) foreach(Element *elmt, NCElements())
{ {
QPen pen = painter.pen(); QPen pen = painter.pen();
m_hovered_contact == elmt ? pen.setColor(Qt::blue) :pen.setColor(Qt::black); m_hovered_contact == elmt ? pen.setColor(Qt::blue)
:pen.setColor(Qt::black);
painter.setPen(pen); painter.setPen(pen);
QString str = elementPositionText(elmt, true); QString str = elementPositionText(elmt, true);
QRectF bounding = painter.boundingRect(QRectF(nc_top_left, QSize(middle_cross, 1)), Qt::AlignRight, str); QRectF bounding = painter.boundingRect(
QRectF(nc_top_left,
QSize(middle_cross, 1)),
Qt::AlignRight,
str);
painter.drawText(bounding, Qt::AlignRight, str); painter.drawText(bounding, Qt::AlignRight, str);
if (m_hovered_contacts_map.contains(elmt)) if (m_hovered_contacts_map.contains(elmt))
@@ -814,14 +874,18 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
} }
/** /**
* @brief CrossRefItem::AddExtraInfo @brief CrossRefItem::AddExtraInfo
* Add the comment info of the parent item if needed. Add the comment info of the parent item if needed.
* @param painter painter to use for draw the text @param painter painter to use for draw the text
* @param type type of Info do be draw e.g. comment, location. @param type type of Info do be draw e.g. comment, location.
*/ */
void CrossRefItem::AddExtraInfo(QPainter &painter, const QString& type) void CrossRefItem::AddExtraInfo(QPainter &painter, const QString& type)
{ {
QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element); QString text = autonum::AssignVariables::formulaToLabel(
m_element->elementInformations()[type].toString(),
m_element->rSequenceStruct(),
m_element->diagram(),
m_element);
bool must_show = m_element -> elementInformations().keyMustShow(type); bool must_show = m_element -> elementInformations().keyMustShow(type);
if (!text.isEmpty() && must_show) if (!text.isEmpty() && must_show)
@@ -831,38 +895,51 @@ void CrossRefItem::AddExtraInfo(QPainter &painter, const QString& type)
QRectF r, text_bounding; QRectF r, text_bounding;
qreal center = boundingRect().center().x(); qreal center = boundingRect().center().x();
qreal width = boundingRect().width() > 70 ? boundingRect().width()/2 : 35; qreal width = boundingRect().width() > 70
? boundingRect().width()/2
: 35;
r = QRectF(QPointF(center - width, boundingRect().bottom()), r = QRectF(QPointF(center - width,
QPointF(center + width, boundingRect().bottom() + 1)); boundingRect().bottom()),
QPointF(center + width,
boundingRect().bottom() + 1));
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, text); text_bounding = painter.boundingRect(
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, text); r,
Qt::TextWordWrap | Qt::AlignHCenter,
text);
painter.drawText(text_bounding,
Qt::TextWordWrap | Qt::AlignHCenter,
text);
text_bounding.adjust(-1,0,1,0); //adjust only for better visual text_bounding.adjust(-1,0,1,0); //adjust only for better visual
m_shape_path.addRect(text_bounding); m_shape_path.addRect(text_bounding);
prepareGeometryChange(); prepareGeometryChange();
m_bounding_rect = m_bounding_rect.united(text_bounding); m_bounding_rect = m_bounding_rect.united(text_bounding);
if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2); if (type == "comment") painter.drawRoundedRect(text_bounding,
2,
2);
painter.restore(); painter.restore();
} }
} }
/** /**
* @brief CrossRefItem::NOElements @brief CrossRefItem::NOElements
* @return The linked elements of @m_element wich are open or switch contact. @return The linked elements of m_element wich are open or switch contact.
* If linked element is a power contact, xref propertie is set to don't show power contact If linked element is a power contact,
* and this cross item must be drawed as cross, the element is not append in the list. xref propertie is set to don't show power contact
*/ and this cross item must be drawed as cross,
the element is not append in the list.
*/
QList<Element *> CrossRefItem::NOElements() const QList<Element *> CrossRefItem::NOElements() const
{ {
QList<Element *> no_list; QList<Element *> no_list;
foreach (Element *elmt, m_element->linkedElements()) foreach (Element *elmt, m_element->linkedElements())
{ {
//We continue if element is a power contact and xref propertie //We continue if element is a power contact and xref propertie
//is set to don't show power contact //is set to don't show power contact
if (m_properties.displayHas() == XRefProperties::Cross && if (m_properties.displayHas() == XRefProperties::Cross &&
!m_properties.showPowerContact() && !m_properties.showPowerContact() &&
elmt -> kindInformations()["type"].toString() == "power") elmt -> kindInformations()["type"].toString() == "power")
@@ -880,19 +957,22 @@ QList<Element *> CrossRefItem::NOElements() const
} }
/** /**
* @brief CrossRefItem::NCElements @brief CrossRefItem::NCElements
* @return The linked elements of @m_element wich are close or switch contact @return The linked elements of m_element wich are close
* If linked element is a power contact, xref propertie is set to don't show power contact or switch contact
* and this cross item must be drawed as cross, the element is not append in the list. If linked element is a power contact,
*/ xref propertie is set to don't show power contact
and this cross item must be drawed as cross,
the element is not append in the list.
*/
QList<Element *> CrossRefItem::NCElements() const QList<Element *> CrossRefItem::NCElements() const
{ {
QList<Element *> nc_list; QList<Element *> nc_list;
foreach (Element *elmt, m_element->linkedElements()) foreach (Element *elmt, m_element->linkedElements())
{ {
//We continue if element is a power contact and xref propertie //We continue if element is a power contact and xref propertie
//is set to don't show power contact //is set to don't show power contact
if (m_properties.displayHas() == XRefProperties::Cross && if (m_properties.displayHas() == XRefProperties::Cross &&
!m_properties.showPowerContact() && !m_properties.showPowerContact() &&
elmt -> kindInformations()["type"].toString() == "power") elmt -> kindInformations()["type"].toString() == "power")

View File

@@ -29,16 +29,20 @@ class DynamicElementTextItem;
class ElementTextItemGroup; class ElementTextItemGroup;
/** /**
* @brief The CrossRefItem class @brief The CrossRefItem class
* This clas provide an item, for show the cross reference, like the contacts linked to a coil. This clas provide an item, for show the cross reference,
* The item setpos automaticaly when parent move. like the contacts linked to a coil.
* All slave displayed in cross ref will be updated when folio position change in the project. The item setpos automaticaly when parent move.
* It's the responsability of the master element to informe displayed slave are moved, All slave displayed in cross ref will be updated
* by calling the slot @updateLabel when folio position change in the project.
* By default master element is the parent graphics item of this Xref, It's the responsability of the master element
* but if the Xref must be snap to the label of master, the label become the parent of this Xref. to informe displayed slave are moved,
* This behavior can be changed at anytime by calling setProperties. by calling the slot updateLabel
*/ By default master element is the parent graphics item of this Xref,
but if the Xref must be snap to the label of master,
the label become the parent of this Xref.
This behavior can be changed at anytime by calling setProperties.
*/
class CrossRefItem : public QGraphicsObject class CrossRefItem : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
@@ -46,8 +50,10 @@ class CrossRefItem : public QGraphicsObject
//Methods //Methods
public: public:
explicit CrossRefItem(Element *elmt); explicit CrossRefItem(Element *elmt);
explicit CrossRefItem(Element *elmt, DynamicElementTextItem *text); explicit CrossRefItem(Element *elmt,
explicit CrossRefItem(Element *elmt, ElementTextItemGroup *group); DynamicElementTextItem *text);
explicit CrossRefItem(Element *elmt,
ElementTextItemGroup *group);
~CrossRefItem() override; ~CrossRefItem() override;
private: private:
void init(); void init();
@@ -57,55 +63,63 @@ class CrossRefItem : public QGraphicsObject
enum { Type = UserType + 1009 }; enum { Type = UserType + 1009 };
int type() const override { return Type; } int type() const override { return Type; }
/**
@brief The CONTACTS enum
*/
enum CONTACTS { enum CONTACTS {
NO = 1, NO = 1,
NC = 2, NC = 2,
NOC = 3, NOC = 3,
SW = 4, SW = 4,
Power = 8, Power = 8,
DelayOn = 16, DelayOn = 16,
DelayOff = 32, DelayOff = 32,
DelayOnOff = 64, DelayOnOff = 64,
Delay = 112 Delay = 112
}; };
QRectF boundingRect () const override; QRectF boundingRect() const override;
QPainterPath shape () const override; QPainterPath shape() const override;
QString elementPositionText (const Element *elmt, const bool &add_prefix = false) const; QString elementPositionText(
const Element *elmt,
const bool &add_prefix = false) const;
public slots: public slots:
void updateProperties (); void updateProperties();
void updateLabel (); void updateLabel();
void autoPos (); void autoPos();
protected: protected:
bool sceneEvent(QEvent *event) override; bool sceneEvent(QEvent *event) override;
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void paint(QPainter *painter,
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ) override; const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
void mouseDoubleClickEvent (
QGraphicsSceneMouseEvent * event ) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private: private:
void linkedChanged(); void linkedChanged();
void buildHeaderContact (); void buildHeaderContact();
void setUpCrossBoundingRect (QPainter &painter); void setUpCrossBoundingRect(QPainter &painter);
void drawAsCross (QPainter &painter); void drawAsCross(QPainter &painter);
void drawAsContacts (QPainter &painter); void drawAsContacts(QPainter &painter);
QRectF drawContact (QPainter &painter, int flags, Element *elmt); QRectF drawContact(QPainter &painter, int flags, Element *elmt);
void fillCrossRef (QPainter &painter); void fillCrossRef(QPainter &painter);
void AddExtraInfo (QPainter &painter, const QString&); void AddExtraInfo(QPainter &painter, const QString&);
QList<Element *> NOElements() const; QList<Element *> NOElements() const;
QList<Element *> NCElements() const; QList<Element *> NCElements() const;
//Attributes //Attributes
private: private:
Element *m_element; //element to display the cross reference Element *m_element; //element to display the cross reference
QRectF m_bounding_rect; QRectF m_bounding_rect;
QPicture m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc; QPicture m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc;
QPainterPath m_shape_path; QPainterPath m_shape_path;
XRefProperties m_properties; XRefProperties m_properties;
int m_drawed_contacts; int m_drawed_contacts;
QMultiMap <Element *, QRectF> m_hovered_contacts_map; QMultiMap <Element *, QRectF> m_hovered_contacts_map;
Element *m_hovered_contact = nullptr; Element *m_hovered_contact = nullptr;
DynamicElementTextItem *m_text = nullptr; DynamicElementTextItem *m_text = nullptr;

View File

@@ -28,6 +28,12 @@
* AddElementTextCommand* * AddElementTextCommand*
* **********************/ * **********************/
/**
@brief AddElementTextCommand::AddElementTextCommand
@param element
@param deti
@param parent
*/
AddElementTextCommand::AddElementTextCommand(Element *element, AddElementTextCommand::AddElementTextCommand(Element *element,
DynamicElementTextItem *deti, DynamicElementTextItem *deti,
QUndoCommand *parent): QUndoCommand *parent):
@@ -38,6 +44,9 @@ AddElementTextCommand::AddElementTextCommand(Element *element,
setText(QObject::tr("Ajouter un texte d'élément")); setText(QObject::tr("Ajouter un texte d'élément"));
} }
/**
@brief AddElementTextCommand::~AddElementTextCommand
*/
AddElementTextCommand::~AddElementTextCommand() AddElementTextCommand::~AddElementTextCommand()
{ {
if(m_text->parentGroup()) if(m_text->parentGroup())
@@ -47,6 +56,9 @@ AddElementTextCommand::~AddElementTextCommand()
delete m_text; delete m_text;
} }
/**
@brief AddElementTextCommand::undo
*/
void AddElementTextCommand::undo() void AddElementTextCommand::undo()
{ {
m_element->removeDynamicTextItem(m_text); m_element->removeDynamicTextItem(m_text);
@@ -54,6 +66,9 @@ void AddElementTextCommand::undo()
m_text->scene()->removeItem(m_text); m_text->scene()->removeItem(m_text);
} }
/**
@brief AddElementTextCommand::redo
*/
void AddElementTextCommand::redo() void AddElementTextCommand::redo()
{ {
m_text->setParentItem(m_element); m_text->setParentItem(m_element);
@@ -65,11 +80,11 @@ void AddElementTextCommand::redo()
* AddTextsGroupCommand* * AddTextsGroupCommand*
* *********************/ * *********************/
/** /**
* @brief AddTextsGroupCommand::AddTextsGroupCommand @brief AddTextsGroupCommand::AddTextsGroupCommand
* @param element : the element to add a new group @param element : the element to add a new group
* @param groupe_name : the name of the group @param groupe_name : the name of the group
* @param parent : parent undo @param parent : parent undo
*/ */
AddTextsGroupCommand::AddTextsGroupCommand(Element *element, AddTextsGroupCommand::AddTextsGroupCommand(Element *element,
QString groupe_name, QString groupe_name,
QUndoCommand *parent) : QUndoCommand *parent) :
@@ -81,11 +96,13 @@ AddTextsGroupCommand::AddTextsGroupCommand(Element *element,
} }
/** /**
* @brief AddTextsGroupCommand::AddTextsGroupCommand @brief AddTextsGroupCommand::AddTextsGroupCommand
* @param element : The element to add a new group @param element : The element to add a new group
* @param dom_element : the first time the group is created, we call the function fromXml of the group, and give @dom_element has argument. @param dom_element : the first time the group is created,
* @param parent : parent undo we call the function fromXml of the group,
*/ and give @dom_element has argument.
@param parent : parent undo
*/
AddTextsGroupCommand::AddTextsGroupCommand(Element *element, AddTextsGroupCommand::AddTextsGroupCommand(Element *element,
const QDomElement& dom_element, const QDomElement& dom_element,
QUndoCommand *parent) : QUndoCommand *parent) :
@@ -97,11 +114,12 @@ AddTextsGroupCommand::AddTextsGroupCommand(Element *element,
} }
/** /**
* @brief AddTextsGroupCommand::AddTextsGroupCommand @brief AddTextsGroupCommand::AddTextsGroupCommand
* @param element : The element to add a new group @param element : The element to add a new group
* @param texts_list : a list of texts to add to the created group (texts must be child of element) @param texts_list : a list of texts to add to the created group
* @param parent : parent undo (texts must be child of element)
*/ @param parent : parent undo
*/
AddTextsGroupCommand::AddTextsGroupCommand( AddTextsGroupCommand::AddTextsGroupCommand(
Element *element, Element *element,
QString groupe_name, QString groupe_name,
@@ -125,18 +143,24 @@ AddTextsGroupCommand::AddTextsGroupCommand(
} }
/** /**
* @brief AddTextsGroupCommand::~AddTextsGroupCommand @brief AddTextsGroupCommand::~AddTextsGroupCommand
* Destructor Destructor
*/ */
AddTextsGroupCommand::~AddTextsGroupCommand() AddTextsGroupCommand::~AddTextsGroupCommand()
{} {}
/**
@brief AddTextsGroupCommand::undo
*/
void AddTextsGroupCommand::undo() void AddTextsGroupCommand::undo()
{ {
if(m_element && m_group) if(m_element && m_group)
m_element.data()->removeTextGroup(m_group); m_element.data()->removeTextGroup(m_group);
} }
/**
@brief AddTextsGroupCommand::redo
*/
void AddTextsGroupCommand::redo() void AddTextsGroupCommand::redo()
{ {
if(!m_element) if(!m_element)
@@ -179,11 +203,11 @@ void AddTextsGroupCommand::redo()
* RemoveTextsGroupCommand* * RemoveTextsGroupCommand*
* ************************/ * ************************/
/** /**
* @brief RemoveTextsGroupCommand::RemoveTextsGroupCommand @brief RemoveTextsGroupCommand::RemoveTextsGroupCommand
* @param element : The element where we remove a group @param element : The element where we remove a group
* @param group : the group to remove @param group : the group to remove
* @param parent : the parent undo command @param parent : the parent undo command
*/ */
RemoveTextsGroupCommand::RemoveTextsGroupCommand(Element *element, RemoveTextsGroupCommand::RemoveTextsGroupCommand(Element *element,
ElementTextItemGroup *group, ElementTextItemGroup *group,
QUndoCommand *parent) : QUndoCommand *parent) :
@@ -197,9 +221,15 @@ RemoveTextsGroupCommand::RemoveTextsGroupCommand(Element *element,
m_text_list.append(deti); m_text_list.append(deti);
} }
/**
@brief RemoveTextsGroupCommand::~RemoveTextsGroupCommand
*/
RemoveTextsGroupCommand::~RemoveTextsGroupCommand() RemoveTextsGroupCommand::~RemoveTextsGroupCommand()
{} {}
/**
@brief RemoveTextsGroupCommand::undo
*/
void RemoveTextsGroupCommand::undo() void RemoveTextsGroupCommand::undo()
{ {
if(m_element && m_group) if(m_element && m_group)
@@ -214,6 +244,9 @@ void RemoveTextsGroupCommand::undo()
} }
} }
/**
@brief RemoveTextsGroupCommand::redo
*/
void RemoveTextsGroupCommand::redo() void RemoveTextsGroupCommand::redo()
{ {
if(m_element && m_group) if(m_element && m_group)
@@ -233,11 +266,11 @@ void RemoveTextsGroupCommand::redo()
* AddTextToGroupCommand* * AddTextToGroupCommand*
* **********************/ * **********************/
/** /**
* @brief AddTextToGroupCommand::AddTextToGroupCommand @brief AddTextToGroupCommand::AddTextToGroupCommand
* @param text @param text
* @param group @param group
* @param parent @param parent
*/ */
AddTextToGroupCommand::AddTextToGroupCommand(DynamicElementTextItem *text, AddTextToGroupCommand::AddTextToGroupCommand(DynamicElementTextItem *text,
ElementTextItemGroup *group, ElementTextItemGroup *group,
QUndoCommand *parent) : QUndoCommand *parent) :
@@ -250,9 +283,9 @@ AddTextToGroupCommand::AddTextToGroupCommand(DynamicElementTextItem *text,
} }
/** /**
* @brief AddTextToGroupCommand::~AddTextToGroupCommand @brief AddTextToGroupCommand::~AddTextToGroupCommand
* Destructor Destructor
*/ */
AddTextToGroupCommand::~AddTextToGroupCommand() AddTextToGroupCommand::~AddTextToGroupCommand()
{ {
if(m_group && m_text && m_element) if(m_group && m_text && m_element)
@@ -263,12 +296,18 @@ AddTextToGroupCommand::~AddTextToGroupCommand()
} }
} }
/**
@brief AddTextToGroupCommand::undo
*/
void AddTextToGroupCommand::undo() void AddTextToGroupCommand::undo()
{ {
if(m_element && m_group && m_text) if(m_element && m_group && m_text)
m_element.data()->removeTextFromGroup(m_text, m_group); m_element.data()->removeTextFromGroup(m_text, m_group);
} }
/**
@brief AddTextToGroupCommand::redo
*/
void AddTextToGroupCommand::redo() void AddTextToGroupCommand::redo()
{ {
if(m_element && m_group && m_text) if(m_element && m_group && m_text)
@@ -286,11 +325,11 @@ void AddTextToGroupCommand::redo()
* RemoveTextFromGroupCommand* * RemoveTextFromGroupCommand*
* ***************************/ * ***************************/
/** /**
* @brief RemoveTextFromGroupCommand::RemoveTextFromGroupCommand @brief RemoveTextFromGroupCommand::RemoveTextFromGroupCommand
* @param text : text to add to @group @param text : text to add to @group
* @param group @param group
* @param parent : parent undo command @param parent : parent undo command
*/ */
RemoveTextFromGroupCommand::RemoveTextFromGroupCommand( RemoveTextFromGroupCommand::RemoveTextFromGroupCommand(
DynamicElementTextItem *text, DynamicElementTextItem *text,
ElementTextItemGroup *group, ElementTextItemGroup *group,
@@ -304,9 +343,9 @@ RemoveTextFromGroupCommand::RemoveTextFromGroupCommand(
} }
/** /**
* @brief RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand @brief RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand
* Destructor Destructor
*/ */
RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand() RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand()
{ {
if(m_group && m_text && m_element) if(m_group && m_text && m_element)
@@ -317,12 +356,18 @@ RemoveTextFromGroupCommand::~RemoveTextFromGroupCommand()
} }
} }
/**
@brief RemoveTextFromGroupCommand::undo
*/
void RemoveTextFromGroupCommand::undo() void RemoveTextFromGroupCommand::undo()
{ {
if(m_element && m_group && m_text) if(m_element && m_group && m_text)
m_element.data()->addTextToGroup(m_text, m_group); m_element.data()->addTextToGroup(m_text, m_group);
} }
/**
@brief RemoveTextFromGroupCommand::redo
*/
void RemoveTextFromGroupCommand::redo() void RemoveTextFromGroupCommand::redo()
{ {
if(m_element && m_group && m_text) if(m_element && m_group && m_text)
@@ -334,11 +379,11 @@ void RemoveTextFromGroupCommand::redo()
* AlignmentTextsGroupCommand* * AlignmentTextsGroupCommand*
* ***************************/ * ***************************/
/** /**
* @brief AlignmentTextsGroupCommand::AlignmentTextsGroupCommand @brief AlignmentTextsGroupCommand::AlignmentTextsGroupCommand
* @param group : Group to change the alignment @param group : Group to change the alignment
* @param new_alignment : the new alignment of the group @param new_alignment : the new alignment of the group
* @param parent : the parent QUndoCommand of this undo @param parent : the parent QUndoCommand of this undo
*/ */
AlignmentTextsGroupCommand::AlignmentTextsGroupCommand( AlignmentTextsGroupCommand::AlignmentTextsGroupCommand(
ElementTextItemGroup *group, ElementTextItemGroup *group,
Qt::Alignment new_alignment, Qt::Alignment new_alignment,
@@ -361,18 +406,18 @@ AlignmentTextsGroupCommand::AlignmentTextsGroupCommand(
} }
/** /**
* @brief AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand @brief AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand
* Destructor Destructor
*/ */
AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand() AlignmentTextsGroupCommand::~AlignmentTextsGroupCommand()
{} {}
/** /**
* @brief AlignmentTextsGroupCommand::mergeWith @brief AlignmentTextsGroupCommand::mergeWith
* Try to merge this command with other command Try to merge this command with other command
* @param other @param other
* @return true if was merged, else false @return true if was merged, else false
*/ */
bool AlignmentTextsGroupCommand::mergeWith(const QUndoCommand *other) bool AlignmentTextsGroupCommand::mergeWith(const QUndoCommand *other)
{ {
if (id() != other->id() || other->childCount()) if (id() != other->id() || other->childCount())
@@ -388,8 +433,8 @@ bool AlignmentTextsGroupCommand::mergeWith(const QUndoCommand *other)
} }
/** /**
* @brief AlignmentTextsGroupCommand::undo @brief AlignmentTextsGroupCommand::undo
*/ */
void AlignmentTextsGroupCommand::undo() void AlignmentTextsGroupCommand::undo()
{ {
if(m_group) if(m_group)
@@ -409,8 +454,8 @@ void AlignmentTextsGroupCommand::undo()
} }
/** /**
* @brief AlignmentTextsGroupCommand::redo @brief AlignmentTextsGroupCommand::redo
*/ */
void AlignmentTextsGroupCommand::redo() void AlignmentTextsGroupCommand::redo()
{ {
if(m_group) if(m_group)

View File

@@ -27,9 +27,9 @@ class DynamicElementTextItem;
class ElementTextItemGroup; class ElementTextItemGroup;
/** /**
* @brief The AddElementTextCommand class @brief The AddElementTextCommand class
* Manage the adding of element text Manage the adding of element text
*/ */
class AddElementTextCommand : public QUndoCommand class AddElementTextCommand : public QUndoCommand
{ {
public: public:
@@ -47,9 +47,9 @@ class AddElementTextCommand : public QUndoCommand
}; };
/** /**
* @brief The AddTextsGroupCommand class @brief The AddTextsGroupCommand class
* Manage the adding of a texts group Manage the adding of a texts group
*/ */
class AddTextsGroupCommand : public QUndoCommand class AddTextsGroupCommand : public QUndoCommand
{ {
public: public:
@@ -78,9 +78,9 @@ class AddTextsGroupCommand : public QUndoCommand
}; };
/** /**
* @brief The RemoveTextsGroupCommand class @brief The RemoveTextsGroupCommand class
* Manage the removinf of a texts group Manage the removinf of a texts group
*/ */
class RemoveTextsGroupCommand : public QUndoCommand class RemoveTextsGroupCommand : public QUndoCommand
{ {
public: public:
@@ -98,6 +98,9 @@ class RemoveTextsGroupCommand : public QUndoCommand
QList<QPointer<DynamicElementTextItem>> m_text_list; QList<QPointer<DynamicElementTextItem>> m_text_list;
}; };
/**
@brief The AddTextToGroupCommand class
*/
class AddTextToGroupCommand : public QUndoCommand class AddTextToGroupCommand : public QUndoCommand
{ {
public: public:
@@ -115,6 +118,9 @@ class AddTextToGroupCommand : public QUndoCommand
QPointer<Element> m_element; QPointer<Element> m_element;
}; };
/**
@brief The RemoveTextFromGroupCommand class
*/
class RemoveTextFromGroupCommand : public QUndoCommand class RemoveTextFromGroupCommand : public QUndoCommand
{ {
public: public:
@@ -132,6 +138,9 @@ class RemoveTextFromGroupCommand : public QUndoCommand
QPointer<Element> m_element; QPointer<Element> m_element;
}; };
/**
@brief The AlignmentTextsGroupCommand class
*/
class AlignmentTextsGroupCommand : public QUndoCommand class AlignmentTextsGroupCommand : public QUndoCommand
{ {
public: public: