mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Element editor: revamped ElementScene::zItems() to fulfil the needs of ElementScene::managePrimitivesGroups()
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2029 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -291,7 +291,7 @@ void AddPartCommand::redo() {
|
|||||||
if (!part -> zValue()) {
|
if (!part -> zValue()) {
|
||||||
// the added part has no specific zValue already defined, we put it
|
// the added part has no specific zValue already defined, we put it
|
||||||
// above existing items (but still under terminals)
|
// above existing items (but still under terminals)
|
||||||
QList<QGraphicsItem *> existing_items = editor_scene_ -> zItems();
|
QList<QGraphicsItem *> existing_items = editor_scene_ -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
|
||||||
qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1;
|
qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1;
|
||||||
part -> setZValue(z);
|
part -> setZValue(z);
|
||||||
}
|
}
|
||||||
@@ -522,8 +522,8 @@ ChangeZValueCommand::ChangeZValueCommand(
|
|||||||
ElementEditionCommand(elmt, 0, parent),
|
ElementEditionCommand(elmt, 0, parent),
|
||||||
option(o)
|
option(o)
|
||||||
{
|
{
|
||||||
// recupere les parties de l'elements, sauf les bornes
|
// retrieve all primitives but terminals
|
||||||
QList<QGraphicsItem *> items_list = editor_scene_ -> zItems();
|
QList<QGraphicsItem *> items_list = editor_scene_ -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
|
||||||
|
|
||||||
// prend un snapshot des zValues
|
// prend un snapshot des zValues
|
||||||
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
|
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ const QDomDocument ElementScene::toXml(bool all_parts) const {
|
|||||||
|
|
||||||
QDomElement description = xml_document.createElement("description");
|
QDomElement description = xml_document.createElement("description");
|
||||||
// description de l'element
|
// description de l'element
|
||||||
foreach(QGraphicsItem *qgi, zItems(true)) {
|
foreach(QGraphicsItem *qgi, zItems()) {
|
||||||
// si l'export ne concerne que la selection, on ignore les parties non selectionnees
|
// si l'export ne concerne que la selection, on ignore les parties non selectionnees
|
||||||
if (!all_parts && !qgi -> isSelected()) continue;
|
if (!all_parts && !qgi -> isSelected()) continue;
|
||||||
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
|
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
|
||||||
@@ -961,30 +961,56 @@ QList<CustomElementPart *> ElementScene::primitives() const {
|
|||||||
@param include_terminals true pour inclure les bornes, false sinon
|
@param include_terminals true pour inclure les bornes, false sinon
|
||||||
@return les parties de l'element ordonnes par zValue croissante
|
@return les parties de l'element ordonnes par zValue croissante
|
||||||
*/
|
*/
|
||||||
QList<QGraphicsItem *> ElementScene::zItems(bool include_terminals) const {
|
QList<QGraphicsItem *> ElementScene::zItems(ItemOptions options) const {
|
||||||
// recupere les elements
|
// handle dummy request, i.e. when neither Selected nor NonSelected are set
|
||||||
QList<QGraphicsItem *> all_items_list(items());
|
if (!(options & ElementScene::Selected) && !(options & ElementScene::NonSelected)) {
|
||||||
|
return(QList<QGraphicsItem *>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrieve all items
|
||||||
|
QList<QGraphicsItem *> all_items_list(items());
|
||||||
|
QMutableListIterator<QGraphicsItem *> i(all_items_list);
|
||||||
|
|
||||||
|
// remove unrequired items
|
||||||
|
if ((options & ElementScene::SelectedOrNot) != ElementScene::SelectedOrNot) {
|
||||||
|
bool keep_selected = options & ElementScene::Selected;
|
||||||
|
while (i.hasNext()) {
|
||||||
|
if (i.next() -> isSelected() != keep_selected) {
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// enleve les bornes
|
|
||||||
QList<QGraphicsItem *> terminals;
|
QList<QGraphicsItem *> terminals;
|
||||||
foreach(QGraphicsItem *qgi, all_items_list) {
|
QList<QGraphicsItem *> helpers;
|
||||||
|
for (i.toFront(); i.hasNext(); ) {
|
||||||
|
i.next();
|
||||||
|
QGraphicsItem *qgi = i.value();
|
||||||
if (
|
if (
|
||||||
qgi -> type() == ElementPrimitiveDecorator::Type ||
|
qgi -> type() == ElementPrimitiveDecorator::Type ||
|
||||||
qgi -> type() == QGraphicsRectItem::Type
|
qgi -> type() == QGraphicsRectItem::Type
|
||||||
) {
|
) {
|
||||||
all_items_list.removeAt(all_items_list.indexOf(qgi));
|
i.remove();
|
||||||
|
helpers << qgi;
|
||||||
}
|
}
|
||||||
else if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
|
else if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
|
||||||
all_items_list.removeAt(all_items_list.indexOf(qgi));
|
i.remove();
|
||||||
terminals << qgi;
|
terminals << qgi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ordonne les parties par leur zValue
|
// ordonne les parties par leur zValue
|
||||||
qSort(all_items_list.begin(), all_items_list.end(), ElementScene::zValueLessThan);
|
if (options & SortByZValue) {
|
||||||
|
qSort(all_items_list.begin(), all_items_list.end(), ElementScene::zValueLessThan);
|
||||||
|
}
|
||||||
|
|
||||||
// rajoute eventuellement les bornes
|
// rajoute eventuellement les bornes
|
||||||
if (include_terminals) all_items_list += terminals;
|
if (options & ElementScene::IncludeTerminals) {
|
||||||
|
all_items_list += terminals;
|
||||||
|
}
|
||||||
|
if (options & ElementScene::IncludeHelperItems) {
|
||||||
|
all_items_list += helpers;
|
||||||
|
}
|
||||||
return(all_items_list);
|
return(all_items_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,7 +1019,7 @@ QList<QGraphicsItem *> ElementScene::zItems(bool include_terminals) const {
|
|||||||
*/
|
*/
|
||||||
ElementContent ElementScene::selectedContent() const {
|
ElementContent ElementScene::selectedContent() const {
|
||||||
ElementContent content;
|
ElementContent content;
|
||||||
foreach(QGraphicsItem *qgi, zItems(true)) {
|
foreach(QGraphicsItem *qgi, zItems()) {
|
||||||
if (qgi -> isSelected()) content << qgi;
|
if (qgi -> isSelected()) content << qgi;
|
||||||
}
|
}
|
||||||
return(content);
|
return(content);
|
||||||
@@ -1260,6 +1286,7 @@ bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2) {
|
|||||||
represents the current selection.
|
represents the current selection.
|
||||||
*/
|
*/
|
||||||
void ElementScene::managePrimitivesGroups() {
|
void ElementScene::managePrimitivesGroups() {
|
||||||
|
// this function is not supposed to be reentrant
|
||||||
if (!decorator_lock_ -> tryLock()) return;
|
if (!decorator_lock_ -> tryLock()) return;
|
||||||
|
|
||||||
if (!decorator_) {
|
if (!decorator_) {
|
||||||
@@ -1269,18 +1296,8 @@ void ElementScene::managePrimitivesGroups() {
|
|||||||
decorator_ -> hide();
|
decorator_ -> hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QGraphicsItem *> selected_items;
|
|
||||||
foreach (QGraphicsItem *item, items()) {
|
|
||||||
if (item -> type() == ElementPrimitiveDecorator::Type) continue;
|
|
||||||
if (item -> type() == QGraphicsRectItem::Type) continue;
|
|
||||||
if (item -> isSelected()) {
|
|
||||||
selected_items << item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// TODO export the above code to a proper method
|
|
||||||
|
|
||||||
|
|
||||||
// should we hide the decorator?
|
// should we hide the decorator?
|
||||||
|
QList<QGraphicsItem *> selected_items = zItems(ElementScene::Selected | ElementScene::IncludeTerminals);
|
||||||
if (!selected_items.count()) {
|
if (!selected_items.count()) {
|
||||||
decorator_ -> hide();
|
decorator_ -> hide();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -42,7 +42,17 @@ class ElementScene : public QGraphicsScene {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
// enum
|
// enum
|
||||||
|
public:
|
||||||
enum Behavior { Normal, Line, Rectangle, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
|
enum Behavior { Normal, Line, Rectangle, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
|
||||||
|
enum ItemOption {
|
||||||
|
SortByZValue = 1,
|
||||||
|
IncludeTerminals = 2,
|
||||||
|
IncludeHelperItems = 4,
|
||||||
|
Selected = 8,
|
||||||
|
NonSelected = 16,
|
||||||
|
SelectedOrNot = 24
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(ItemOptions, ItemOption);
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
@@ -130,7 +140,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual QList<CustomElementPart *> primitives() const;
|
virtual QList<CustomElementPart *> primitives() const;
|
||||||
virtual QList<QGraphicsItem *> zItems(bool = false) const;
|
virtual QList<QGraphicsItem *> zItems(ItemOptions options = ItemOptions(SortByZValue | IncludeTerminals | SelectedOrNot)) const;
|
||||||
virtual ElementContent selectedContent() const;
|
virtual ElementContent selectedContent() const;
|
||||||
virtual void getPasteArea(const QRectF &);
|
virtual void getPasteArea(const QRectF &);
|
||||||
QRectF borderRect() const;
|
QRectF borderRect() const;
|
||||||
@@ -209,6 +219,8 @@ class ElementScene : public QGraphicsScene {
|
|||||||
void pasteAreaDefined(const QRectF &);
|
void pasteAreaDefined(const QRectF &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param wid the new width for the currently edited element
|
@param wid the new width for the currently edited element
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1145,7 +1145,7 @@ void QETElementEditor::firstActivation(QEvent *event) {
|
|||||||
void QETElementEditor::slot_createPartsList() {
|
void QETElementEditor::slot_createPartsList() {
|
||||||
parts_list -> blockSignals(true);
|
parts_list -> blockSignals(true);
|
||||||
parts_list -> clear();
|
parts_list -> clear();
|
||||||
QList<QGraphicsItem *> qgis = ce_scene -> zItems(true);
|
QList<QGraphicsItem *> qgis = ce_scene -> zItems();
|
||||||
|
|
||||||
// on ne construit plus la liste a partir de 200 primitives
|
// on ne construit plus la liste a partir de 200 primitives
|
||||||
// c'est ingerable : la maj de la liste prend trop de temps et le resultat
|
// c'est ingerable : la maj de la liste prend trop de temps et le resultat
|
||||||
@@ -1179,7 +1179,7 @@ void QETElementEditor::slot_updatePartsList() {
|
|||||||
} else if (items_count <= QET_MAX_PARTS_IN_ELEMENT_EDITOR_LIST) {
|
} else if (items_count <= QET_MAX_PARTS_IN_ELEMENT_EDITOR_LIST) {
|
||||||
parts_list -> blockSignals(true);
|
parts_list -> blockSignals(true);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
QList<QGraphicsItem *> items = ce_scene -> zItems(true);
|
QList<QGraphicsItem *> items = ce_scene -> zItems();
|
||||||
for (int j = items.count() - 1 ; j >= 0 ; -- j) {
|
for (int j = items.count() - 1 ; j >= 0 ; -- j) {
|
||||||
QGraphicsItem *qgi = items[j];
|
QGraphicsItem *qgi = items[j];
|
||||||
QListWidgetItem *qlwi = parts_list -> item(i);
|
QListWidgetItem *qlwi = parts_list -> item(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user