Merge branch 'terminal_strip'

* terminal_strip:
  Terminal strip item can saved / loaded to .qet file
  See previous commit...
  Move terminal strip drawer class in is own file
  Fix wrong use of QStringLiteral and QLatin1String
  Double click a TerminalStripItem open the editor
  Minor change about checkable QAction of QetDiagramEditor
  Minor : corrects a minor aesthetic defect when unbridge terminals
  Revamp code
  Add and move terminal strip item are now managed by undo command
  TerminalStripItem : Draw terminal bridge
  Terminal strip item can be added to diagram
  Minor : add QGIUtility namespace
This commit is contained in:
joshua 2023-01-02 19:40:08 +01:00
commit 539e0a7a49
45 changed files with 1628 additions and 276 deletions

View File

@ -11,6 +11,7 @@ DiagramImageItem + 1007
QetShapItem + 1008
crossRefItem + 1009
DynamiqueElementTextItem + 1010
TerminalStripItem +1011
ElementPrimitiveDecorator + 2200
###ELEMENT EDITOR###

View File

@ -160,6 +160,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
$$files(sources/TerminalStrip/*.h) \
$$files(sources/TerminalStrip/ui/*.h) \
$$files(sources/TerminalStrip/UndoCommand/*.h) \
$$files(sources/TerminalStrip/GraphicsItem/*.h) \
$$files(sources/xml/*.h) \
$$files(sources/dxf/*.h)
SOURCES += $$files(sources/*.cpp) \
@ -197,6 +199,8 @@ SOURCES += $$files(sources/*.cpp) \
$$files(sources/TerminalStrip/*.cpp) \
$$files(sources/TerminalStrip/ui/*.cpp) \
$$files(sources/TerminalStrip/UndoCommand/*.cpp) \
$$files(sources/TerminalStrip/GraphicsItem/*.cpp) \
$$files(sources/xml/*.cpp) \
$$files(sources/dxf/*.cpp)
# Needed for use promote QTreeWidget in terminalstripeditor.ui

View File

@ -0,0 +1,231 @@
/*
Copyright 2006-2022 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 "terminalstripdrawer.h"
#include <QPainter>
#include "../physicalterminal.h"
#include "../realterminal.h"
#include "../terminalstrip.h"
#include "../terminalstripbridge.h"
/**
* @brief TerminalStripDrawer::TerminalStripDrawer
* @param strip
* @param pattern
*/
TerminalStripDrawer::TerminalStripDrawer(QPointer<TerminalStrip> strip) :
m_strip(strip)
{}
void TerminalStripDrawer::setStrip(TerminalStrip *strip)
{
m_strip = strip;
}
/**
* @brief TerminalStripDrawer::paint
* @param painter
*/
void TerminalStripDrawer::paint(QPainter *painter)
{
if (m_strip)
{
//To draw text, QPainter need a Qrect. Instead of create an instance
//for each text, we re-use the same instance of QRect.
QRect text_rect;
painter->save();
auto pen_{painter->pen()};
pen_.setColor(Qt::black);
pen_.setWidth(1);
auto brush_ = painter->brush();
brush_.setColor(Qt::white);
painter->setPen(pen_);
painter->setBrush(brush_);
//Draw header
painter->drawRect(m_pattern.m_header_rect);
//Draw the header text
painter->save();
if (m_pattern.m_header_text_orientation == Qt::Horizontal)
{
text_rect.setRect(0,m_pattern.m_header_rect.y(),m_pattern.m_header_rect.width(),m_pattern.m_header_rect.height());
}
else
{
painter->translate(m_pattern.m_header_rect.bottomLeft());
painter->rotate(270);
text_rect.setRect(0,0,m_pattern.m_header_rect.height(),m_pattern.m_header_rect.width());
}
const auto text_{m_strip->installation() + " " + m_strip->location() + " " + m_strip->name()};
painter->drawText(text_rect, text_, m_pattern.headerTextOption());
painter->restore();
//Move painter pos to next drawing
painter->translate(m_pattern.m_header_rect.width(),0);
int x_offset{m_pattern.m_header_rect.width()};
//Draw spacer
painter->drawRect(m_pattern.m_spacer_rect);
//Move painter pos to next drawing
painter->translate(m_pattern.m_spacer_rect.width(),0);
x_offset += m_pattern.m_spacer_rect.width();
//Draw terminals
const auto terminals_text_rect{m_pattern.m_terminals_text_rect};
const auto terminals_text_orientation{m_pattern.m_terminals_text_orientation};
const auto terminals_text_option{m_pattern.terminalsTextOption()};
QRect terminal_rect;
QHash<QUuid, QVector<QPointF>> bridges_anchor_points;
//Loop over physical terminals
for (const auto &physical_t : m_strip->physicalTerminal())
{
//Get the good offset according to how many level have the current physical terminal
const QVector<QSharedPointer<RealTerminal>> real_terminal{physical_t->realTerminals()};
const auto real_t_count{real_terminal.size()};
const auto offset_{4 - real_t_count};
//Loop over real terminals
for (auto i=0 ; i<real_t_count ; ++i)
{
const auto index_ = offset_ + i;
if (index_ >= 4) {
break;
}
terminal_rect = m_pattern.m_terminal_rect[index_];
//Draw terminal rect
painter->drawRect(terminal_rect);
//Draw text
painter->save();
if (terminals_text_orientation[index_] == Qt::Horizontal)
{
text_rect = terminals_text_rect[index_];
}
else
{
const auto rect_{terminals_text_rect[index_]};
painter->translate(rect_.bottomLeft());
painter->rotate(270);
text_rect.setRect(0, 0, rect_.height(), rect_.width());
}
const auto shared_real_terminal{real_terminal[i]};
painter->drawText(text_rect,
shared_real_terminal ? shared_real_terminal->label() : QLatin1String(),
terminals_text_option[index_]);
painter->restore();
//Add bridge anchor
if (shared_real_terminal->isBridged())
{
painter->save();
if (const auto bridge_ = shared_real_terminal->bridge())
{
const auto anchor_center{m_pattern.m_bridge_point_d/2};
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(QPointF{terminal_rect.width()/2, m_pattern.m_bridge_point_y_offset[index_]},
anchor_center,
anchor_center);
auto anchor_points{bridges_anchor_points.value(bridge_->uuid())};
anchor_points.append(QPointF{x_offset + terminal_rect.width()/2,
m_pattern.m_bridge_point_y_offset[index_]});
bridges_anchor_points.insert(bridge_->uuid(), anchor_points);
}
painter->restore();
}
//Move painter pos to next drawing
painter->translate(terminal_rect.width(),0);
x_offset += terminal_rect.width();
}
}
painter->restore();
//Draw the bridges
for (const auto &points_ : qAsConst(bridges_anchor_points))
{
painter->save();
auto pen_{painter->pen()};
pen_.setWidth(2);
painter->setPen(pen_);
painter->drawPolyline(QPolygonF{points_});
painter->restore();
}
}
}
QRectF TerminalStripDrawer::boundingRect() const
{
return QRect{0, 0, width(), height()};;
}
int TerminalStripDrawer::height() const
{
auto height_{m_pattern.m_header_rect.y() + m_pattern.m_header_rect.height()};
height_ = std::max(height_, m_pattern.m_spacer_rect.y() + m_pattern.m_spacer_rect.height());
for (const auto &rect : m_pattern.m_terminal_rect) {
height_ = std::max(height_, rect.y() + rect.height());
}
return height_;
}
int TerminalStripDrawer::width() const
{
int width_{m_pattern.m_header_rect.width() + m_pattern.m_spacer_rect.width()};
if (m_strip)
{
//Loop over physical terminals
for (const auto &physical_t : m_strip->physicalTerminal())
{
//Get the good offset according to how many level have the current physical terminal
const QVector<QSharedPointer<RealTerminal>> real_terminal{physical_t->realTerminals()};
const auto real_t_count{real_terminal.size()};
const auto offset_{4 - real_t_count};
//Loop over real terminals
for (auto i=0 ; i<real_t_count ; ++i)
{
const auto index_ = offset_ + i;
if (index_ >= 4) {
break;
}
width_ += m_pattern.m_terminal_rect[index_].width();
}
}
}
return width_;
}

View File

@ -0,0 +1,45 @@
/*
Copyright 2006-2022 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 TERMINALSTRIPDRAWER_H
#define TERMINALSTRIPDRAWER_H
#include <QPointer>
#include "terminalstriplayoutpattern.h"
class QPainter;
class TerminalStrip;
class TerminalStripDrawer
{
public:
TerminalStripDrawer(QPointer<TerminalStrip> strip = QPointer<TerminalStrip>());
void setStrip(TerminalStrip *strip);
void paint(QPainter *painter);
QRectF boundingRect() const;
private:
int height() const;
int width() const;
private:
QPointer<TerminalStrip> m_strip;
TerminalStripLayoutPattern m_pattern;
};
#endif // TERMINALSTRIPDRAWER_H

View File

@ -0,0 +1,107 @@
/*
Copyright 2006-2022 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 "terminalstripitem.h"
#include "../diagram.h"
#include "../../qetgraphicsitem/qgraphicsitemutility.h"
#include "../terminalstrip.h"
#include "../ui/terminalstripeditorwindow.h"
TerminalStripItem::TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsItem *parent) :
QetGraphicsItem{parent},
m_strip{strip},
m_drawer{strip}
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true);
}
TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) :
QetGraphicsItem { parent }
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true);
}
void TerminalStripItem::setTerminalStrip(TerminalStrip *strip)
{
m_strip = strip;
m_drawer.setStrip(strip);
m_pending_strip_uuid = QUuid();
}
/**
* @brief TerminalStripItem::terminalStrip
* @return The strip drawed by this item
*/
QPointer<TerminalStrip> TerminalStripItem::terminalStrip() const {
return m_strip;
}
void TerminalStripItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
m_drawer.paint(painter);
if (isSelected() || isHovered())
{
QGIUtility::drawBoundingRectSelection(this, painter);
}
}
QRectF TerminalStripItem::boundingRect() const
{
auto br_ = m_drawer.boundingRect();
br_.adjust(-5,-5,5,5);
return br_;
}
/**
* @brief TerminalStripItem::name
* @return usual name of this item
*/
QString TerminalStripItem::name() const {
return tr("plan de bornes");
}
void TerminalStripItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED (event);
if (m_strip) {
TerminalStripEditorWindow::edit(m_strip);
}
}
void TerminalStripItem::refreshPending()
{
if (!m_pending_strip_uuid.isNull()
&& diagram()
&& diagram()->project())
{
for (const auto &strip_ : diagram()->project()->terminalStrip()) {
if (strip_->uuid() == m_pending_strip_uuid) {
setTerminalStrip(strip_);
break;
}
}
}
}

View File

@ -0,0 +1,60 @@
/*
Copyright 2006-2022 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 TERMINALSTRIPITEM_H
#define TERMINALSTRIPITEM_H
#include <QGraphicsObject>
#include <QUuid>
#include "terminalstripdrawer.h"
#include "../../qetgraphicsitem/qetgraphicsitem.h"
class TerminalStrip;
class TerminalStripItem : public QetGraphicsItem
{
friend class TerminalStripItemXml;
Q_OBJECT
public:
TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsItem *parent = nullptr);
TerminalStripItem(QGraphicsItem *parent = nullptr);
void setTerminalStrip(TerminalStrip *strip);
QPointer<TerminalStrip> terminalStrip() const;
enum {Type = UserType + 1011};
int type() const override {return Type;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
QRectF boundingRect() const override;
QString name() const override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void refreshPending();
private:
QPointer<TerminalStrip> m_strip;
TerminalStripDrawer m_drawer;
QUuid m_pending_strip_uuid;
};
#endif // TERMINALSTRIPITEM_H

View File

@ -0,0 +1,78 @@
/*
Copyright 2006-2022 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 "terminalstriplayoutpattern.h"
#include <QDebug>
TerminalStripLayoutPattern::TerminalStripLayoutPattern()
{
updateHeaderTextOption();
updateTerminalsTextOption();
}
void TerminalStripLayoutPattern::setHeaderTextAlignment(const Qt::Alignment &alignment)
{
m_header_text_alignment = alignment;
updateHeaderTextOption();
}
Qt::Alignment TerminalStripLayoutPattern::headerTextAlignment() const
{
return m_header_text_alignment;
}
QTextOption TerminalStripLayoutPattern::headerTextOption() const {
return m_header_text_option;
}
void TerminalStripLayoutPattern::setTerminalsTextAlignment(const QVector<Qt::Alignment> &alignment)
{
m_terminals_text_alignment = alignment;
updateTerminalsTextOption();
}
QVector<Qt::Alignment> TerminalStripLayoutPattern::terminalsTextAlignment() const
{
return m_terminals_text_alignment;
}
QVector<QTextOption> TerminalStripLayoutPattern::terminalsTextOption() const
{
return m_terminals_text_option;
}
void TerminalStripLayoutPattern::updateHeaderTextOption()
{
m_header_text_option.setAlignment(m_header_text_alignment);
m_header_text_option.setWrapMode(QTextOption::WordWrap);
}
void TerminalStripLayoutPattern::updateTerminalsTextOption()
{
if (m_terminals_text_option.size() ==
m_terminals_text_alignment.size())
{
for (auto i = 0 ; i<m_terminals_text_option.size() ; ++i)
{
m_terminals_text_option[i].setAlignment(m_terminals_text_alignment.at(i));
m_terminals_text_option[i].setWrapMode(QTextOption::WordWrap);
}
}
else {
qDebug() << "TerminalStripLayoutPattern::updateTerminalsTextOption() : Wrong vector size";
}
}

View File

@ -0,0 +1,109 @@
/*
Copyright 2006-2022 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 TERMINALSTRIPLAYOUTPATTERN_H
#define TERMINALSTRIPLAYOUTPATTERN_H
#include <QSize>
#include <QTextOption>
#include <QVector>
#include <QRect>
/**
* @brief The TerminalStripLayoutPattern class
* A class with all values used to define how a terminal strip must be drawn.
* Most of the value are public, some values are private and have getter / setter
* because when these values change we need to compute the change.
*
* The values with name '_y_offset' mean offset is relating to the top
* of the QGraphicsItem used to display the terminal strip.
*
* The terminal strip can display up to 4 terminal level,
* the value used for multilevel terminal are stored in several QVector (m_terminal_y_offset, m_terminal_height, m_bridge_point_y_offset).
* The order of the values are from the most back terminal to the front terminal.
*/
class TerminalStripLayoutPattern
{
public:
TerminalStripLayoutPattern();
//Header of terminal strip
QRect m_header_rect{0,30,50,130};
Qt::Orientation m_header_text_orientation{Qt::Horizontal};
void setHeaderTextAlignment(const Qt::Alignment &alignment);
Qt::Alignment headerTextAlignment() const;
QTextOption headerTextOption() const;
//Spacer between the header and the terminals
QRect m_spacer_rect{0, 50, 10, 90};
//Terminals
QVector<QRect> m_terminal_rect
{
QRect{0, 0, 20, 190},
QRect{0, 10, 20, 170},
QRect{0, 20, 20, 150},
QRect{0, 30, 20, 130}
};
void setTerminalsTextAlignment(const QVector<Qt::Alignment> &alignment);
QVector<Qt::Alignment> terminalsTextAlignment() const;
QVector<QTextOption> terminalsTextOption() const;
QVector<QRect> m_terminals_text_rect
{
QRect{0,35,20,50},
QRect{0,35,20,50},
QRect{0,35,20,50},
QRect{0,35,20,50}
};
QVector<Qt::Orientation> m_terminals_text_orientation
{
Qt::Vertical,
Qt::Vertical,
Qt::Vertical,
Qt::Vertical
};
int m_bridge_point_d{5};
QVector<int> m_bridge_point_y_offset{50,70,90,110};
private:
void updateHeaderTextOption();
void updateTerminalsTextOption();
private:
Qt::Alignment m_header_text_alignment{Qt::AlignCenter};
QTextOption m_header_text_option;
QVector<Qt::Alignment> m_terminals_text_alignment
{
Qt::AlignRight | Qt::AlignVCenter,
Qt::AlignRight | Qt::AlignVCenter,
Qt::AlignRight | Qt::AlignVCenter,
Qt::AlignRight | Qt::AlignVCenter
};
QVector<QTextOption> m_terminals_text_option
{
QTextOption(),
QTextOption(),
QTextOption(),
QTextOption()
};
};
#endif // TERMINALSTRIPLAYOUTPATTERN_H

View File

@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bridgeterminalscommand.h"
#include "../terminalstripbridge.h"
BridgeTerminalsCommand::BridgeTerminalsCommand(TerminalStrip *strip,
QVector<QSharedPointer<RealTerminal>> real_terminal,
@ -57,8 +58,18 @@ UnBridgeTerminalsCommand::UnBridgeTerminalsCommand(TerminalStrip *strip,
if (strip->canUnBridge(real_terminal))
{
m_terminals = real_terminal;
m_bridge = strip->isBridged(real_terminal.first());
m_bridge = strip->isBridged(real_terminal.first());
//If bridge have one more terminals than @real_terminal
//that mean every terminals of the bridge must be unbridged by this undo command,
//else the single terminal who's not umbridged by this undo command
//continue to have a bridge (to nothing) and this nowhere bridge is visible
//in the terminal strip graphic item and terminal strip editor dialog.
if (m_bridge->realTerminals().size() == real_terminal.size() + 1) {
m_terminals = m_bridge->realTerminals();
} else {
m_terminals = real_terminal;
}
}
}

View File

@ -975,8 +975,9 @@ QDomElement TerminalStrip::toXml(QDomDocument &parent_document)
root_elmt.appendChild(m_data.toXml(parent_document));
//Undrawn terminals
auto xml_layout = parent_document.createElement("layout");
//Undrawed terminals
auto xml_layout = parent_document.createElement(QStringLiteral("layout"));
for (auto &phy_t : m_physical_terminals) {
xml_layout.appendChild(phy_t->toXml(parent_document));
}

View File

@ -120,6 +120,14 @@ void TerminalStripBridge::fromXml(const QDomElement &dom_element)
}
}
/**
* @brief TerminalStripBridge::uuid
* @return The uuid of this terminal
*/
QUuid TerminalStripBridge::uuid() const noexcept {
return m_uuid;
}
/**
* @brief TerminalStripBridge::addTerminals
* @param real_terminals

View File

@ -46,6 +46,7 @@ class TerminalStripBridge
static QString xmlTagName() {return QStringLiteral("terminal_strip_bridge");}
QDomElement toXml(QDomDocument &parent_document) const;
void fromXml(const QDomElement &dom_element);
QUuid uuid() const noexcept;
private:
bool addTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);

View File

@ -34,7 +34,7 @@ QDomElement TerminalStripData::toXml(QDomDocument &xml_document) const
root_elmt.setAttribute(QStringLiteral("uuid"), m_uuid.toString());
auto info_elmt = xml_document.createElement("informations");
auto info_elmt = xml_document.createElement(QStringLiteral("informations"));
root_elmt.appendChild(info_elmt);
if (!m_installation.isEmpty()) {
@ -65,23 +65,23 @@ bool TerminalStripData::fromXml(const QDomElement &xml_element)
return false;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
m_uuid = QUuid::fromString(xml_element.attribute(QLatin1String("uuid")));
m_uuid = QUuid::fromString(xml_element.attribute(QStringLiteral("uuid")));
#else
m_uuid = QUuid(xml_element.attribute(QStringLiteral("uuid")));
#endif
for (auto &xml_info :
QETXML::findInDomElement(xml_element.firstChildElement("informations"),
QStringLiteral("information")))
QETXML::findInDomElement(xml_element.firstChildElement(QStringLiteral("informations")),
QStringLiteral("information")))
{
auto name = xml_info.attribute("name");
auto name = xml_info.attribute(QStringLiteral("name"));
auto value = xml_info.text();
if (name == QStringLiteral("installation")) { m_installation = value;}
else if (name == QStringLiteral("location")) {m_location = value;}
else if (name == QStringLiteral("name")) {m_name = value;}
else if (name == QStringLiteral("comment")) {m_comment = value;}
else if (name == QStringLiteral("description")) {m_description = value;}
if (name == QLatin1String("installation")) { m_installation = value;}
else if (name == QLatin1String("location")) {m_location = value;}
else if (name == QLatin1String("name")) {m_name = value;}
else if (name == QLatin1String("comment")) {m_comment = value;}
else if (name == QLatin1String("description")) {m_description = value;}
}
return true;
@ -101,7 +101,7 @@ TerminalStripData &TerminalStripData::operator=(const TerminalStripData &other)
QDomElement TerminalStripData::infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value)
{
auto xml_elmt = xml_doc.createElement("information");
auto xml_elmt = xml_doc.createElement(QStringLiteral("information"));
xml_elmt.setAttribute(QStringLiteral("name"), name);
xml_elmt.appendChild(xml_doc.createTextNode(value));

View File

@ -0,0 +1,88 @@
/*
Copyright 2006-2022 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 "addterminalstripitemdialog.h"
#include "ui_addterminalstripitemdialog.h"
#include "../../undocommand/addgraphicsobjectcommand.h"
#include "../terminalstrip.h"
#include "../GraphicsItem/terminalstripitem.h"
#include "../../diagram.h"
void AddTerminalStripItemDialog::openDialog(Diagram *diagram, QWidget *parent)
{
AddTerminalStripItemDialog d(diagram->project(), parent);
if (d.exec())
{
const auto strip_{d.selectedTerminalStrip()};
if (strip_)
{
auto item_ = new TerminalStripItem(strip_);
diagram->addItem(item_);
item_->setPos(50, 50);
diagram->project()->undoStack()->push(new AddGraphicsObjectCommand(item_, diagram, QPointF{50, 50}));
}
}
}
AddTerminalStripItemDialog::AddTerminalStripItemDialog(QETProject *project, QWidget *parent) :
QDialog{parent},
m_project{project},
ui{new Ui::AddTerminalStripItemDialog}
{
ui->setupUi(this);
fillComboBox();
}
AddTerminalStripItemDialog::~AddTerminalStripItemDialog()
{
delete ui;
}
/**
* @brief AddTerminalStripItemDialog::selectedTerminalStrip
* @return The selected terminal strip or nullptr if no one is selected
* or error encounted.
*/
TerminalStrip *AddTerminalStripItemDialog::selectedTerminalStrip() const
{
if (m_project)
{
const QUuid uuid_{ui->m_terminal_strip_cb->currentData().toUuid()};
for (auto &&strip_ : m_project->terminalStrip())
{
if (strip_->uuid() == uuid_) {
return strip_;
}
}
}
return nullptr;
}
void AddTerminalStripItemDialog::fillComboBox()
{
if (m_project)
{
for (auto &&strip_ : m_project->terminalStrip())
{
const auto text{strip_->installation() + " " + strip_->location() + " " + strip_->name()};
ui->m_terminal_strip_cb->addItem(text, strip_->uuid());
}
}
}

View File

@ -0,0 +1,51 @@
/*
Copyright 2006-2022 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 ADDTERMINALSTRIPITEMDIALOG_H
#define ADDTERMINALSTRIPITEMDIALOG_H
#include <QDialog>
#include <QPointer>
class Diagram;
class QETDiagramEditor;
class QETProject;
class TerminalStrip;
namespace Ui {
class AddTerminalStripItemDialog;
}
class AddTerminalStripItemDialog : public QDialog
{
Q_OBJECT
public:
static void openDialog(Diagram *diagram, QWidget *parent = nullptr);
private:
explicit AddTerminalStripItemDialog(QETProject *project, QWidget *parent = nullptr);
~AddTerminalStripItemDialog();
TerminalStrip *selectedTerminalStrip() const;
void fillComboBox();
private:
QPointer<QETProject> m_project;
Ui::AddTerminalStripItemDialog *ui;
};
#endif // ADDTERMINALSTRIPITEMDIALOG_H

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddTerminalStripItemDialog</class>
<widget class="QDialog" name="AddTerminalStripItemDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<height>100</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Ajouter le plan de bornes suivant :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_terminal_strip_cb"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddTerminalStripItemDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddTerminalStripItemDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -333,7 +333,7 @@ QWidget *FreeTerminalModelDelegate::createEditor(QWidget *parent, const QStyleOp
{
if (index.column() == TYPE_CELL) {
auto qcb = new QComboBox(parent);
qcb->setObjectName(QLatin1String("terminal_type"));
qcb->setObjectName(QStringLiteral("terminal_type"));
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGeneric), ElementData::TTGeneric);
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTFuse), ElementData::TTFuse);
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTSectional), ElementData::TTSectional);
@ -344,7 +344,7 @@ QWidget *FreeTerminalModelDelegate::createEditor(QWidget *parent, const QStyleOp
}
if (index.column() == FUNCTION_CELL) {
auto qcb = new QComboBox(parent);
qcb->setObjectName(QLatin1String("terminal_function"));
qcb->setObjectName(QStringLiteral("terminal_function"));
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFGeneric), ElementData::TFGeneric);
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFPhase), ElementData::TFPhase);
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFNeutral), ElementData::TFNeutral);

View File

@ -19,6 +19,8 @@
#include "../UndoCommand/addterminalstripcommand.h"
#include "freeterminaleditor.h"
#include "../../qetapp.h"
#include "../../qetdiagrameditor.h"
#include "../../qetproject.h"
#include "../realterminal.h"
#include "../terminalstrip.h"
@ -27,6 +29,8 @@
#include "terminalstripeditorwindow.h"
#include "terminalstriptreedockwidget.h"
QPointer<TerminalStripEditorWindow> TerminalStripEditorWindow::window_;
static const int EMPTY_PAGE = 0;
static const int FREE_TERMINAL_PAGE = 1;
static const int TERMINAL_STRIP_PAGE = 2;
@ -35,6 +39,16 @@ static const int TERMINAL_STRIP_PAGE = 2;
* @param project
* @param parent
*/
void TerminalStripEditorWindow::edit(TerminalStrip *strip)
{
if (const auto project_ = strip->project())
{
auto editor_ = TerminalStripEditorWindow::instance(project_, QETApp::diagramEditor(project_));
editor_->setCurrentStrip(strip);
editor_->show();
}
}
TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TerminalStripEditorWindow),
@ -59,7 +73,11 @@ TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidge
*/
TerminalStripEditorWindow::~TerminalStripEditorWindow()
{
delete ui;
delete ui;
}
void TerminalStripEditorWindow::setCurrentStrip(TerminalStrip *strip) {
m_tree_dock->setSelectedStrip(strip);
}
/**

View File

@ -19,6 +19,8 @@
#define TERMINALSTRIPEDITORWINDOW_H
#include <QMainWindow>
#include <QMutex>
#include <QPointer>
class QETProject;
class TerminalStripTreeDockWidget;
@ -35,16 +37,47 @@ class TerminalStripEditorWindow : public QMainWindow
{
Q_OBJECT
public:
private:
//We need to use a QPointer instead of a raw pointer because when window_
//have got a parent widget, the parent widget can delete the window_
//instance in her destrucor and then window_ become a dangling pointer.
static QPointer<TerminalStripEditorWindow> window_;
public:
static TerminalStripEditorWindow* instance(QETProject *project, QWidget *parent = nullptr) {
static QMutex mutex_;
if (!window_) {
mutex_.lock();
if (!window_)
window_ = new TerminalStripEditorWindow{project, parent};
mutex_.unlock();
}
return window_;
}
static void dropInstance () {
static QMutex mutex;
if (window_) {
mutex.lock();
window_->deleteLater();
window_.clear();
mutex.unlock();
}
}
static void edit(TerminalStrip *strip);
public:
explicit TerminalStripEditorWindow(QETProject *project, QWidget *parent = nullptr);
~TerminalStripEditorWindow();
void setCurrentStrip(TerminalStrip *strip);
private slots:
void on_m_add_terminal_strip_triggered();
void on_m_remove_terminal_triggered();
void on_m_reload_triggered();
void on_m_button_box_clicked(QAbstractButton *button);
void on_m_stacked_widget_currentChanged(int arg1);
private:

View File

@ -794,7 +794,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
{
if (index.column() == TYPE_CELL) {
auto qcb = new QComboBox(parent);
qcb->setObjectName(QLatin1String("terminal_type"));
qcb->setObjectName(QStringLiteral("terminal_type"));
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGeneric), ElementData::TTGeneric);
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTFuse), ElementData::TTFuse);
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTSectional), ElementData::TTSectional);
@ -805,7 +805,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
}
if (index.column() == FUNCTION_CELL) {
auto qcb = new QComboBox(parent);
qcb->setObjectName(QLatin1String("terminal_function"));
qcb->setObjectName(QStringLiteral("terminal_function"));
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFGeneric), ElementData::TFGeneric);
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFPhase), ElementData::TFPhase);
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFNeutral), ElementData::TFNeutral);

View File

@ -18,6 +18,8 @@
#include "diagram.h"
#include "ElementsCollection/elementcollectionhandler.h"
#include "TerminalStrip/GraphicsItem/terminalstripitem.h"
#include "xml/terminalstripitemxml.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "diagramcommands.h"
#include "diagramcontent.h"
@ -873,6 +875,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
QVector<DiagramImageItem *> list_images;
QVector<QetShapeItem *> list_shapes;
QVector<QetGraphicsTableItem *> table_vector;
QVector<TerminalStripItem *> strip_vector;
//Ckeck graphics item to "XMLise"
for(QGraphicsItem *qgi : items())
@ -922,6 +925,12 @@ QDomDocument Diagram::toXml(bool whole_content) {
if (whole_content || table->isSelected())
table_vector << table;
}
case TerminalStripItem::Type: {
const auto strip = static_cast<TerminalStripItem *>(qgi);
if (whole_content || strip->isSelected()) {
strip_vector << strip;
}
}
}
}
@ -979,6 +988,11 @@ QDomDocument Diagram::toXml(bool whole_content) {
dom_root.appendChild(tables);
}
if (!strip_vector.isEmpty()) {
dom_root.appendChild(TerminalStripItemXml::toXml(strip_vector, document));
}
return(document);
}
@ -1423,6 +1437,9 @@ bool Diagram::fromXml(QDomElement &document,
added_tables << table;
}
//Load terminal strip item
QVector<TerminalStripItem *> added_strips { TerminalStripItemXml::fromXml(this, root) };
//Translate items if a new position was given in parameter
if (position != QPointF())
{
@ -1433,6 +1450,7 @@ bool Diagram::fromXml(QDomElement &document,
for (auto text : qAsConst(added_texts )) added_items << text;
for (auto image : qAsConst(added_images )) added_items << image;
for (auto table : qAsConst(added_tables )) added_items << table;
for (const auto &strip : qAsConst(added_strips)) added_items << strip;
//Get the top left corner of the rectangle that contain all added items
QRectF items_rect;
@ -1473,8 +1491,9 @@ bool Diagram::fromXml(QDomElement &document,
content_ptr -> m_shapes = QSet<QetShapeItem *>(
added_shapes.begin(),
added_shapes.end());
content_ptr->m_terminal_strip.swap(added_strips);
#endif
content_ptr -> m_tables = added_tables;
content_ptr->m_tables.swap(added_tables);
}
adjustSceneRect();
@ -1528,20 +1547,25 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root,
*/
void Diagram::refreshContents()
{
ElementProvider provider_(this);
DiagramContent dc_(this, false);
for (Element *elmt : elements())
{
for (auto &elmt : dc_.m_elements) {
elmt->initLink(project());
for (DynamicElementTextItem *deti : elmt->dynamicTextItems())
for (auto &deti : elmt->dynamicTextItems())
deti->refreshLabelConnection();
}
for (Conductor *conductor : conductors())
for (auto &conductor : dc_.conductors()) {
conductor->refreshText();
}
for (auto table : provider_.table())
for (auto &table : qAsConst(dc_.m_tables)) {
table->initLink();
}
for (auto &strip :qAsConst(dc_.m_terminal_strip)) {
strip->refreshPending();
}
}
/**

View File

@ -148,153 +148,6 @@ CutDiagramCommand::~CutDiagramCommand()
{
}
/**
@brief MoveElementsCommand::MoveElementsCommand
Constructor
@param dia diagram
@param diagram_content diagram content (contain all items to be moved)
@param m movement to applied
@param parent parent undo command
*/
MoveElementsCommand::MoveElementsCommand(
Diagram *dia,
const DiagramContent &diagram_content,
const QPointF &m,
QUndoCommand *parent
) :
QUndoCommand (parent),
diagram (dia),
content_to_move (diagram_content),
movement (m),
m_anim_group (nullptr),
first_redo (true)
{
QString moved_content_sentence = content_to_move.sentence(
DiagramContent::Elements |
DiagramContent::TextFields |
DiagramContent::ConductorsToUpdate |
DiagramContent::ConductorsToMove |
DiagramContent::Images |
DiagramContent::Shapes |
DiagramContent::ElementTextFields
);
setText(
QString(
QObject::tr(
"déplacer %1",
"undo caption - %1 is a sentence listing the moved content"
).arg(moved_content_sentence)
)
);
}
/**
@brief MoveElementsCommand::~MoveElementsCommand
Destructor
*/
MoveElementsCommand::~MoveElementsCommand()
{
delete m_anim_group;
}
/**
@brief MoveElementsCommand::undo
*/
void MoveElementsCommand::undo()
{
diagram -> showMe();
m_anim_group->setDirection(QAnimationGroup::Forward);
m_anim_group->start();
QUndoCommand::undo();
}
/**
@brief MoveElementsCommand::redo
*/
void MoveElementsCommand::redo()
{
diagram -> showMe();
if (first_redo) {
first_redo = false;
move(-movement);
}
else {
m_anim_group->setDirection(QAnimationGroup::Backward);
m_anim_group->start();
}
QUndoCommand::redo();
}
/**
@brief MoveElementsCommand::move
Move item and conductor to actual_movement
@param actual_movement movement to be applied
*/
void MoveElementsCommand::move(const QPointF &actual_movement)
{
typedef DiagramContent dc;
//Move every movable items, except conductor
for (QGraphicsItem *qgi : content_to_move.items(dc::Elements
| dc::TextFields
| dc::Images
| dc::Shapes
| dc::TextGroup
| dc::ElementTextFields
| dc::Tables))
{
//If current item has parent, and parent item is in content_to_move
//we don't apply movement to this item, because this item will be moved by is parent.
if (qgi->parentItem())
if (content_to_move.items().contains(qgi->parentItem()))
continue;
if(qgi->toGraphicsObject())
setupAnimation(qgi->toGraphicsObject(), "pos",
qgi->pos(), qgi->pos() + actual_movement);
else if(qgi->type() == QGraphicsItemGroup::Type)
{
//ElementTextItemGroup is a QObject but not a QGraphicsObject
if(ElementTextItemGroup *etig = dynamic_cast<ElementTextItemGroup *>(qgi))
setupAnimation(etig, "pos", etig->pos(),
etig->pos() + actual_movement);
}
else qgi -> setPos(qgi->pos() + actual_movement);
}
// Move some conductors
for (Conductor *conductor : content_to_move.m_conductors_to_move)
setupAnimation(conductor, "pos", conductor->pos(),
conductor->pos() + actual_movement);
// Recalcul the path of other conductor
for (Conductor *conductor : content_to_move.m_conductors_to_update)
setupAnimation(conductor, "animPath", 1, 1);
}
/**
@brief MoveElementsCommand::setupAnimation
Set up the animation for this undo command
@param target object to anim
@param propertyName property to animate
@param start value at start
@param end value at end
*/
void MoveElementsCommand::setupAnimation(QObject *target,
const QByteArray &propertyName,
const QVariant& start,
const QVariant& end) {
//create animation group if not yet.
if (m_anim_group == nullptr) m_anim_group = new QParallelAnimationGroup();
QPropertyAnimation *animation = new QPropertyAnimation(target, propertyName);
animation->setDuration(300);
animation->setStartValue(start);
animation->setEndValue(end);
animation->setEasingCurve(QEasingCurve::OutQuad);
m_anim_group->addAnimation(animation);
}
/**
@brief MoveConductorsTextsCommand::MoveConductorsTextsCommand
Constructeur

View File

@ -69,45 +69,6 @@ class CutDiagramCommand : public DeleteQGraphicsItemCommand {
CutDiagramCommand(const CutDiagramCommand &);
};
/**
@brief The MoveElementsCommand class
This command moves some content on a particular diagram.
*/
class MoveElementsCommand : public QUndoCommand {
// constructors, destructor
public:
MoveElementsCommand(Diagram *, const DiagramContent &,
const QPointF &m, QUndoCommand * = nullptr);
~MoveElementsCommand() override;
private:
MoveElementsCommand(const MoveElementsCommand &);
// methods
public:
void undo() override;
void redo() override;
virtual void move(const QPointF &);
private:
void setupAnimation (QObject * target,
const QByteArray &propertyName,
const QVariant& start,
const QVariant& end);
// attributes
private:
/// diagram the movement takes place on.
Diagram *diagram;
/// moved content
DiagramContent content_to_move;
/// applied movement
QPointF movement;
///animation group
QParallelAnimationGroup *m_anim_group;
/// prevent the first call to redo()
bool first_redo;
};
/**
@brief The MoveConductorsTextsCommand class
This command moves text items related to conductors

View File

@ -28,6 +28,7 @@
#include "qetgraphicsitem/independenttextitem.h"
#include "qetgraphicsitem/qetshapeitem.h"
#include "qetgraphicsitem/terminal.h"
#include "TerminalStrip/GraphicsItem/terminalstripitem.h"
#include <QGraphicsItem>
@ -54,7 +55,7 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) :
item_list = diagram->items();
}
for (auto item : item_list)
for (const auto &item : qAsConst(item_list))
{
switch (item->type())
{
@ -88,6 +89,7 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) :
break;
}
case QetGraphicsTableItem::Type: { m_tables << qgraphicsitem_cast<QetGraphicsTableItem *>(item); break;}
case TerminalStripItem::Type : {m_terminal_strip << qgraphicsitem_cast<TerminalStripItem *>(item); break;}
}
}
@ -194,13 +196,14 @@ bool DiagramContent::hasDeletableItems() const
{
for(QGraphicsItem *qgi : m_selected_items)
{
if (qgi->type() == Element::Type ||
qgi->type() == Conductor::Type ||
qgi->type() == IndependentTextItem::Type ||
qgi->type() == QetShapeItem::Type ||
qgi->type() == DiagramImageItem::Type ||
qgi->type() == DynamicElementTextItem::Type ||
qgi->type() == QetGraphicsTableItem::Type)
if (qgi->type() == Element::Type
|| qgi->type() == Conductor::Type
|| qgi->type() == IndependentTextItem::Type
|| qgi->type() == QetShapeItem::Type
|| qgi->type() == DiagramImageItem::Type
|| qgi->type() == DynamicElementTextItem::Type
|| qgi->type() == QetGraphicsTableItem::Type
|| qgi->type() == TerminalStripItem::Type)
return true;
if(qgi->type() == QGraphicsItemGroup::Type)
if(dynamic_cast<ElementTextItemGroup *>(qgi))
@ -240,6 +243,7 @@ void DiagramContent::clear()
m_texts_groups.clear();
m_selected_items.clear();
m_tables.clear();
m_terminal_strip.clear();
}
/**
@ -378,7 +382,7 @@ QList<QGraphicsItem *> DiagramContent::items(int filter) const
{
QList<QGraphicsItem *> items_list;
for(QGraphicsItem *qgi : conductors(filter)) items_list << qgi;
for(auto &&qgi : conductors(filter)) items_list << qgi;
if (filter & Elements) for(auto qgi : m_elements) items_list << qgi;
if (filter & TextFields) for(auto qgi : m_text_fields) items_list << qgi;
@ -387,9 +391,10 @@ QList<QGraphicsItem *> DiagramContent::items(int filter) const
if (filter & ElementTextFields) for(auto qgi : m_element_texts) items_list << qgi;
if (filter & TextGroup) for(auto qgi : m_texts_groups) items_list << qgi;
if (filter & Tables) for(auto qgi : m_tables) items_list << qgi;
if (filter & TerminalStrip) for(const auto qgi : qAsConst(m_terminal_strip)) items_list << qgi;
if (filter & SelectedOnly) {
for(QGraphicsItem *qgi : items_list) {
for(const auto &qgi : qAsConst(items_list)) {
if (!qgi -> isSelected()) items_list.removeOne(qgi);
}
}
@ -415,6 +420,7 @@ int DiagramContent::count(int filter) const
if (filter & ElementTextFields) for(auto deti : m_element_texts) { if (deti -> isSelected()) ++ count; }
if (filter & TextGroup) for(auto etig : m_texts_groups) { if (etig -> isSelected()) ++ count; }
if (filter & Tables) for(auto table : m_tables) { if (table -> isSelected()) ++ count; }
if (filter & TerminalStrip) for(const auto &strip : qAsConst(m_terminal_strip)) {if (strip->isSelected()) ++ count;}
}
else {
if (filter & Elements) count += m_elements.count();
@ -427,6 +433,7 @@ int DiagramContent::count(int filter) const
if (filter & ElementTextFields) count += m_element_texts.count();
if (filter & TextGroup) count += m_texts_groups.count();
if (filter & Tables) count += m_tables.count();
if (filter & TerminalStrip) count += m_terminal_strip.count();
}
return(count);
}
@ -447,7 +454,7 @@ QString DiagramContent::sentence(int filter) const
int shapes_count = (filter & Shapes) ? m_shapes.count() : 0;
int elmt_text_count = (filter & ElementTextFields) ? m_element_texts.count() : 0;
int tables_count = (filter & Tables) ? m_tables.count() : 0;
const int strip_count = (filter & TerminalStrip) ? m_terminal_strip.count() : 0;
return(
QET::ElementsAndConductorsSentence(
elements_count,
@ -456,7 +463,8 @@ QString DiagramContent::sentence(int filter) const
images_count,
shapes_count,
elmt_text_count,
tables_count
tables_count,
strip_count
)
);
}

View File

@ -32,6 +32,7 @@ class ElementTextItemGroup;
class Diagram;
class DiagramTextItem;
class QetGraphicsTableItem;
class TerminalStripItem;
/**
This class provides a container that makes the transmission of diagram content
@ -62,8 +63,9 @@ class DiagramContent
Shapes = 128,
TextGroup = 256,
Tables = 512,
All = 1023,
SelectedOnly = 1024
TerminalStrip = 1024,
All = 2047,
SelectedOnly = 2048
};
QList<Element *> m_elements;
@ -78,6 +80,7 @@ class DiagramContent
QSet<ElementTextItemGroup *> m_texts_groups;
QList<QGraphicsItem *> m_selected_items;
QVector<QetGraphicsTableItem *> m_tables;
QVector<TerminalStripItem *> m_terminal_strip;
QList<DiagramTextItem *> selectedTexts() const;

View File

@ -20,7 +20,6 @@
#include "conductorautonumerotation.h"
#include "diagram.h"
#include "qetgraphicsitem/conductor.h"
#include "diagramcommands.h"
#include "qetgraphicsitem/conductortextitem.h"
#include "qetgraphicsitem/diagramimageitem.h"
#include "qetgraphicsitem/dynamicelementtextitem.h"
@ -30,6 +29,7 @@
#include "undocommand/addgraphicsobjectcommand.h"
#include "qetapp.h"
#include "qetdiagrameditor.h"
#include "undocommand/movegraphicsitemcommand.h"
/**
@brief ElementsMover::ElementsMover Constructor
@ -176,18 +176,19 @@ void ElementsMover::endMovement()
//Create undo move if there is a movement
if (!m_current_movement.isNull()) {
QUndoCommand *quc{new MoveElementsCommand(m_diagram, m_moved_content, m_current_movement, undo_object)};
QUndoCommand *quc{new MoveGraphicsItemCommand(m_diagram, m_moved_content, m_current_movement, undo_object)};
undo_object->setText(quc->text());
}
//There is only one element moved, and project authorize auto conductor,
//we try auto connection of conductor;
typedef DiagramContent dc;
if (m_moved_content.items(dc::TextFields
| dc::Images
| dc::Shapes).isEmpty()
&& m_moved_content.items(dc::Elements).size() == 1
&& m_diagram->project()->autoConductor())
if (m_moved_content.items(dc::TextFields
| dc::Images
| dc::Shapes
| dc::TerminalStrip).isEmpty()
&& m_moved_content.items(dc::Elements).size() == 1
&& m_diagram->project()->autoConductor())
{
const Element *elmt{m_moved_content.m_elements.first()};
const auto aligned_free_terminals{elmt->AlignedFreeTerminals()};

View File

@ -266,7 +266,8 @@ QString QET::ElementsAndConductorsSentence(
int images_count,
int shapes_count,
int element_text_count,
int tables_count)
int tables_count,
int terminal_strip_count)
{
QString text;
if (elements_count) {
@ -329,6 +330,14 @@ QString QET::ElementsAndConductorsSentence(
tables_count);
}
if (terminal_strip_count) {
if (!text.isEmpty()) text += ", ";
text += QObject::tr(
"%n plan de bornes",
"part of a sentence listing the content of a diagram",
terminal_strip_count);
}
return(text);
}

View File

@ -162,7 +162,14 @@ namespace QET {
bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = nullptr);
bool attributeIsAnInteger(const QDomElement &, const QString& , int * = nullptr);
bool attributeIsAReal(const QDomElement &, const QString& , qreal * = nullptr);
QString ElementsAndConductorsSentence(int elements=0, int conductors=0, int indi_texts=0, int images=0, int shapes=0, int element_text=0, int tables_count=0);
QString ElementsAndConductorsSentence(int elements=0,
int conductors=0,
int indi_texts=0,
int images=0,
int shapes=0,
int element_text=0,
int tables_count=0,
int terminal_strip_count=0);
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
QList<QChar> forbiddenCharacters();

View File

@ -36,6 +36,7 @@
#include "ui/aboutqetdialog.h"
#include "ui/configpage/generalconfigurationpage.h"
#include "machine_info.h"
#include "TerminalStrip/ui/terminalstripeditorwindow.h"
#include <cstdlib>
#include <iostream>
@ -159,6 +160,7 @@ QETApp::~QETApp()
ElementFactory::dropInstance();
ElementPictureFactory::dropInstance();
MachineInfo::dropInstance();
TerminalStripEditorWindow::dropInstance();
}
@ -1129,7 +1131,28 @@ QFont QETApp::indiTextsItemFont(qreal size)
*/
QList<QETDiagramEditor *> QETApp::diagramEditors()
{
return(QETApp::instance() -> detectWindows<QETDiagramEditor>());
return(QETApp::instance() -> detectWindows<QETDiagramEditor>());
}
/**
* @brief QETApp::diagramEditor
* @param project
* @return The diagram editor of @a project or nullptr.
*/
QETDiagramEditor *QETApp::diagramEditor(QETProject *project)
{
for (const auto &editor : QETApp::instance()->detectWindows<QETDiagramEditor>())
{
for (const auto &project_view : editor->openedProjects())
{
if (project_view->project() == project)
{
return editor;
}
}
}
return nullptr;
}
/**

View File

@ -148,7 +148,8 @@ class QETApp : public QObject
static QFont indiTextsItemFont (qreal = -1.0);
static QETDiagramEditor *diagramEditorForFile(const QString &);
static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child);
static QList<QETDiagramEditor *> diagramEditors();
static QList<QETDiagramEditor *> diagramEditors();
static QETDiagramEditor* diagramEditor(QETProject *project);
static QList<QETElementEditor *> elementEditors();
static QList<QETElementEditor *> elementEditors(QETProject *);
static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors();

View File

@ -44,6 +44,7 @@
#include "diagram.h"
#include "TerminalStrip/ui/terminalstripeditorwindow.h"
#include "ui/diagrameditorhandlersizewidget.h"
#include "TerminalStrip/ui/addterminalstripitemdialog.h"
#ifdef BUILD_WITHOUT_KF5
#else
@ -446,8 +447,7 @@ void QETDiagramEditor::setUpActions()
{
if (auto project = this->currentProject())
{
auto tsew {new TerminalStripEditorWindow{project, this}};
tsew->show();
TerminalStripEditorWindow::instance(project, this)->show();
}
});
@ -664,6 +664,7 @@ void QETDiagramEditor::setUpActions()
QAction *add_rectangle = m_add_item_actions_group.addAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle"));
QAction *add_ellipse = m_add_item_actions_group.addAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse"));
QAction *add_polyline = m_add_item_actions_group.addAction(QET::Icons::PartPolygon, tr("Ajouter une polyligne"));
QAction *add_terminal_strip = m_add_item_actions_group.addAction(QET::Icons::TerminalStrip, tr("Ajouter un plan de bornes"));
add_text ->setStatusTip(tr("Ajoute un champ de texte sur le folio actuel"));
add_image ->setStatusTip(tr("Ajoute une image sur le folio actuel"));
@ -671,17 +672,22 @@ void QETDiagramEditor::setUpActions()
add_rectangle->setStatusTip(tr("Ajoute un rectangle sur le folio actuel"));
add_ellipse ->setStatusTip(tr("Ajoute une ellipse sur le folio actuel"));
add_polyline ->setStatusTip(tr("Ajoute une polyligne sur le folio actuel"));
add_terminal_strip->setStatusTip(tr("Ajoute un plan de bornier sur le folio actuel"));
add_text ->setData("text");
add_image ->setData("image");
add_line ->setData("line");
add_rectangle->setData("rectangle");
add_ellipse ->setData("ellipse");
add_polyline ->setData("polyline");
add_text ->setData(QStringLiteral("text"));
add_image ->setData(QStringLiteral("image"));
add_line ->setData(QStringLiteral("line"));
add_rectangle->setData(QStringLiteral("rectangle"));
add_ellipse ->setData(QStringLiteral("ellipse"));
add_polyline ->setData(QStringLiteral("polyline"));
add_terminal_strip->setData(QStringLiteral("terminal_strip"));
add_text->setCheckable(true);
add_line->setCheckable(true);
add_rectangle->setCheckable(true);
add_ellipse->setCheckable(true);
add_polyline->setCheckable(true);
for(QAction *action : m_add_item_actions_group.actions()) {
action->setCheckable(true);
}
connect(&m_add_item_actions_group, &QActionGroup::triggered, this, &QETDiagramEditor::addItemGroupTriggered);
//Depth action
@ -1423,14 +1429,23 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action)
if (deai->isNull())
{
delete deai;
action->setChecked(false);
return;
}
else
diagram_event = deai;
}
else if (value == "text")
{
diagram_event = new DiagramEventAddText(d);
}
else if (value == QLatin1String("terminal_strip"))
{
const auto diagram_view{currentDiagramView()};
if (diagram_view)
{
AddTerminalStripItemDialog::openDialog(diagram_view->diagram(), this);
}
}
if (diagram_event)
{

View File

@ -253,13 +253,13 @@ void CrossRefItem::autoPos()
{
//We calcul the position according to the snapTo of the xrefproperties
if (m_properties.snapTo() == XRefProperties::Bottom)
centerToBottomDiagram(this,
QGIUtility::centerToBottomDiagram(this,
m_element,
m_properties.offset() <= 40
? 5
: m_properties.offset());
else
centerToParentBottom(this);
QGIUtility::centerToParentBottom(this);
}
/**

View File

@ -861,7 +861,7 @@ void ElementTextItemGroup::autoPos()
}
}
qreal r = rotation();
centerToBottomDiagram(this, m_parent_element, offset);
QGIUtility::centerToBottomDiagram(this, m_parent_element, offset);
//centerToBottomDiagram change the rotation of this group if needed,
//but setRotation is not a virtual function of QGraphicsItem, and the function centerToBottomDiagram
//work with a QGraphicsItem. So we emit the signal if rotation changed

View File

@ -64,6 +64,10 @@ void QetGraphicsItem::setPos(qreal x, qreal y) {
setPos(QPointF(x, y));
}
bool QetGraphicsItem::isHovered() const {
return m_hovered;
}
/**
@brief QetGraphicsItem::state
@return the current state of this item
@ -155,3 +159,15 @@ void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
event->accept();
}
}
void QetGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered = true;
QGraphicsObject::hoverEnterEvent(event);
}
void QetGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered = false;
QGraphicsObject::hoverLeaveEvent(event);
}

View File

@ -42,6 +42,8 @@ class QetGraphicsItem : public QGraphicsObject
{return is_movable_;}
virtual void setMovable (bool movable) { is_movable_ = movable;}
bool isHovered() const;
virtual void editProperty () {}
virtual QString name ()const
{return QString("");}
@ -54,6 +56,8 @@ class QetGraphicsItem : public QGraphicsObject
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
protected:
bool is_movable_;
@ -62,6 +66,9 @@ class QetGraphicsItem : public QGraphicsObject
QPointF m_mouse_to_origin_movement;
QET::GraphicsItemState m_state = QET:: GIOK;
private:
bool m_hovered{false};
};
#endif // QETGRAPHICSITEM_H

View File

@ -23,6 +23,9 @@
#include <QDebug>
#include <QGraphicsItem>
namespace QGIUtility
{
/**
@brief centerToParentBottom
Center the item at the bottom of is parent.
@ -51,10 +54,10 @@ bool centerToParentBottom(QGraphicsItem *item) {
@param offset
@return true if element is centered else false (element_to_follow have not diagram)
*/
#include "elementtextitemgroup.h"
#include "crossrefitem.h"
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset) {
if (! element_to_follow -> diagram()) {
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset)
{
if (! element_to_follow -> diagram())
{
qDebug() << "qgraphicsitemutility centerAtBottomDiagram : Element_to_follow have not diagram";
return false;
}
@ -81,8 +84,25 @@ bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_f
rot += parent->rotation();
parent = parent->parentItem();
}
if(rot != 0)
if(rot != 0) {
item_to_center->setRotation(item_to_center->rotation() - rot);
}
return true;
}
void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter)
{
painter->save();
QPen t;
t.setColor(Qt::gray);
t.setStyle(Qt::DashDotLine);
t.setCosmetic(true);
painter->setPen(t);
painter->drawRoundedRect(item->boundingRect(),10,10);
painter->restore();
}
}

View File

@ -17,11 +17,18 @@
*/
#ifndef QGRAPHICSITEMUTILITY_H
#define QGRAPHICSITEMUTILITY_H
#include <QtGlobal>
class QGraphicsItem;
class Element;
class QPainter;
bool centerToParentBottom (QGraphicsItem *item);
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 );
namespace QGIUtility
{
bool centerToParentBottom (QGraphicsItem *item);
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 );
void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter);
}
#endif // QGRAPHICSITEMUTILITY_H

View File

@ -225,7 +225,33 @@ QETProject::ProjectState QETProject::openFile(QFile *file)
if(opened_here) {
file->close();
}
return ProjectState::Ok;
return ProjectState::Ok;
}
/**
* @brief QETProject::refresh
* Refresh everything in the project.
* This is notably use when open a project from file.
*/
void QETProject::refresh()
{
DialogWaiting *dlgWaiting { nullptr };
if(DialogWaiting::hasInstance())
{
dlgWaiting = DialogWaiting::instance();
dlgWaiting->setModal(true);
dlgWaiting->show();
}
for(const auto &diagram : diagrams())
{
if(dlgWaiting)
{
dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
dlgWaiting->setDetail(diagram->title());
}
diagram->refreshContents();
}
}
/**
@ -1388,6 +1414,9 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
//Load the terminal strip
readTerminalStripXml(xml_project);
//Now that all are loaded we refresh content of the project.
refresh();
m_data_base.blockSignals(false);
m_data_base.updateDB();
@ -1461,18 +1490,6 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
"Mise en place des références croisées"
"</p>"));
}
m_data_base.updateDB(); //All diagrams and items are created we need to update the database
for(const auto &diagram : diagrams())
{
if(dlgWaiting)
{
dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
dlgWaiting->setDetail(diagram->title());
}
diagram->refreshContents();
}
}
/**

View File

@ -234,6 +234,7 @@ class QETProject : public QObject
void writeBackup();
void init();
ProjectState openFile(QFile *file);
void refresh();
// attributes
private:

View File

@ -21,6 +21,7 @@
#include <QDir>
#include <QFont>
#include <QGraphicsItem>
#include <QPen>
/**
@ -917,7 +918,39 @@ bool validXmlProperty(const QDomElement& e) {
if (!e.hasAttribute("value"))
return false;
return true;
return true;
}
/**
* @brief qGraphicsItemPosToXml
* Save the pos of a QGraphicsItem into an xml element.
* The tag name of the xml element is pos and there is 3 attributes:
* x, y, z.
* @param item
* @param document
* @return
*/
QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document)
{
auto dom_pos = document.createElement(QStringLiteral("pos"));
dom_pos.setAttribute(QStringLiteral("x"), QString::number(item->pos().x()));
dom_pos.setAttribute(QStringLiteral("y"), QString::number(item->pos().y()));
dom_pos.setAttribute(QStringLiteral("z"), QString::number(item->zValue()));
return dom_pos;
}
bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt)
{
if (xml_elmt.tagName() == QLatin1String("pos"))
{
item->setX(xml_elmt.attribute(QStringLiteral("x"), QStringLiteral("0")).toDouble());
item->setY(xml_elmt.attribute(QStringLiteral("y"), QStringLiteral("0")).toDouble());
item->setZValue(xml_elmt.attribute(QStringLiteral("z"), QStringLiteral("0")).toInt());
return true;
}
return false;
}
}

View File

@ -25,6 +25,7 @@ class QDomDocument;
class QDir;
class QFile;
class QAbstractItemModel;
class QGraphicsItem;
/**
*This namespace contain some function to use xml with QET.
@ -89,6 +90,10 @@ namespace QETXML
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
const QString &tag_name);
QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document);
bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt);
QString boolToString(bool value);
bool boolFromString(const QString &value,
bool default_value = true,

View File

@ -0,0 +1,175 @@
/*
Copyright 2006-2022 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 <QGraphicsItemGroup>
#include <QPropertyAnimation>
#include "movegraphicsitemcommand.h"
#include "../qetgraphicsitem/conductor.h"
#include "../qetgraphicsitem/elementtextitemgroup.h"
#include "../diagram.h"
/**
* @brief MoveGraphicsItemCommand::MoveGraphicsItemCommand
* @param diagram : Diagram where the movement occur
* @param content : content aka QGraphicsItem to move
* @param movement : the movement to apply
* @param parent : parent undo command
*/
MoveGraphicsItemCommand::MoveGraphicsItemCommand(Diagram *diagram,
const DiagramContent &content,
const QPointF &movement,
QUndoCommand *parent) :
QUndoCommand{parent},
m_diagram{diagram},
m_content{content},
m_movement{movement}
{
const auto moved_content_sentence = m_content.sentence(DiagramContent::Elements
| DiagramContent::TextFields
| DiagramContent::ConductorsToUpdate
| DiagramContent::ConductorsToMove
| DiagramContent::Images
| DiagramContent::Shapes
| DiagramContent::ElementTextFields
| DiagramContent::TerminalStrip);
setText(QString(QObject::tr("déplacer %1",
"undo caption - %1 is a sentence listing the moved content").arg(moved_content_sentence)));
}
/**
* @brief MoveGraphicsItemCommand::undo
* Reimplemented from QUndoCommand::undo()
*/
void MoveGraphicsItemCommand::undo()
{
if (m_diagram)
{
m_diagram->showMe();
m_anim_group.setDirection(QAnimationGroup::Forward);
m_anim_group.start();
}
QUndoCommand::undo();
}
/**
* @brief MoveGraphicsItemCommand::redo
* Reimplemented from QUndoCommand::redo()
*/
void MoveGraphicsItemCommand::redo()
{
if (m_diagram)
{
m_diagram->showMe();
if (m_first_redo)
{
m_first_redo = false;
move(-m_movement);
}
else
{
m_anim_group.setDirection(QAnimationGroup::Backward);
m_anim_group.start();
}
}
QUndoCommand::redo();
}
/**
* @brief MoveGraphicsItemCommand::move
* Apply @a movement to items of m_content
* @param movement
*/
void MoveGraphicsItemCommand::move(const QPointF &movement)
{
for (auto &&qgi : m_content.items(DiagramContent::Elements
| DiagramContent::TextFields
| DiagramContent::Images
| DiagramContent::Shapes
| DiagramContent::TextGroup
| DiagramContent::ElementTextFields
| DiagramContent::Tables
| DiagramContent::TerminalStrip))
{
//If item have a parent and the parent is in m_content,
//we don't apply movement because this item will be moved by his parent
if (const auto parent_ = qgi->parentItem()) {
if (m_content.items().contains(parent_)) {
continue;
}
}
if (const auto graphics_object = qgi->toGraphicsObject()) {
setupAnimation(graphics_object,
"pos",
graphics_object->pos(),
graphics_object->pos() + movement);
}
else if (qgi->type() == QGraphicsItemGroup::Type)
{
//ElementTextItemGroup is a QObject not a QGraphicsObject
if (ElementTextItemGroup *etig = dynamic_cast<ElementTextItemGroup *>(qgi)) {
setupAnimation(etig,
"pos",
etig->pos(),
etig->pos() + movement);
}
}
else
{
qgi->setPos(qgi->pos() + movement);
}
}
//Move some conductors
for (const auto &conductor : qAsConst(m_content.m_conductors_to_move)) {
setupAnimation(conductor,
"pos",
conductor->pos(),
conductor->pos() + movement);
}
//Recalcul the path of other conductors
for (const auto &conductor : qAsConst(m_content.m_conductors_to_update)) {
setupAnimation(conductor, "animPath", 1, 1);
}
}
/**
* @brief MoveGraphicsItemCommand::setupAnimation
* Create the animation used for the movement.
* @see QPropertyAnimation.
* @param target
* @param property_name
* @param start
* @param end
*/
void MoveGraphicsItemCommand::setupAnimation(QObject *target,
const QByteArray &property_name,
const QVariant &start,
const QVariant &end)
{
QPropertyAnimation *animation{new QPropertyAnimation(target, property_name)};
animation->setDuration(300);
animation->setStartValue(start);
animation->setEndValue(end);
animation->setEasingCurve(QEasingCurve::OutQuad);
m_anim_group.addAnimation(animation);
}

View File

@ -0,0 +1,65 @@
/*
Copyright 2006-2022 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 MOVEGRAPHICSITEMCOMMAND_H
#define MOVEGRAPHICSITEMCOMMAND_H
#include <QUndoCommand>
#include <QParallelAnimationGroup>
#include <QPointer>
#include "../diagramcontent.h"
class Diagram;
/**
* @brief The MoveGraphicsItemCommand class
* An undo command used for move item(s) in a diagram
*/
class MoveGraphicsItemCommand : public QUndoCommand
{
public:
MoveGraphicsItemCommand(Diagram *diagram,
const DiagramContent &content,
const QPointF &movement,
QUndoCommand *parent = nullptr);
~MoveGraphicsItemCommand() {}
private:
MoveGraphicsItemCommand(const MoveGraphicsItemCommand &);
public:
void undo() override;
void redo() override;
private:
void move(const QPointF &movement);
void setupAnimation(QObject *target,
const QByteArray &property_name,
const QVariant &start,
const QVariant &end);
private:
QPointer<Diagram> m_diagram;
DiagramContent m_content;
const QPointF m_movement;
QParallelAnimationGroup m_anim_group;
bool m_first_redo{true};
};
#endif // MOVEGRAPHICSITEMCOMMAND_H

View File

@ -0,0 +1,131 @@
/*
Copyright 2006-2022 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 "terminalstripitemxml.h"
#include "../diagram.h"
#include "../qetproject.h"
#include "../qetxml.h"
#include "../TerminalStrip/GraphicsItem/terminalstripitem.h"
#include "../TerminalStrip/terminalstrip.h"
#include <QUuid>
const QString STRIP_ITEM_TAG_NAME { QStringLiteral("terminal_strip_item") };
const QString STRIP_ITEMS_TAG_NAME { QStringLiteral("terminal_strip_items") };
/**
* @brief TerminalStripItemXml::toXml
* Save the vector of @a items as child of an xml element with tag "terminal_strip_tems"
* @param items : items to save in xml
* @param document : parent document used to create the QDomElement returned by this function.
* @return QDomElement where are saved @a items.
*/
QDomElement TerminalStripItemXml::toXml(const QVector<TerminalStripItem *> &items, QDomDocument &document)
{
auto dom_element = document.createElement(STRIP_ITEMS_TAG_NAME);
for (const auto &item : items) {
dom_element.appendChild(toXml(item, document));
}
return dom_element;
}
/**
* @brief TerminalStripItemXml::fromXml
* Load items stored in @a xml_elmt into @a diagram
* @a xml_elmt must have a child element with tag name "terminal_strip_tems"
* @param diagram
* @param xml_elmt
* @return a vector of added terminal strip item
*/
QVector<TerminalStripItem *> TerminalStripItemXml::fromXml(Diagram *diagram, const QDomElement &xml_elmt)
{
QVector<TerminalStripItem *> returned_vector;
for (const auto &dom_elmt : QETXML::subChild(xml_elmt,
STRIP_ITEMS_TAG_NAME,
STRIP_ITEM_TAG_NAME))
{
auto strip_item = new TerminalStripItem();
diagram->addItem(strip_item);
returned_vector << strip_item;
TerminalStripItemXml::fromXml(strip_item, diagram->project(), dom_elmt);
}
return returned_vector;
}
/**
* @brief TerminalStripItemXml::toXml
* Save @a item to an xml element with tag "terminal_strip_item"
* @param item : item to save in xml
* @param document : parent document used to create the QDomElement returned by this function.
* @return QDomElement where are saved @a item.
*/
QDomElement TerminalStripItemXml::toXml(TerminalStripItem *item, QDomDocument &document)
{
//Terminal strip item dom element
auto dom_element = document.createElement(STRIP_ITEM_TAG_NAME);
auto dom_strip = document.createElement(QStringLiteral("terminal_strip"));
dom_strip.setAttribute(QStringLiteral("uuid"), item->terminalStrip()->uuid().toString());
dom_element.appendChild(dom_strip);
dom_element.appendChild(QETXML::qGraphicsItemPosToXml(item, document));
return dom_element;
}
/**
* @brief TerminalStripItemXml::fromXml
* Restor the state of a terminal strip item from @a xml_elmt.
* The @a xml_elmt tag name must be "terminal_strip_item"
* @param item
* @param project
* @param xml_elmt
* @return
*/
bool TerminalStripItemXml::fromXml(TerminalStripItem *item, QETProject *project, const QDomElement &xml_elmt)
{
if (xml_elmt.tagName() == STRIP_ITEM_TAG_NAME)
{
bool a{false};
const auto ts = xml_elmt.firstChildElement(QStringLiteral("terminal_strip"));
if (!ts.isNull())
{
const QUuid uuid_(ts.attribute(QStringLiteral("uuid")));
item->m_pending_strip_uuid = uuid_;
for (const auto &ts : project->terminalStrip()) {
if (ts->uuid() == uuid_) {
item->setTerminalStrip(ts);
a = true;
break;
}
}
}
bool b{QETXML::qGraphicsItemPosFromXml(item,
xml_elmt.firstChildElement(QStringLiteral("pos")))};
return (a && b);
}
return false;
}

View File

@ -0,0 +1,37 @@
/*
Copyright 2006-2022 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 TERMINALSTRIPITEMXML_H
#define TERMINALSTRIPITEMXML_H
#include <QDomElement>
class TerminalStripItem;
class QETProject;
class Diagram;
class TerminalStripItemXml
{
public:
static QDomElement toXml(const QVector<TerminalStripItem *> &items, QDomDocument &document);
static QVector<TerminalStripItem *> fromXml(Diagram *diagram, const QDomElement &xml_elmt);
static QDomElement toXml(TerminalStripItem *item, QDomDocument &document);
static bool fromXml(TerminalStripItem *item, QETProject *project, const QDomElement &xml_elmt);
};
#endif // TERMINALSTRIPITEMXML_H