mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
add function to sort an elements list by the positions of elements.
this function is use by: cross ref item -> shild are always sorted element selector widget -> list of widget are sorted. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2931 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <ui/elementpropertieswidget.h>
|
#include <ui/elementpropertieswidget.h>
|
||||||
#include "elementprovider.h"
|
#include "elementprovider.h"
|
||||||
|
#include "diagramposition.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur pour un element sans scene ni parent
|
Constructeur pour un element sans scene ni parent
|
||||||
@@ -54,6 +55,8 @@ void Element::editProperty() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return true si l'element est mis en evidence
|
@return true si l'element est mis en evidence
|
||||||
*/
|
*/
|
||||||
@@ -499,3 +502,23 @@ void Element::initLink(QETProject *prj) {
|
|||||||
}
|
}
|
||||||
tmp_uuids_link.clear();
|
tmp_uuids_link.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief comparPos
|
||||||
|
* Compare position of the two elements. Compare 3 points:
|
||||||
|
* 1 folio - 2 row - 3 line
|
||||||
|
* returns a response when a comparison is found.
|
||||||
|
* @return true if elmt1 is at lower position than elmt 2, else false
|
||||||
|
*/
|
||||||
|
bool comparPos(const Element *elmt1, const Element *elmt2) {
|
||||||
|
//Compare folio first
|
||||||
|
if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex())
|
||||||
|
return elmt1->diagram()->folioIndex() < elmt2->diagram()->folioIndex();
|
||||||
|
//Compare the row in second
|
||||||
|
QString a = elmt1->diagram()->convertPosition(elmt1->scenePos()).letter();
|
||||||
|
QString b = elmt2->diagram()->convertPosition(elmt2->scenePos()).letter();
|
||||||
|
if (a != b)
|
||||||
|
return a<b;
|
||||||
|
//In last compare the line
|
||||||
|
return elmt1->pos().x() <= elmt2->pos().x();
|
||||||
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class Element : public QetGraphicsItem {
|
|||||||
virtual void unlinkAllElements() {}
|
virtual void unlinkAllElements() {}
|
||||||
virtual void unlinkElement(Element *) {}
|
virtual void unlinkElement(Element *) {}
|
||||||
void initLink(QETProject *);
|
void initLink(QETProject *);
|
||||||
QList<Element *> linkedElements () const;
|
QList<Element *> linkedElements ();
|
||||||
virtual int linkType() const {return link_type_;} // @return the linkable type
|
virtual int linkType() const {return link_type_;} // @return the linkable type
|
||||||
void newUuid() {uuid_ = QUuid::createUuid();} //create new uuid for this element
|
void newUuid() {uuid_ = QUuid::createUuid();} //create new uuid for this element
|
||||||
|
|
||||||
@@ -179,6 +179,8 @@ class Element : public QetGraphicsItem {
|
|||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool comparPos(const Element * elmt1, const Element * elmt2);
|
||||||
|
|
||||||
inline bool Element::isFree() const {
|
inline bool Element::isFree() const {
|
||||||
return (connected_elements.isEmpty());
|
return (connected_elements.isEmpty());
|
||||||
}
|
}
|
||||||
@@ -221,7 +223,12 @@ inline QUuid Element::uuid() const {
|
|||||||
return uuid_;
|
return uuid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QList <Element *> Element::linkedElements() const {
|
/**
|
||||||
|
* @brief Element::linkedElements
|
||||||
|
* @return the list of linked elements, the list is sorted by position
|
||||||
|
*/
|
||||||
|
inline QList <Element *> Element::linkedElements() {
|
||||||
|
qSort(connected_elements.begin(), connected_elements.end(), comparPos);
|
||||||
return connected_elements;
|
return connected_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ ElementSelectorWidget::ElementSelectorWidget(QList <Element *> elmt_list, QWidge
|
|||||||
selected_element(0),
|
selected_element(0),
|
||||||
showed_element(0)
|
showed_element(0)
|
||||||
{
|
{
|
||||||
|
qSort(elements_list.begin(), elements_list.end(), comparPos);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
buildInterface();
|
buildInterface();
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,7 @@ void ElementSelectorWidget::clear() {
|
|||||||
void ElementSelectorWidget::setList(QList<Element *> elmt_list) {
|
void ElementSelectorWidget::setList(QList<Element *> elmt_list) {
|
||||||
clear();
|
clear();
|
||||||
elements_list << elmt_list;
|
elements_list << elmt_list;
|
||||||
|
qSort(elements_list.begin(), elements_list.end(), comparPos);
|
||||||
buildInterface();
|
buildInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user