mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
Merge branch 'master' of ssh://git.tuxfamily.org/gitroot/qet/qet
This commit is contained in:
@@ -215,11 +215,13 @@ void ProjectDBModel::setQuery(const QString &query)
|
||||
@brief ProjectDBModel::queryString
|
||||
@return the current query used by this model
|
||||
*/
|
||||
QString ProjectDBModel::queryString() const {
|
||||
QString ProjectDBModel::queryString() const
|
||||
{
|
||||
return m_query;
|
||||
}
|
||||
|
||||
QETProject *ProjectDBModel::project() const {
|
||||
QETProject *ProjectDBModel::project() const
|
||||
{
|
||||
return m_project.data();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static int no_model_width = 40;
|
||||
@param parent
|
||||
*/
|
||||
QetGraphicsHeaderItem::QetGraphicsHeaderItem(QGraphicsItem *parent) :
|
||||
QGraphicsObject(parent)
|
||||
QGraphicsObject(parent)
|
||||
{}
|
||||
|
||||
/**
|
||||
@@ -44,17 +44,23 @@ QetGraphicsHeaderItem::QetGraphicsHeaderItem(QGraphicsItem *parent) :
|
||||
void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged,
|
||||
this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
}
|
||||
|
||||
m_model = model;
|
||||
m_model = model;
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged,
|
||||
this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this,
|
||||
&QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
@@ -69,7 +75,8 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
@brief QetGraphicsHeaderItem::model
|
||||
@return the model that this item is presenting
|
||||
*/
|
||||
QAbstractItemModel *QetGraphicsHeaderItem::model() const {
|
||||
QAbstractItemModel *QetGraphicsHeaderItem::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
@@ -78,7 +85,8 @@ QAbstractItemModel *QetGraphicsHeaderItem::model() const {
|
||||
Reimplemented from QGraphicsObject::boundingRect() const;
|
||||
@return
|
||||
*/
|
||||
QRectF QetGraphicsHeaderItem::boundingRect() const {
|
||||
QRectF QetGraphicsHeaderItem::boundingRect() const
|
||||
{
|
||||
return m_bounding_rect;
|
||||
}
|
||||
|
||||
@@ -89,7 +97,10 @@ QRectF QetGraphicsHeaderItem::boundingRect() const {
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void QetGraphicsHeaderItem::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@@ -113,9 +124,13 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
painter->setFont(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto size : m_current_sections_width)
|
||||
{
|
||||
@@ -125,15 +140,33 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
offset += size;
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
//Write text of each cell
|
||||
auto margins_ = QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
QPointF top_left(margins_.left(), margins_.top());
|
||||
for (auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(), m_section_height - margins_.top() - margins_.bottom());
|
||||
painter->drawText(QRectF(top_left, size),
|
||||
m_model->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt(),
|
||||
m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
QSize size(
|
||||
m_current_sections_width.at(i)
|
||||
- margins_.left()
|
||||
- margins_.right(),
|
||||
|
||||
m_section_height
|
||||
- margins_.top()
|
||||
- margins_.bottom());
|
||||
painter->drawText(
|
||||
QRectF(top_left, size),
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::TextAlignmentRole).toInt(),
|
||||
m_model->headerData(
|
||||
i,
|
||||
Qt::Horizontal,
|
||||
Qt::DisplayRole).toString());
|
||||
|
||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||
}
|
||||
@@ -141,54 +174,71 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->restore();
|
||||
}
|
||||
/**
|
||||
@brief QetGraphicsHeaderItem::toDXF
|
||||
Draw this table to the dxf document
|
||||
@param filepath file path of the the dxf document
|
||||
@return true if draw success
|
||||
@brief QetGraphicsHeaderItem::toDXF
|
||||
Draw this table to the dxf document
|
||||
@param filepath file path of the the dxf document
|
||||
@return true if draw success
|
||||
*/
|
||||
bool QetGraphicsHeaderItem::toDXF(const QString &filepath)
|
||||
{
|
||||
QRectF rect = m_current_rect;
|
||||
QPolygonF poly(rect);
|
||||
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
||||
QRectF rect = m_current_rect;
|
||||
QPolygonF poly(rect);
|
||||
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
||||
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto size : m_current_sections_width)
|
||||
{
|
||||
QPointF p1(offset+size, m_current_rect.top());
|
||||
QPointF p2(offset+size, m_current_rect.bottom());
|
||||
Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0);
|
||||
offset += size;
|
||||
}
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto size : m_current_sections_width)
|
||||
{
|
||||
QPointF p1(offset+size, m_current_rect.top());
|
||||
QPointF p2(offset+size, m_current_rect.bottom());
|
||||
Createdxf::drawLine(
|
||||
filepath,
|
||||
QLineF(
|
||||
mapToScene(p1),
|
||||
mapToScene(p2)),
|
||||
0);
|
||||
offset += size;
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
QPointF top_left(margins_.left(), margins_.top());
|
||||
for (auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(), m_section_height - margins_.top() - margins_.bottom());
|
||||
//Write text of each cell
|
||||
auto margins_ = QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
QPointF top_left(margins_.left(), margins_.top());
|
||||
for (auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(),
|
||||
m_section_height - margins_.top() - margins_.bottom());
|
||||
|
||||
QPointF qm = mapToScene(top_left);
|
||||
qreal h = size.height();// * Createdxf::yScale;
|
||||
qreal x = qm.x() * Createdxf::xScale;
|
||||
qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale);
|
||||
qreal h1 = h * 0.5 * Createdxf::yScale;
|
||||
QPointF qm = mapToScene(top_left);
|
||||
qreal h = size.height();// * Createdxf::yScale;
|
||||
qreal x = qm.x() * Createdxf::xScale;
|
||||
qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale);
|
||||
qreal h1 = h * 0.5 * Createdxf::yScale;
|
||||
|
||||
int valign = 2;
|
||||
int valign = 2;
|
||||
|
||||
Createdxf::drawTextAligned(filepath,m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(),x,y,h1,0,0,0,valign,x,0,0);
|
||||
Createdxf::drawTextAligned(
|
||||
filepath,
|
||||
m_model->headerData(
|
||||
i,
|
||||
Qt::Horizontal,
|
||||
Qt::DisplayRole).toString(),
|
||||
x,y,h1,0,0,0,valign,x,0,0);
|
||||
|
||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||
}
|
||||
return true;
|
||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsHeaderItem::rect
|
||||
@return the current rect of the item aka the size of rectangle painted.
|
||||
*/
|
||||
QRect QetGraphicsHeaderItem::rect() const {
|
||||
QRect QetGraphicsHeaderItem::rect() const
|
||||
{
|
||||
return m_current_rect;
|
||||
}
|
||||
|
||||
@@ -223,7 +273,11 @@ void QetGraphicsHeaderItem::resizeSection(int logicalIndex, int size)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_current_sections_width.replace(logicalIndex, size);
|
||||
m_current_rect.setWidth(std::accumulate(m_current_sections_width.begin(), m_current_sections_width.end(), 0));
|
||||
m_current_rect.setWidth(
|
||||
std::accumulate(
|
||||
m_current_sections_width.begin(),
|
||||
m_current_sections_width.end(),
|
||||
0));
|
||||
setUpBoundingRect();
|
||||
update();
|
||||
emit sectionResized(logicalIndex, size);
|
||||
@@ -254,7 +308,14 @@ QDomElement QetGraphicsHeaderItem::toXml(QDomDocument &document) const
|
||||
{
|
||||
auto dom_element = document.createElement(xmlTagName());
|
||||
if (m_model) {
|
||||
dom_element.appendChild(QETXML::marginsToXml(document, QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString())));
|
||||
dom_element.appendChild(
|
||||
QETXML::marginsToXml(
|
||||
document,
|
||||
QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString())));
|
||||
}
|
||||
|
||||
return dom_element;
|
||||
@@ -271,8 +332,16 @@ void QetGraphicsHeaderItem::fromXml(const QDomElement &element)
|
||||
return;
|
||||
}
|
||||
|
||||
auto margins_ = QETUtils::marginsToString(QETXML::marginsFromXml(element.firstChildElement("margins")));
|
||||
m_model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(QETXML::marginsFromXml(element.firstChildElement("margins"))), Qt::UserRole+1);
|
||||
auto margins_ = QETUtils::marginsToString(
|
||||
QETXML::marginsFromXml(
|
||||
element.firstChildElement("margins")));
|
||||
m_model->setHeaderData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
QETUtils::marginsToString(
|
||||
QETXML::marginsFromXml(
|
||||
element.firstChildElement("margins"))),
|
||||
Qt::UserRole+1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,10 +360,19 @@ void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
|
||||
return;
|
||||
}
|
||||
|
||||
QFontMetrics metrics(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
QFontMetrics metrics(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::FontRole).value<QFont>());
|
||||
auto margins_ = QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
//Set the height of row;
|
||||
m_minimum_section_height = metrics.boundingRect("HEIGHT TEST").height() + margins_.top() + margins_.bottom();
|
||||
m_minimum_section_height = metrics.boundingRect("HEIGHT TEST").height()
|
||||
+ margins_.top() + margins_.bottom();
|
||||
|
||||
m_sections_minimum_width.clear();
|
||||
m_sections_minimum_width.resize(m_model->columnCount());
|
||||
@@ -302,17 +380,25 @@ void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
|
||||
for (auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
auto str = m_model->headerData(i, Qt::Horizontal).toString();
|
||||
m_sections_minimum_width.replace(i, metrics.boundingRect(str).width() + margins_.left() + margins_.right());
|
||||
m_sections_minimum_width.replace(
|
||||
i,
|
||||
metrics.boundingRect(str).width()
|
||||
+ margins_.left()
|
||||
+ margins_.right());
|
||||
}
|
||||
|
||||
m_minimum_width = std::accumulate(m_sections_minimum_width.begin(), m_sections_minimum_width.end(), 0);
|
||||
m_minimum_width = std::accumulate(
|
||||
m_sections_minimum_width.begin(),
|
||||
m_sections_minimum_width.end(),
|
||||
0);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsHeaderItem::setUpBoundingRect
|
||||
Setup the bounding rect of the item
|
||||
*/
|
||||
void QetGraphicsHeaderItem::setUpBoundingRect() {
|
||||
void QetGraphicsHeaderItem::setUpBoundingRect()
|
||||
{
|
||||
m_bounding_rect = m_current_rect.adjusted(-10, -10, 10, 10);
|
||||
}
|
||||
|
||||
@@ -323,7 +409,8 @@ void QetGraphicsHeaderItem::setUpBoundingRect() {
|
||||
@param first
|
||||
@param last
|
||||
*/
|
||||
void QetGraphicsHeaderItem::headerDataChanged(Qt::Orientations orientation, int first, int last)
|
||||
void QetGraphicsHeaderItem::headerDataChanged(
|
||||
Qt::Orientations orientation, int first, int last)
|
||||
{
|
||||
Q_UNUSED(orientation)
|
||||
Q_UNUSED(first)
|
||||
|
||||
@@ -51,17 +51,22 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
virtual void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
QRect rect() const;
|
||||
void resizeSection(int logicalIndex, int size);
|
||||
int sectionSize(int logical_index) const;
|
||||
QVector<int> minimumSectionWidth() const {return m_sections_minimum_width;}
|
||||
int minimumWidth() const {return m_minimum_width;}
|
||||
QVector<int> minimumSectionWidth() const
|
||||
{return m_sections_minimum_width;}
|
||||
int minimumWidth() const
|
||||
{return m_minimum_width;}
|
||||
|
||||
QDomElement toXml (QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
static QString xmlTagName() {return QString("graphics_header");}
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
|
||||
signals:
|
||||
void sectionResized(int logicalIndex, int size);
|
||||
@@ -70,19 +75,25 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
private:
|
||||
void setUpMinimumSectionsSize();
|
||||
void setUpBoundingRect();
|
||||
void headerDataChanged(Qt::Orientations orientation, int first, int last);
|
||||
void headerDataChanged(
|
||||
Qt::Orientations orientation,
|
||||
int first,
|
||||
int last);
|
||||
void adjustSize();
|
||||
void modelReseted();
|
||||
|
||||
private:
|
||||
QRect m_current_rect;
|
||||
QRectF m_bounding_rect;
|
||||
QAbstractItemModel *m_model = nullptr;
|
||||
QVector<int> m_sections_minimum_width,
|
||||
m_current_sections_width;
|
||||
int m_section_height=1,
|
||||
m_minimum_section_height=1;
|
||||
int m_minimum_width=1;
|
||||
QRect m_current_rect;
|
||||
|
||||
QVector<int>
|
||||
m_sections_minimum_width,
|
||||
m_current_sections_width;
|
||||
|
||||
int
|
||||
m_section_height=1,
|
||||
m_minimum_section_height=1,
|
||||
m_minimum_width=1;
|
||||
};
|
||||
|
||||
#endif // QETGRAPHICSHEADERITEM_H
|
||||
|
||||
@@ -40,24 +40,29 @@ static int no_model_width = 40;
|
||||
@param table : table to adjust
|
||||
@param margins : margins between table and folio.
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustTableToFolio(QetGraphicsTableItem *table,
|
||||
QMargins margins)
|
||||
void QetGraphicsTableItem::adjustTableToFolio(
|
||||
QetGraphicsTableItem *table,
|
||||
QMargins margins)
|
||||
{
|
||||
if (!table->diagram()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect();
|
||||
table->setPos(drawable_rect.topLeft().x() + margins.left(), drawable_rect.topLeft().y() + margins.top() + table->headerItem()->rect().height());
|
||||
table->setPos(
|
||||
drawable_rect.topLeft().x() + margins.left(),
|
||||
drawable_rect.topLeft().y()
|
||||
+ margins.top()
|
||||
+ table->headerItem()->rect().height());
|
||||
|
||||
auto size_ = table->size();
|
||||
size_.setWidth(int(drawable_rect.width() - (margins.left() + margins.right())));
|
||||
//Size must be a multiple of 10, because the table adjust itself by step of 10.
|
||||
//Size must be a multiple of 10, because the table adjust itself by step of 10.
|
||||
while (size_.width()%10) {
|
||||
--size_.rwidth(); }
|
||||
table->setSize(size_);
|
||||
|
||||
//Calcul the maximum row to display to fit the nomenclature into diagram
|
||||
//Calcul the maximum row to display to fit the nomenclature into diagram
|
||||
auto available_height = drawable_rect.height() - table->pos().y();
|
||||
auto min_row_height = table->minimumRowHeigth();
|
||||
table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok
|
||||
@@ -130,16 +135,21 @@ QetGraphicsTableItem::QetGraphicsTableItem(QGraphicsItem *parent) :
|
||||
setAcceptHoverEvents(true);
|
||||
setUpHandler();
|
||||
|
||||
//A litle bounding rect before model is set,
|
||||
//then user can already grab this item, even if model is not already set
|
||||
//A litle bounding rect before model is set,
|
||||
//then user can already grab this item, even if model is not already set
|
||||
m_bounding_rect.setRect(m_br_margin/-2, m_br_margin/-2, 50, 50);
|
||||
|
||||
connect(this, &QetGraphicsTableItem::xChanged, this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::yChanged, this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::xChanged,
|
||||
this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::yChanged,
|
||||
this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
|
||||
m_header_item = new QetGraphicsHeaderItem(this);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::heightResized, this, [this]() {
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized,
|
||||
this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::heightResized,
|
||||
this, [this]()
|
||||
{
|
||||
m_header_item->setPos(0, 0-m_header_item->rect().height());
|
||||
});
|
||||
//Init the size of table without a model
|
||||
@@ -160,8 +170,10 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model)
|
||||
{
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged,
|
||||
this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
m_model = model;
|
||||
m_header_item->setModel(model);
|
||||
@@ -172,8 +184,10 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
m_header_item->setPos(0, -m_header_item->rect().height());
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::dataChanged,
|
||||
this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
|
||||
if (m_next_table) {
|
||||
@@ -185,7 +199,8 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
@brief QetGraphicsTableItem::model
|
||||
@return The model that this item is presenting
|
||||
*/
|
||||
QAbstractItemModel *QetGraphicsTableItem::model() const {
|
||||
QAbstractItemModel *QetGraphicsTableItem::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
@@ -194,7 +209,8 @@ QAbstractItemModel *QetGraphicsTableItem::model() const {
|
||||
Reimplemented from QGraphicsObject
|
||||
@return
|
||||
*/
|
||||
QRectF QetGraphicsTableItem::boundingRect() const {
|
||||
QRectF QetGraphicsTableItem::boundingRect() const
|
||||
{
|
||||
return m_bounding_rect;
|
||||
}
|
||||
|
||||
@@ -205,7 +221,10 @@ QRectF QetGraphicsTableItem::boundingRect() const {
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void QetGraphicsTableItem::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@@ -236,7 +255,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
}
|
||||
painter->setFont(m_model->data(m_model->index(0,0), Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto i=0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
@@ -246,7 +265,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
|
||||
//Calcule the number of rows to display.
|
||||
//Calcule the number of rows to display.
|
||||
auto row_count = m_model->rowCount();
|
||||
|
||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||
@@ -255,7 +274,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
//Draw horizontal lines
|
||||
//Draw horizontal lines
|
||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||
for(auto i= 1 ; i-1<row_count ; ++i)
|
||||
{
|
||||
@@ -264,7 +283,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
painter->drawLine(p1, p2);
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
//Write text of each cell
|
||||
for (auto i=0 ; i<row_count ; ++i)
|
||||
{
|
||||
auto margin_ = QETUtils::marginsFromString(m_model->index(0,0).data(Qt::UserRole+1).toString());
|
||||
@@ -272,16 +291,23 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
|
||||
for(auto j= 0 ; j<m_model->columnCount() ; ++j)
|
||||
{
|
||||
//In first iteration the top left X is margin left, in all other iteration the top left X is stored in m_column_size
|
||||
//In first iteration the top left X is margin left,
|
||||
// in all other iteration the top left X is stored in m_column_size
|
||||
if (j>0) {
|
||||
top_left.setX(top_left.x() + m_header_item->sectionSize(j-1));
|
||||
}
|
||||
QSize size(m_header_item->sectionSize(j) - margin_.left() - margin_.right(),
|
||||
static_cast<int>(cell_height) - margin_.top() - margin_.bottom());
|
||||
auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i;
|
||||
painter->drawText(QRectF(top_left, size),
|
||||
m_model->data(m_model->index(0,0), Qt::TextAlignmentRole).toInt() | Qt::AlignVCenter,
|
||||
m_model->index(index_row, j).data().toString());
|
||||
painter->drawText(
|
||||
QRectF(top_left, size),
|
||||
m_model->data(
|
||||
m_model->index(0,0),
|
||||
Qt::TextAlignmentRole
|
||||
).toInt()
|
||||
| Qt::AlignVCenter,
|
||||
m_model->index(index_row, j)
|
||||
.data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +322,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
void QetGraphicsTableItem::setSize(const QSize &size)
|
||||
{
|
||||
auto new_size = size;
|
||||
if (new_size.width() < minimumSize().width()) {
|
||||
if (new_size.width() < minimumSize().width()) {
|
||||
new_size.setWidth(minimumSize().width());
|
||||
}
|
||||
if (new_size.height() < minimumSize().height()) {
|
||||
@@ -325,7 +351,8 @@ QSize QetGraphicsTableItem::size() const
|
||||
/**
|
||||
@brief QetGraphicsTableItem::minimumSize
|
||||
@return the minimum size the table can be
|
||||
The returned size take care of the table's minimum width, but also the header item's minimum width
|
||||
The returned size take care of the table's minimum width,
|
||||
but also the header item's minimum width
|
||||
*/
|
||||
QSize QetGraphicsTableItem::minimumSize() const
|
||||
{
|
||||
@@ -342,9 +369,14 @@ QSize QetGraphicsTableItem::minimumSize() const
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
|
||||
//m_minimum_column_width already take in count the minimum size of header
|
||||
QSize size_(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*row_count);
|
||||
//make sure that the width is a multiple of 10
|
||||
//m_minimum_column_width already take in count the minimum size of header
|
||||
QSize size_(
|
||||
std::accumulate(
|
||||
m_minimum_column_width.begin(),
|
||||
m_minimum_column_width.end(),
|
||||
0),
|
||||
m_minimum_row_height*row_count);
|
||||
//make sure that the width is a multiple of 10
|
||||
while (size_.width()%10) {
|
||||
size_.rwidth()++;
|
||||
}
|
||||
@@ -356,7 +388,8 @@ QSize QetGraphicsTableItem::minimumSize() const
|
||||
Limit the number of row to display
|
||||
@param number : set to 0 or less to disabled the limit of row to display
|
||||
*/
|
||||
void QetGraphicsTableItem::setDisplayNRow(const int &number) {
|
||||
void QetGraphicsTableItem::setDisplayNRow(const int &number)
|
||||
{
|
||||
m_number_of_displayed_row = number;
|
||||
setToMinimumHeight();
|
||||
if (m_next_table)
|
||||
@@ -368,7 +401,8 @@ void QetGraphicsTableItem::setDisplayNRow(const int &number) {
|
||||
@return the number of row displayed.
|
||||
A value of 0 or less mean there is no limit
|
||||
*/
|
||||
int QetGraphicsTableItem::displayNRow() const {
|
||||
int QetGraphicsTableItem::displayNRow() const
|
||||
{
|
||||
return m_number_of_displayed_row;
|
||||
}
|
||||
|
||||
@@ -439,11 +473,13 @@ void QetGraphicsTableItem::setNextTable(QetGraphicsTableItem *table)
|
||||
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::setTableName(const QString &name) {
|
||||
void QetGraphicsTableItem::setTableName(const QString &name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString QetGraphicsTableItem::tableName() const {
|
||||
QString QetGraphicsTableItem::tableName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
@@ -461,11 +497,13 @@ int QetGraphicsTableItem::displayNRowOffset() const
|
||||
return offset_;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const {
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const
|
||||
{
|
||||
return m_previous_table;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const {
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const
|
||||
{
|
||||
return m_next_table;
|
||||
}
|
||||
|
||||
@@ -498,7 +536,8 @@ void QetGraphicsTableItem::initLink()
|
||||
@brief QetGraphicsTableItem::minimumRowHeigth
|
||||
@return the minimum height of a row
|
||||
*/
|
||||
int QetGraphicsTableItem::minimumRowHeigth() const {
|
||||
int QetGraphicsTableItem::minimumRowHeigth() const
|
||||
{
|
||||
return m_minimum_row_height;
|
||||
}
|
||||
|
||||
@@ -554,103 +593,139 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element)
|
||||
return;
|
||||
}
|
||||
|
||||
this->setPos(dom_element.attribute("x", QString::number(10)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(10)).toDouble());
|
||||
//Size is not set now because will change during the whole process of opening a project from the xml
|
||||
m_pending_size = QSize(dom_element.attribute("width", QString::number(no_model_width)).toInt(),
|
||||
dom_element.attribute("height", QString::number(no_model_height)).toInt());
|
||||
this->setPos(
|
||||
dom_element.attribute(
|
||||
"x",
|
||||
QString::number(10)).toDouble(),
|
||||
dom_element.attribute(
|
||||
"y",
|
||||
QString::number(10)).toDouble());
|
||||
//Size is not set now because will change during the whole process of opening a project from the xml
|
||||
m_pending_size = QSize(
|
||||
dom_element.attribute(
|
||||
"width",
|
||||
QString::number(no_model_width)).toInt(),
|
||||
dom_element.attribute(
|
||||
"height",
|
||||
QString::number(no_model_height)).toInt());
|
||||
|
||||
m_uuid = QUuid(dom_element.attribute("uuid", QUuid::createUuid().toString()));
|
||||
m_uuid = QUuid(
|
||||
dom_element.attribute(
|
||||
"uuid",
|
||||
QUuid::createUuid().toString()));
|
||||
m_name = dom_element.attribute("name");
|
||||
m_number_of_displayed_row = dom_element.attribute("display_n_row", QString::number(0)).toInt();
|
||||
m_number_of_displayed_row = dom_element.attribute(
|
||||
"display_n_row",
|
||||
QString::number(0)).toInt();
|
||||
|
||||
auto vector_ = QETXML::directChild(dom_element, "previous_table");
|
||||
if (vector_.size()) { //Table have a previous table
|
||||
m_pending_previous_table_uuid = QUuid(vector_.first().attribute("uuid"));
|
||||
m_pending_previous_table_uuid = QUuid(
|
||||
vector_.first().attribute("uuid"));
|
||||
}
|
||||
else if (this->diagram()) //The table haven't got a previous table, so there should be a model save to xml
|
||||
{
|
||||
//Get table
|
||||
auto model_ = new ProjectDBModel(this->diagram()->project(), this->diagram()->project());
|
||||
model_->fromXml(dom_element.firstChildElement("model").firstChildElement(ProjectDBModel::xmlTagName()));
|
||||
//Get table
|
||||
auto model_ = new ProjectDBModel(
|
||||
this->diagram()->project(),
|
||||
this->diagram()->project());
|
||||
model_->fromXml(
|
||||
dom_element
|
||||
.firstChildElement("model")
|
||||
.firstChildElement(
|
||||
ProjectDBModel::xmlTagName()));
|
||||
this->setModel(model_);
|
||||
}
|
||||
|
||||
//Restore the header from xml
|
||||
m_header_item->fromXml(dom_element.firstChildElement(QetGraphicsHeaderItem::xmlTagName()));
|
||||
//Restore the header from xml
|
||||
m_header_item->fromXml(
|
||||
dom_element.firstChildElement(
|
||||
QetGraphicsHeaderItem::xmlTagName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsTableItem::toDXF
|
||||
Draw this table to the dxf document
|
||||
@param filepath file path of the the dxf document
|
||||
@return true if draw success
|
||||
@brief QetGraphicsTableItem::toDXF
|
||||
Draw this table to the dxf document
|
||||
@param filepath file path of the the dxf document
|
||||
@return true if draw success
|
||||
*/
|
||||
bool QetGraphicsTableItem::toDXF(const QString &filepath)
|
||||
{
|
||||
// Header
|
||||
m_header_item->toDXF(filepath);
|
||||
// Header
|
||||
m_header_item->toDXF(filepath);
|
||||
|
||||
//QRectF rect = boundingRect();
|
||||
QRectF rect(0,0, m_header_item->rect().width(), m_current_size.height());
|
||||
QPolygonF poly(rect);
|
||||
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
||||
//QRectF rect = boundingRect();
|
||||
QRectF rect(0,0, m_header_item->rect().width(), m_current_size.height());
|
||||
QPolygonF poly(rect);
|
||||
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
||||
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto i=0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
QPointF p1(offset+m_header_item->sectionSize(i), 0);
|
||||
QPointF p2(offset+m_header_item->sectionSize(i), m_current_size.height());
|
||||
Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0);
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
//Calculate the number of rows to display.
|
||||
auto row_count = m_model->rowCount();
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto i=0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
QPointF p1(offset+m_header_item->sectionSize(i), 0);
|
||||
QPointF p2(
|
||||
offset+m_header_item->sectionSize(i),
|
||||
m_current_size.height());
|
||||
Createdxf::drawLine(
|
||||
filepath,
|
||||
QLineF(mapToScene(p1),mapToScene(p2)),
|
||||
0);
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
//Calculate the number of rows to display.
|
||||
auto row_count = m_model->rowCount();
|
||||
|
||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||
row_count -= m_previous_table->displayNRowOffset();
|
||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||
row_count -= m_previous_table->displayNRowOffset();
|
||||
|
||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
//Draw horizontal lines
|
||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||
for(auto i= 1 ; i-1<row_count ; ++i)
|
||||
{
|
||||
QPointF p1(m_header_item->rect().left(), cell_height*i);
|
||||
QPointF p2(m_header_item->rect().right(), cell_height*i);
|
||||
Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0);
|
||||
}
|
||||
//Draw horizontal lines
|
||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||
for(auto i= 1 ; i-1<row_count ; ++i)
|
||||
{
|
||||
QPointF p1(m_header_item->rect().left(), cell_height*i);
|
||||
QPointF p2(m_header_item->rect().right(), cell_height*i);
|
||||
Createdxf::drawLine(
|
||||
filepath,
|
||||
QLineF(mapToScene(p1),mapToScene(p2))
|
||||
,0);
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
for (auto i=0 ; i<row_count ; ++i)
|
||||
{
|
||||
auto margin_ = QETUtils::marginsFromString(m_model->index(0,0).data(Qt::UserRole+1).toString());
|
||||
QPointF top_left(margin_.left(), i==0? margin_.top() : cell_height*i + margin_.top());
|
||||
//Write text of each cell
|
||||
for (auto i=0 ; i<row_count ; ++i)
|
||||
{
|
||||
auto margin_ = QETUtils::marginsFromString(m_model->index(0,0).data(Qt::UserRole+1).toString());
|
||||
QPointF top_left(margin_.left(), i==0? margin_.top() : cell_height*i + margin_.top());
|
||||
|
||||
for(auto j= 0 ; j<m_model->columnCount() ; ++j)
|
||||
{
|
||||
//In first iteration the top left X is margin left, in all other iteration the top left X is stored in m_column_size
|
||||
if (j>0) {
|
||||
top_left.setX(top_left.x() + m_header_item->sectionSize(j-1));
|
||||
}
|
||||
QSize size(m_header_item->sectionSize(j) - margin_.left() - margin_.right(),
|
||||
static_cast<int>(cell_height) - margin_.top() - margin_.bottom());
|
||||
auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i;
|
||||
for(auto j= 0 ; j<m_model->columnCount() ; ++j)
|
||||
{
|
||||
//In first iteration the top left X is margin left,
|
||||
// in all other iteration the top left X is stored in m_column_size
|
||||
if (j>0) {
|
||||
top_left.setX(top_left.x() + m_header_item->sectionSize(j-1));
|
||||
}
|
||||
QSize size(m_header_item->sectionSize(j) - margin_.left() - margin_.right(),
|
||||
static_cast<int>(cell_height) - margin_.top() - margin_.bottom());
|
||||
auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i;
|
||||
|
||||
QPointF qm = mapToScene(top_left);
|
||||
qreal h = size.height();// * Createdxf::yScale;
|
||||
qreal x = qm.x() * Createdxf::xScale;
|
||||
qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale);
|
||||
qreal h1 = h * 0.5 * Createdxf::yScale;
|
||||
QPointF qm = mapToScene(top_left);
|
||||
qreal h = size.height();// * Createdxf::yScale;
|
||||
qreal x = qm.x() * Createdxf::xScale;
|
||||
qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale);
|
||||
qreal h1 = h * 0.5 * Createdxf::yScale;
|
||||
|
||||
int valign = 2;
|
||||
int valign = 2;
|
||||
|
||||
Createdxf::drawTextAligned(filepath,m_model->index(index_row, j).data().toString(),x,y,h1,0,0,0,valign,x,0,0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
Createdxf::drawTextAligned(
|
||||
filepath,
|
||||
m_model->index(index_row, j).data().toString(),
|
||||
x,y,h1,0,0,0,valign,x,0,0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -719,7 +794,8 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
QVariant QetGraphicsTableItem::itemChange(
|
||||
QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
//item was removed from scene, we remove the handler
|
||||
if (change == ItemSceneHasChanged) {
|
||||
@@ -731,7 +807,8 @@ QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange chan
|
||||
return QetGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::modelReseted() {
|
||||
void QetGraphicsTableItem::modelReseted()
|
||||
{
|
||||
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
||||
setToMinimumHeight();
|
||||
|
||||
@@ -768,7 +845,11 @@ void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
|
||||
{
|
||||
auto index = m_model->index(row, col);
|
||||
auto width = metrics.boundingRect(index.data().toString()).width();
|
||||
m_minimum_column_width.replace(col, std::max(m_minimum_column_width.at(col), width + margin_.left() + margin_.right()));
|
||||
m_minimum_column_width.replace(
|
||||
col,
|
||||
std::max(
|
||||
m_minimum_column_width.at(col),
|
||||
width + margin_.left() + margin_.right()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -779,15 +860,24 @@ void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
|
||||
void QetGraphicsTableItem::setUpBoundingRect()
|
||||
{
|
||||
QSize header_size = m_header_item->rect().size();
|
||||
QRect rect(0, -header_size.height(), header_size.width(), m_current_size.height() + header_size.height());
|
||||
m_bounding_rect = rect.adjusted(-m_br_margin, -m_br_margin, m_br_margin, m_br_margin);
|
||||
QRect rect(
|
||||
0,
|
||||
-header_size.height(),
|
||||
header_size.width(),
|
||||
m_current_size.height() + header_size.height());
|
||||
m_bounding_rect = rect.adjusted(
|
||||
-m_br_margin,
|
||||
-m_br_margin,
|
||||
m_br_margin,
|
||||
m_br_margin);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsTableItem::adjustHandlerPos
|
||||
Adjust the pos of the handler item
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustHandlerPos() {
|
||||
void QetGraphicsTableItem::adjustHandlerPos()
|
||||
{
|
||||
m_handler_item.setPos(mapToScene(QRect(QPoint(0,0), size()).bottomRight()));
|
||||
}
|
||||
|
||||
@@ -800,23 +890,30 @@ void QetGraphicsTableItem::setUpHandler()
|
||||
m_handler_item.setZValue(this->zValue() + 1);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMousePressEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
diagram()->clearSelection();
|
||||
this->setSelected(true);
|
||||
m_old_size = size();
|
||||
//User start to resize the table, disconnect the signal to avoid double paint.
|
||||
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
//User start to resize the table, disconnect the signal to avoid double paint.
|
||||
disconnect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMouseMoveEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
auto new_handler_pos = Diagram::snapToGrid(event->scenePos());
|
||||
QSize size_ = QRectF(QPointF(0,0), mapFromScene(new_handler_pos)).size().toSize();
|
||||
|
||||
QPoint new_pos(std::max(minimumSize().width(), size_.width()),
|
||||
std::max(minimumSize().height(), size_.height()));
|
||||
QPoint new_pos(
|
||||
std::max(minimumSize().width(), size_.width()),
|
||||
std::max(minimumSize().height(), size_.height()));
|
||||
m_handler_item.setPos(mapToScene(new_pos));
|
||||
|
||||
QSize new_size(new_pos.x(), new_pos.y());
|
||||
@@ -825,7 +922,8 @@ void QetGraphicsTableItem::handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMouseReleaseEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (diagram())
|
||||
@@ -836,12 +934,17 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *ev
|
||||
diagram()->undoStack().push(undo);
|
||||
}
|
||||
//User finish to resize the table, we can reconnect now
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsTableItem::adjustColumnsWidth
|
||||
Adjust the size of each column according to the current table width by setting the sectionSize of the header item
|
||||
Adjust the size of each column according to the current table width
|
||||
by setting the sectionSize of the header item
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
{
|
||||
@@ -857,38 +960,59 @@ void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
auto a = m_current_size.width() - minimumSize().width();
|
||||
auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0
|
||||
|
||||
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized); //Avoid to resize
|
||||
//Avoid to resize
|
||||
disconnect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
|
||||
int sum_=0;
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
auto at_a = std::min(m_minimum_column_width.size()-1, i); //In case of the I is higher than m_minimum_column_width or
|
||||
auto at_b = std::min(m_header_item->minimumSectionWidth().size()-1, i); //m_header_item->minimumSectionWidth().size()
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(at_a),
|
||||
m_header_item->minimumSectionWidth().at(at_b))+b);
|
||||
m_header_item->resizeSection(
|
||||
i,
|
||||
std::max(
|
||||
m_minimum_column_width.at(at_a),
|
||||
m_header_item->minimumSectionWidth().at(at_b))+b);
|
||||
sum_+= m_header_item->sectionSize(i);
|
||||
}
|
||||
|
||||
|
||||
//The sum of the header sections width can be less than width of @m_current_size we adjust it in order to have the same width
|
||||
//The sum of the header sections width can be less than width of
|
||||
// @m_current_size we adjust it in order to have the same width
|
||||
if (m_model->columnCount() > 0 &&
|
||||
sum_ < m_current_size.width())
|
||||
{
|
||||
//add the quotient of the division to each columns
|
||||
//add the quotient of the division to each columns
|
||||
auto result = (m_current_size.width()-sum_)/m_model->columnCount();
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i) {
|
||||
m_header_item->resizeSection(i, m_header_item->sectionSize(i) + result);
|
||||
m_header_item->resizeSection(
|
||||
i,
|
||||
m_header_item->sectionSize(i) + result);
|
||||
}
|
||||
|
||||
//add the rest of the division to the last column
|
||||
auto last_section = m_model->columnCount()-1;
|
||||
m_header_item->resizeSection(last_section, m_header_item->sectionSize(last_section) + ((m_current_size.width()-sum_)%m_model->columnCount()));
|
||||
m_header_item->resizeSection(
|
||||
last_section,
|
||||
m_header_item->sectionSize(last_section)
|
||||
+ ((m_current_size.width()-sum_)%m_model->columnCount()));
|
||||
}
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
update();
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
void QetGraphicsTableItem::dataChanged(
|
||||
const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles)
|
||||
{
|
||||
Q_UNUSED(topLeft)
|
||||
Q_UNUSED(bottomRight)
|
||||
@@ -947,7 +1071,8 @@ void QetGraphicsTableItem::adjustSize()
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::previousTableDisplayRowChanged() {
|
||||
void QetGraphicsTableItem::previousTableDisplayRowChanged()
|
||||
{
|
||||
setToMinimumHeight();
|
||||
if (m_next_table) {
|
||||
m_next_table->previousTableDisplayRowChanged();
|
||||
|
||||
@@ -47,11 +47,13 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow)
|
||||
|
||||
public :
|
||||
static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0));
|
||||
static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table);
|
||||
static void adjustTableToFolio(
|
||||
QetGraphicsTableItem *table,
|
||||
QMargins margins = QMargins(20,20,20,0));
|
||||
static void checkInsufficientRowsCount(
|
||||
QetGraphicsTableItem *first_table);
|
||||
|
||||
public:
|
||||
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
||||
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
||||
virtual ~QetGraphicsTableItem() override;
|
||||
|
||||
enum { Type = UserType + 1300 };
|
||||
@@ -61,8 +63,12 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
QetGraphicsHeaderItem *headerItem() const {return m_header_item;}
|
||||
virtual void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
QetGraphicsHeaderItem *headerItem() const
|
||||
{return m_header_item;}
|
||||
void setSize(const QSize &size);
|
||||
QSize size() const;
|
||||
QSize minimumSize() const;
|
||||
@@ -83,16 +89,22 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
QDomElement toXml(QDomDocument &dom_document) const;
|
||||
void fromXml(const QDomElement &dom_element);
|
||||
static QString xmlTagName() {return QString("graphics_table");}
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
virtual void hoverEnterEvent(
|
||||
QGraphicsSceneHoverEvent *event) override;
|
||||
virtual void hoverLeaveEvent(
|
||||
QGraphicsSceneHoverEvent *event) override;
|
||||
virtual bool sceneEventFilter(
|
||||
QGraphicsItem *watched,
|
||||
QEvent *event) override;
|
||||
virtual QVariant itemChange(
|
||||
GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
|
||||
private:
|
||||
void modelReseted();
|
||||
private:
|
||||
void modelReseted();
|
||||
void setUpColumnAndRowMinimumSize();
|
||||
void setUpBoundingRect();
|
||||
void adjustHandlerPos();
|
||||
@@ -101,33 +113,40 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
void handlerMouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
void adjustColumnsWidth();
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
void dataChanged(
|
||||
const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles);
|
||||
void headerSectionResized();
|
||||
void adjustSize();
|
||||
void previousTableDisplayRowChanged();
|
||||
|
||||
private:
|
||||
QAbstractItemModel *m_model= nullptr;
|
||||
QAbstractItemModel *m_model= nullptr;
|
||||
|
||||
QVector<int> m_minimum_column_width;
|
||||
int m_minimum_row_height;
|
||||
int m_number_of_displayed_row = 0;
|
||||
QSize m_current_size,
|
||||
m_old_size,
|
||||
m_pending_size;
|
||||
int
|
||||
m_minimum_row_height,
|
||||
m_number_of_displayed_row = 0,
|
||||
m_br_margin = 10;
|
||||
|
||||
QSize
|
||||
m_current_size,
|
||||
m_old_size,
|
||||
m_pending_size;
|
||||
|
||||
int m_br_margin= 10;
|
||||
QRectF m_bounding_rect;
|
||||
|
||||
QetGraphicsHandlerItem m_handler_item;
|
||||
QetGraphicsHeaderItem *m_header_item = nullptr;
|
||||
|
||||
QetGraphicsTableItem *m_previous_table = nullptr,
|
||||
*m_next_table = nullptr;
|
||||
QetGraphicsTableItem
|
||||
*m_previous_table = nullptr,
|
||||
*m_next_table = nullptr;
|
||||
|
||||
QString m_name;
|
||||
QUuid m_uuid = QUuid::createUuid(),
|
||||
m_pending_previous_table_uuid;
|
||||
QUuid
|
||||
m_uuid = QUuid::createUuid(),
|
||||
m_pending_previous_table_uuid;
|
||||
};
|
||||
|
||||
#endif // QetGraphicsTableItem_H
|
||||
|
||||
@@ -34,11 +34,13 @@
|
||||
@param table
|
||||
@param parent
|
||||
*/
|
||||
GraphicsTablePropertiesEditor::GraphicsTablePropertiesEditor(QetGraphicsTableItem *table, QWidget *parent) :
|
||||
GraphicsTablePropertiesEditor::GraphicsTablePropertiesEditor(
|
||||
QetGraphicsTableItem *table,
|
||||
QWidget *parent) :
|
||||
PropertiesEditorWidget(parent),
|
||||
ui(new Ui::GraphicsTablePropertiesEditor)
|
||||
ui(new Ui::GraphicsTablePropertiesEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->setupUi(this);
|
||||
m_header_button_group = new QButtonGroup(this);
|
||||
m_header_button_group->addButton(ui->m_header_align_left_rb, Qt::AlignLeft);
|
||||
m_header_button_group->addButton(ui->m_header_align_center_rb, Qt::AlignHCenter);
|
||||
@@ -59,7 +61,8 @@ GraphicsTablePropertiesEditor::GraphicsTablePropertiesEditor(QetGraphicsTableIte
|
||||
/**
|
||||
@brief GraphicsTablePropertiesEditor::~GraphicsTablePropertiesEditor
|
||||
*/
|
||||
GraphicsTablePropertiesEditor::~GraphicsTablePropertiesEditor() {
|
||||
GraphicsTablePropertiesEditor::~GraphicsTablePropertiesEditor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@@ -84,8 +87,14 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table)
|
||||
|
||||
m_table_item = table;
|
||||
m_connect_list.clear();
|
||||
m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::xChanged, this, &GraphicsTablePropertiesEditor::updateUi);
|
||||
m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::yChanged, this, &GraphicsTablePropertiesEditor::updateUi);
|
||||
m_connect_list << connect(m_table_item.data(),
|
||||
&QetGraphicsTableItem::xChanged,
|
||||
this,
|
||||
&GraphicsTablePropertiesEditor::updateUi);
|
||||
m_connect_list << connect(m_table_item.data(),
|
||||
&QetGraphicsTableItem::yChanged,
|
||||
this,
|
||||
&GraphicsTablePropertiesEditor::updateUi);
|
||||
|
||||
|
||||
if (auto editor = PropertiesEditorFactory::propertiesEditor(table->model(), this))
|
||||
@@ -121,63 +130,103 @@ QUndoCommand *GraphicsTablePropertiesEditor::associatedUndo() const
|
||||
if (m_live_edit)
|
||||
{
|
||||
if (!qFuzzyCompare(ui->m_x_pos->value(), m_table_item->pos().x())) {
|
||||
auto undo = new QPropertyUndoCommand(m_table_item.data(), "x", m_table_item->pos().x(), ui->m_x_pos->value());
|
||||
auto undo = new QPropertyUndoCommand(
|
||||
m_table_item.data(),
|
||||
"x",
|
||||
m_table_item->pos().x(),
|
||||
ui->m_x_pos->value());
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
if (!qFuzzyCompare(ui->m_y_pos->value(), m_table_item->pos().y())) {
|
||||
auto undo = new QPropertyUndoCommand(m_table_item.data(), "y", m_table_item->pos().y(), ui->m_y_pos->value());
|
||||
auto undo = new QPropertyUndoCommand(
|
||||
m_table_item.data(),
|
||||
"y",
|
||||
m_table_item->pos().y(),
|
||||
ui->m_y_pos->value());
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
if (ui->m_display_n_row_sb->value() != m_table_item->displayNRow()) {
|
||||
auto undo = new QPropertyUndoCommand(m_table_item.data(), "displayNRow", m_table_item->displayNRow(), ui->m_display_n_row_sb->value());
|
||||
auto undo = new QPropertyUndoCommand(
|
||||
m_table_item.data(),
|
||||
"displayNRow",
|
||||
m_table_item->displayNRow(),
|
||||
ui->m_display_n_row_sb->value());
|
||||
undo->setText(tr("Modifier le nombre de ligne affiché par un tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
QMargins edited_header_margins(ui->m_header_left_margin->value(),
|
||||
ui->m_header_top_margin->value(),
|
||||
ui->m_header_right_margin->value(),
|
||||
ui->m_header_bottom_margin->value());
|
||||
auto model_header_margins = QETUtils::marginsFromString(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
QMargins edited_header_margins(
|
||||
ui->m_header_left_margin->value(),
|
||||
ui->m_header_top_margin->value(),
|
||||
ui->m_header_right_margin->value(),
|
||||
ui->m_header_bottom_margin->value());
|
||||
auto model_header_margins = QETUtils::marginsFromString(
|
||||
m_table_item->model()->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
if (edited_header_margins != model_header_margins)
|
||||
{
|
||||
auto undo = new ModelHeaderDataCommand(m_table_item->model());
|
||||
undo->setData(0, Qt::Horizontal, QETUtils::marginsToString(edited_header_margins), Qt::UserRole+1);
|
||||
undo->setData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
QETUtils::marginsToString(edited_header_margins),
|
||||
Qt::UserRole+1);
|
||||
undo->setText(tr("Modifier les marges d'une en tête de tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
QMargins edited_table_margins(ui->m_table_left_margin->value(),
|
||||
ui->m_table_top_margin->value(),
|
||||
ui->m_table_right_margin->value(),
|
||||
ui->m_table_bottom_margin->value());
|
||||
auto model_margins = QETUtils::marginsFromString(m_table_item->model()->index(0,0).data(Qt::UserRole+1).toString());
|
||||
QMargins edited_table_margins(
|
||||
ui->m_table_left_margin->value(),
|
||||
ui->m_table_top_margin->value(),
|
||||
ui->m_table_right_margin->value(),
|
||||
ui->m_table_bottom_margin->value());
|
||||
auto model_margins = QETUtils::marginsFromString(
|
||||
m_table_item->model()->index(0,0).data(Qt::UserRole+1).toString());
|
||||
if (edited_table_margins != model_margins)
|
||||
{
|
||||
auto undo = new ModelIndexCommand(m_table_item->model(), m_table_item->model()->index(0,0));
|
||||
undo->setData(QETUtils::marginsToString(edited_table_margins), Qt::UserRole+1);
|
||||
auto undo = new ModelIndexCommand(
|
||||
m_table_item->model(),
|
||||
m_table_item->model()->index(0,0));
|
||||
undo->setData(
|
||||
QETUtils::marginsToString(edited_table_margins),
|
||||
Qt::UserRole+1);
|
||||
undo->setText(tr("Modifier les marges d'un tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
if (m_header_button_group->checkedId() != m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt())
|
||||
if (m_header_button_group->checkedId()
|
||||
!= m_table_item->model()->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::TextAlignmentRole).toInt())
|
||||
{
|
||||
auto undo = new ModelHeaderDataCommand(m_table_item->model());
|
||||
undo->setData(0, Qt::Horizontal, m_header_button_group->checkedId(), Qt::TextAlignmentRole);
|
||||
undo->setData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
m_header_button_group->checkedId(),
|
||||
Qt::TextAlignmentRole);
|
||||
undo->setText(tr("Modifier l'alignement d'une en tête de tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
if (m_table_button_group->checkedId() != m_table_item->model()->index(0,0).data(Qt::TextAlignmentRole).toInt())
|
||||
if (m_table_button_group->checkedId()
|
||||
!= m_table_item->model()->index(0,0).data(Qt::TextAlignmentRole).toInt())
|
||||
{
|
||||
auto undo = new ModelIndexCommand(m_table_item->model(), m_table_item->model()->index(0,0));
|
||||
undo->setData(m_table_button_group->checkedId(), Qt::TextAlignmentRole);
|
||||
auto undo = new ModelIndexCommand(
|
||||
m_table_item->model(),
|
||||
m_table_item->model()->index(0,0));
|
||||
undo->setData(
|
||||
m_table_button_group->checkedId(),
|
||||
Qt::TextAlignmentRole);
|
||||
undo->setText(tr("Modifier l'alignement des textes d'un tableau"));
|
||||
return undo;
|
||||
}
|
||||
@@ -205,13 +254,21 @@ void GraphicsTablePropertiesEditor::on_m_header_font_pb_clicked()
|
||||
if (m_table_item && m_table_item->model())
|
||||
{
|
||||
bool ok;
|
||||
auto font = QFontDialog::getFont(&ok,
|
||||
m_table_item->model()->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>(),
|
||||
this);
|
||||
auto font = QFontDialog::getFont(
|
||||
&ok,
|
||||
m_table_item->model()->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::FontRole).value<QFont>(),
|
||||
this);
|
||||
if (ok && m_table_item->model())
|
||||
{
|
||||
auto undo = new ModelHeaderDataCommand(m_table_item->model());
|
||||
undo->setData(0, Qt::Horizontal, QVariant::fromValue(font), Qt::FontRole);
|
||||
undo->setData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
QVariant::fromValue(font),
|
||||
Qt::FontRole);
|
||||
undo->setText(tr("Modifier la police d'une en tête de tableau"));
|
||||
m_table_item->diagram()->undoStack().push(undo);
|
||||
}
|
||||
@@ -227,12 +284,15 @@ void GraphicsTablePropertiesEditor::on_m_table_font_pb_clicked()
|
||||
{
|
||||
bool ok;
|
||||
auto index = m_table_item->model()->index(0,0);
|
||||
auto old_font = m_table_item->model()->data(index, Qt::FontRole).value<QFont>();
|
||||
auto old_font = m_table_item->model()->data(
|
||||
index,
|
||||
Qt::FontRole).value<QFont>();
|
||||
auto new_font = QFontDialog::getFont(&ok, old_font, this);
|
||||
|
||||
if (ok && m_table_item->diagram())
|
||||
{
|
||||
auto undo = new ModelIndexCommand(m_table_item->model(), index);
|
||||
auto undo = new ModelIndexCommand(
|
||||
m_table_item->model(), index);
|
||||
undo->setData(QVariant::fromValue(new_font), Qt::FontRole);
|
||||
undo->setText(tr("Changer la police d'un tableau"));
|
||||
m_table_item->diagram()->undoStack().push(undo);
|
||||
@@ -268,8 +328,12 @@ void GraphicsTablePropertiesEditor::updateUi()
|
||||
if (auto item_ = m_table_item->previousTable()) //Add the current previous table
|
||||
{
|
||||
m_other_table_vector.append(item_);
|
||||
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
|
||||
ui->m_previous_table_cb->setCurrentIndex(ui->m_previous_table_cb->findData(m_other_table_vector.indexOf(item_)));
|
||||
ui->m_previous_table_cb->addItem(
|
||||
item_->tableName(),
|
||||
m_other_table_vector.indexOf(item_));
|
||||
ui->m_previous_table_cb->setCurrentIndex(
|
||||
ui->m_previous_table_cb->findData(
|
||||
m_other_table_vector.indexOf(item_)));
|
||||
}
|
||||
|
||||
ElementProvider ep(m_table_item->diagram()->project());
|
||||
@@ -279,19 +343,27 @@ void GraphicsTablePropertiesEditor::updateUi()
|
||||
item_->nextTable() == nullptr)
|
||||
{
|
||||
m_other_table_vector.append(item_);
|
||||
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
|
||||
ui->m_previous_table_cb->addItem(
|
||||
item_->tableName(),
|
||||
m_other_table_vector.indexOf(item_));
|
||||
}
|
||||
}
|
||||
|
||||
updateInfoLabel();
|
||||
|
||||
auto margin = QETUtils::marginsFromString(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
auto margin = QETUtils::marginsFromString(
|
||||
m_table_item->model()->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
ui->m_header_top_margin ->setValue(margin.top());
|
||||
ui->m_header_left_margin ->setValue(margin.left());
|
||||
ui->m_header_right_margin ->setValue(margin.right());
|
||||
ui->m_header_bottom_margin->setValue(margin.bottom());
|
||||
|
||||
margin = QETUtils::marginsFromString(m_table_item->model()->index(0,0).data(Qt::UserRole+1).toString());
|
||||
margin = QETUtils::marginsFromString(
|
||||
m_table_item->model()->index(0,0).data(
|
||||
Qt::UserRole+1).toString());
|
||||
ui->m_table_top_margin ->setValue(margin.top());
|
||||
ui->m_table_left_margin ->setValue(margin.left());
|
||||
ui->m_table_right_margin ->setValue(margin.right());
|
||||
@@ -302,9 +374,16 @@ void GraphicsTablePropertiesEditor::updateUi()
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto button = m_header_button_group->button(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt()))
|
||||
if (auto button = m_header_button_group->button(
|
||||
m_table_item->model()->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::TextAlignmentRole).toInt()))
|
||||
button->setChecked(true);
|
||||
if (auto button = m_table_button_group->button(m_table_item->model()->data(m_table_item->model()->index(0,0), Qt::TextAlignmentRole).toInt()))
|
||||
if (auto button = m_table_button_group->button(
|
||||
m_table_item->model()->data(
|
||||
m_table_item->model()->index(0,0),
|
||||
Qt::TextAlignmentRole).toInt()))
|
||||
button->setChecked(true);
|
||||
|
||||
setUpEditConnection();
|
||||
@@ -378,7 +457,8 @@ void GraphicsTablePropertiesEditor::setUpEditConnection()
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsTablePropertiesEditor::on_m_table_name_le_textEdited(const QString &arg1) {
|
||||
void GraphicsTablePropertiesEditor::on_m_table_name_le_textEdited(const QString &arg1)
|
||||
{
|
||||
m_table_item->setTableName(arg1);
|
||||
}
|
||||
|
||||
@@ -387,7 +467,9 @@ void GraphicsTablePropertiesEditor::on_m_previous_table_cb_activated(int index)
|
||||
if (index == 0) {
|
||||
m_table_item->setPreviousTable();
|
||||
} else {
|
||||
m_table_item->setPreviousTable(m_other_table_vector.at(ui->m_previous_table_cb->currentData().toInt()));
|
||||
m_table_item->setPreviousTable(
|
||||
m_other_table_vector.at(
|
||||
ui->m_previous_table_cb->currentData().toInt()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,7 +506,10 @@ void GraphicsTablePropertiesEditor::on_m_auto_geometry_pb_clicked()
|
||||
*/
|
||||
void GraphicsTablePropertiesEditor::on_m_apply_geometry_to_linked_table_pb_clicked()
|
||||
{
|
||||
if (m_table_item.isNull() || !m_table_item->diagram() || (!m_table_item->nextTable() && !m_table_item->previousTable())) {
|
||||
if (m_table_item.isNull()
|
||||
|| !m_table_item->diagram()
|
||||
|| (!m_table_item->nextTable()
|
||||
&& !m_table_item->previousTable())) {
|
||||
return;
|
||||
}
|
||||
auto first_table = m_table_item;
|
||||
|
||||
@@ -29,27 +29,31 @@
|
||||
@param model
|
||||
@param parent
|
||||
*/
|
||||
ProjectDBModelPropertiesWidget::ProjectDBModelPropertiesWidget(ProjectDBModel *model, QWidget *parent) :
|
||||
ProjectDBModelPropertiesWidget::ProjectDBModelPropertiesWidget(
|
||||
ProjectDBModel *model,
|
||||
QWidget *parent) :
|
||||
PropertiesEditorWidget(parent),
|
||||
ui(new Ui::ProjectDBModelPropertiesWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->setupUi(this);
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief projectDBModelPropertiesWidget::~projectDBModelPropertiesWidget
|
||||
*/
|
||||
ProjectDBModelPropertiesWidget::~ProjectDBModelPropertiesWidget() {
|
||||
delete ui;
|
||||
ProjectDBModelPropertiesWidget::~ProjectDBModelPropertiesWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief projectDBModelPropertiesWidget::setModel
|
||||
@param model
|
||||
*/
|
||||
void ProjectDBModelPropertiesWidget::setModel(ProjectDBModel *model) {
|
||||
m_model = model;
|
||||
void ProjectDBModelPropertiesWidget::setModel(ProjectDBModel *model)
|
||||
{
|
||||
m_model = model;
|
||||
ui->m_edit_query_pb->setEnabled(m_model);
|
||||
ui->m_refresh_pb->setEnabled(m_model);
|
||||
}
|
||||
@@ -93,7 +97,8 @@ void ProjectDBModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDBModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
void ProjectDBModelPropertiesWidget::on_m_refresh_pb_clicked()
|
||||
{
|
||||
if (m_model && m_model->project()) {
|
||||
m_model->project()->dataBase()->updateDB();
|
||||
}
|
||||
|
||||
@@ -147,7 +147,8 @@ Conductor::~Conductor()
|
||||
@return true if conductor is valid else false;
|
||||
A non valid conductor, is a conductor without two terminal
|
||||
*/
|
||||
bool Conductor::isValid() const {
|
||||
bool Conductor::isValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
@@ -288,7 +289,8 @@ QHash<ConductorSegmentProfile *, qreal> Conductor::shareOffsetBetweenSegments(
|
||||
const qreal &offset,
|
||||
const QList<ConductorSegmentProfile *> &segments_list,
|
||||
const qreal &precision
|
||||
) const {
|
||||
) const
|
||||
{
|
||||
// construit le QHash qui sera retourne
|
||||
QHash<ConductorSegmentProfile *, qreal> segments_hash;
|
||||
foreach(ConductorSegmentProfile *csp, segments_list) {
|
||||
@@ -556,14 +558,16 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
||||
}
|
||||
|
||||
/// @return le Diagram auquel ce conducteur appartient, ou 0 si ce conducteur est independant
|
||||
Diagram *Conductor::diagram() const {
|
||||
Diagram *Conductor::diagram() const
|
||||
{
|
||||
return(qobject_cast<Diagram *>(scene()));
|
||||
}
|
||||
|
||||
/**4
|
||||
@return le champ de texte associe a ce conducteur
|
||||
*/
|
||||
ConductorTextItem *Conductor::textItem() const {
|
||||
ConductorTextItem *Conductor::textItem() const
|
||||
{
|
||||
return(m_text_item);
|
||||
}
|
||||
|
||||
@@ -913,7 +917,8 @@ QPainterPath Conductor::nearShape() const
|
||||
@param type Type de Segments
|
||||
@return Le nombre de segments composant le conducteur.
|
||||
*/
|
||||
uint Conductor::segmentsCount(QET::ConductorSegmentType type) const {
|
||||
uint Conductor::segmentsCount(QET::ConductorSegmentType type) const
|
||||
{
|
||||
QList<ConductorSegment *> segments_list = segmentsList();
|
||||
if (type == QET::Both) return(segments_list.count());
|
||||
uint nb_seg = 0;
|
||||
@@ -927,7 +932,8 @@ uint Conductor::segmentsCount(QET::ConductorSegmentType type) const {
|
||||
Genere une liste de points a partir des segments de ce conducteur
|
||||
@return La liste de points representant ce conducteur
|
||||
*/
|
||||
QList<QPointF> Conductor::segmentsToPoints() const {
|
||||
QList<QPointF> Conductor::segmentsToPoints() const
|
||||
{
|
||||
// liste qui sera retournee
|
||||
QList<QPointF> points_list;
|
||||
|
||||
@@ -1168,7 +1174,8 @@ QVector<QPointF> Conductor::handlerPoints() const
|
||||
}
|
||||
|
||||
/// @return les segments de ce conducteur
|
||||
const QList<ConductorSegment *> Conductor::segmentsList() const {
|
||||
const QList<ConductorSegment *> Conductor::segmentsList() const
|
||||
{
|
||||
if (segments == nullptr) return(QList<ConductorSegment *>());
|
||||
|
||||
QList<ConductorSegment *> segments_vector;
|
||||
@@ -1193,7 +1200,8 @@ qreal Conductor::length() const{
|
||||
/**
|
||||
@return Le segment qui contient le point au milieu du conducteur
|
||||
*/
|
||||
ConductorSegment *Conductor::middleSegment() {
|
||||
ConductorSegment *Conductor::middleSegment()
|
||||
{
|
||||
if (segments == nullptr) return(nullptr);
|
||||
|
||||
qreal half_length = length() / 2.0;
|
||||
@@ -1440,7 +1448,8 @@ void Conductor::setProfile(const ConductorProfile &cp, Qt::Corner path_type) {
|
||||
}
|
||||
|
||||
/// @return le profil de ce conducteur
|
||||
ConductorProfile Conductor::profile(Qt::Corner path_type) const {
|
||||
ConductorProfile Conductor::profile(Qt::Corner path_type) const
|
||||
{
|
||||
return(conductor_profiles[path_type]);
|
||||
}
|
||||
|
||||
@@ -1586,7 +1595,8 @@ ConductorProperties Conductor::properties() const
|
||||
/**
|
||||
@return true si le conducteur est mis en evidence
|
||||
*/
|
||||
Conductor::Highlight Conductor::highlight() const {
|
||||
Conductor::Highlight Conductor::highlight() const
|
||||
{
|
||||
return(must_highlight_);
|
||||
}
|
||||
|
||||
@@ -1700,7 +1710,8 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(const bool all_diagram,
|
||||
@brief Conductor::diagramEditor
|
||||
@return The parent diagram editor or nullptr;
|
||||
*/
|
||||
QETDiagramEditor* Conductor::diagramEditor() const {
|
||||
QETDiagramEditor* Conductor::diagramEditor() const
|
||||
{
|
||||
if (!diagram()) return nullptr;
|
||||
if (diagram() -> views().isEmpty()) return nullptr;
|
||||
|
||||
@@ -1714,7 +1725,8 @@ QETDiagramEditor* Conductor::diagramEditor() const {
|
||||
/**
|
||||
@brief Conductor::editProperty
|
||||
*/
|
||||
void Conductor::editProperty() {
|
||||
void Conductor::editProperty()
|
||||
{
|
||||
ConductorPropertiesDialog::PropertiesDialog(this, diagramEditor());
|
||||
}
|
||||
|
||||
@@ -1770,7 +1782,8 @@ bool isContained(const QPointF &a, const QPointF &b, const QPointF &c) {
|
||||
/**
|
||||
@return la liste des positions des jonctions avec d'autres conducteurs
|
||||
*/
|
||||
QList<QPointF> Conductor::junctions() const {
|
||||
QList<QPointF> Conductor::junctions() const
|
||||
{
|
||||
QList<QPointF> junctions_list;
|
||||
|
||||
// pour qu'il y ait des jonctions, il doit y avoir d'autres conducteurs et des bifurcations
|
||||
@@ -1840,7 +1853,8 @@ QList<QPointF> Conductor::junctions() const {
|
||||
(en coordonnees locales) de la bifurcation tandis que le Corner indique le
|
||||
type de bifurcation.
|
||||
*/
|
||||
QList<ConductorBend> Conductor::bends() const {
|
||||
QList<ConductorBend> Conductor::bends() const
|
||||
{
|
||||
QList<ConductorBend> points;
|
||||
if (!segments) return(points);
|
||||
|
||||
@@ -1908,12 +1922,14 @@ Qt::Corner Conductor::movementType(const QPointF &start, const QPointF &end) {
|
||||
}
|
||||
|
||||
/// @return le type de trajet actuel de ce conducteur
|
||||
Qt::Corner Conductor::currentPathType() const {
|
||||
Qt::Corner Conductor::currentPathType() const
|
||||
{
|
||||
return(movementType(terminal1 -> dockConductor(), terminal2 -> dockConductor()));
|
||||
}
|
||||
|
||||
/// @return les profils de ce conducteur
|
||||
ConductorProfilesGroup Conductor::profiles() const {
|
||||
ConductorProfilesGroup Conductor::profiles() const
|
||||
{
|
||||
return(conductor_profiles);
|
||||
}
|
||||
|
||||
@@ -1936,7 +1952,8 @@ void Conductor::setProfiles(const ConductorProfilesGroup &cpg) {
|
||||
}
|
||||
|
||||
/// Supprime les segments
|
||||
void Conductor::deleteSegments() {
|
||||
void Conductor::deleteSegments()
|
||||
{
|
||||
if (segments != nullptr) {
|
||||
while (segments -> hasNextSegment()) delete segments -> nextSegment();
|
||||
delete segments;
|
||||
|
||||
@@ -79,14 +79,15 @@ class Conductor : public QGraphicsObject
|
||||
ConductorTextItem *textItem() const;
|
||||
void updatePath(const QRectF & = QRectF());
|
||||
|
||||
//This method do nothing, it's only made to be used with Q_PROPERTY
|
||||
//It's used to anim the path when is change
|
||||
//This method do nothing, it's only made to be used with Q_PROPERTY
|
||||
//It's used to anim the path when is change
|
||||
void updatePathAnimate(const int = 1) {updatePath();}
|
||||
int fakePath() {return 1;}
|
||||
|
||||
void paint(QPainter *,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
void paint(
|
||||
QPainter *,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
QRectF boundingRect() const override;
|
||||
QPainterPath shape() const override;
|
||||
virtual QPainterPath nearShape() const;
|
||||
@@ -100,9 +101,10 @@ class Conductor : public QGraphicsObject
|
||||
public:
|
||||
static bool valideXml (QDomElement &);
|
||||
bool fromXml (QDomElement &);
|
||||
QDomElement toXml (QDomDocument &,
|
||||
QHash<Terminal *,
|
||||
int> &) const;
|
||||
QDomElement toXml (
|
||||
QDomDocument &,
|
||||
QHash<Terminal *,
|
||||
int> &) const;
|
||||
private:
|
||||
bool pathFromXml(const QDomElement &);
|
||||
|
||||
@@ -110,8 +112,9 @@ class Conductor : public QGraphicsObject
|
||||
QVector <QPointF> handlerPoints() const;
|
||||
const QList<ConductorSegment *> segmentsList() const;
|
||||
|
||||
void setPropertyToPotential(const ConductorProperties &property,
|
||||
bool only_text = false);
|
||||
void setPropertyToPotential(
|
||||
const ConductorProperties &property,
|
||||
bool only_text = false);
|
||||
void setProperties(const ConductorProperties &property);
|
||||
ConductorProperties properties() const;
|
||||
|
||||
@@ -128,14 +131,17 @@ class Conductor : public QGraphicsObject
|
||||
QETDiagramEditor* diagramEditor() const;
|
||||
void editProperty ();
|
||||
|
||||
autonum::sequentialNumbers sequenceNum () const {return m_autoNum_seq;}
|
||||
autonum::sequentialNumbers& rSequenceNum() {return m_autoNum_seq;}
|
||||
autonum::sequentialNumbers sequenceNum () const
|
||||
{return m_autoNum_seq;}
|
||||
autonum::sequentialNumbers& rSequenceNum()
|
||||
{return m_autoNum_seq;}
|
||||
void setSequenceNum(const autonum::sequentialNumbers& sn);
|
||||
|
||||
QList<QPointF> junctions() const;
|
||||
|
||||
private:
|
||||
void setUpConnectionForFormula(QString old_formula, QString new_formula);
|
||||
void setUpConnectionForFormula(
|
||||
QString old_formula, QString new_formula);
|
||||
autonum::sequentialNumbers m_autoNum_seq;
|
||||
|
||||
public:
|
||||
@@ -145,20 +151,30 @@ class Conductor : public QGraphicsObject
|
||||
void displayedTextChanged();
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(
|
||||
QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(
|
||||
QGraphicsSceneMouseEvent *event) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange, const QVariant &) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
QVariant itemChange(
|
||||
GraphicsItemChange, const QVariant &) override;
|
||||
bool sceneEventFilter(
|
||||
QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMousePressEvent(
|
||||
QetGraphicsHandlerItem *qghi,
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent(
|
||||
QetGraphicsHandlerItem *qghi,
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent(
|
||||
QetGraphicsHandlerItem *qghi,
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
|
||||
@param text Le texte affiche par le champ de texte
|
||||
@param parent_conductor Conducteur auquel ce texte est rattache
|
||||
*/
|
||||
ConductorTextItem::ConductorTextItem(const QString &text,
|
||||
Conductor *parent_conductor) :
|
||||
ConductorTextItem::ConductorTextItem(
|
||||
const QString &text, Conductor *parent_conductor) :
|
||||
DiagramTextItem(text, parent_conductor),
|
||||
parent_conductor_(parent_conductor),
|
||||
moved_by_user_(false),
|
||||
@@ -49,14 +49,16 @@ ConductorTextItem::ConductorTextItem(const QString &text,
|
||||
/**
|
||||
Destructeur
|
||||
*/
|
||||
ConductorTextItem::~ConductorTextItem() {
|
||||
ConductorTextItem::~ConductorTextItem()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@return le conducteur parent de ce champ de texte, ou 0 si celui-ci n'en a
|
||||
pas
|
||||
*/
|
||||
Conductor *ConductorTextItem::parentConductor() const {
|
||||
Conductor *ConductorTextItem::parentConductor() const
|
||||
{
|
||||
return(parent_conductor_);
|
||||
}
|
||||
|
||||
@@ -81,7 +83,8 @@ void ConductorTextItem::fromXml(const QDomElement &e) {
|
||||
@return true si ce champ de texte a ete explictement deplace par
|
||||
l'utilisateur, false sinon
|
||||
*/
|
||||
bool ConductorTextItem::wasMovedByUser() const {
|
||||
bool ConductorTextItem::wasMovedByUser() const
|
||||
{
|
||||
return(moved_by_user_);
|
||||
}
|
||||
|
||||
@@ -89,7 +92,8 @@ bool ConductorTextItem::wasMovedByUser() const {
|
||||
@brief ConductorTextItem::wasRotateByUser
|
||||
@return true if text was explicit moved by user else false
|
||||
*/
|
||||
bool ConductorTextItem::wasRotateByUser() const {
|
||||
bool ConductorTextItem::wasRotateByUser() const
|
||||
{
|
||||
return(rotate_by_user_);
|
||||
}
|
||||
|
||||
@@ -120,7 +124,7 @@ void ConductorTextItem::forceRotateByUser(bool rotate_by_user) {
|
||||
rotate_by_user_ = rotate_by_user;
|
||||
if (!rotate_by_user && parent_conductor_) {
|
||||
parent_conductor_ -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,8 +158,8 @@ void ConductorTextItem::setPos(const QPointF &pos)
|
||||
*/
|
||||
void ConductorTextItem::setPos(qreal x, qreal y)
|
||||
{
|
||||
QPointF p(x,y);
|
||||
setPos(p);
|
||||
QPointF p(x,y);
|
||||
setPos(p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,7 +65,8 @@ CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
|
||||
@brief CrossRefItem::~CrossRefItem
|
||||
Default destructor
|
||||
*/
|
||||
CrossRefItem::~CrossRefItem() {}
|
||||
CrossRefItem::~CrossRefItem()
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief CrossRefItem::init
|
||||
@@ -107,16 +108,25 @@ void CrossRefItem::setUpConnection()
|
||||
set=true;
|
||||
else if(m_properties.snapTo() == XRefProperties::Bottom && !m_text && !m_group) //Snap to bottom of element and parent is the element itself
|
||||
{
|
||||
m_update_connection << connect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
|
||||
m_update_connection << connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
|
||||
m_update_connection << connect(m_element, SIGNAL(yChanged()),
|
||||
this, SLOT(autoPos()));
|
||||
m_update_connection << connect(m_element, SIGNAL(rotationChanged()),
|
||||
this, SLOT(autoPos()));
|
||||
set=true;
|
||||
}
|
||||
|
||||
if(set)
|
||||
{
|
||||
m_update_connection << connect(project, &QETProject::projectDiagramsOrderChanged, this, &CrossRefItem::updateLabel);
|
||||
m_update_connection << connect(project, &QETProject::diagramRemoved, this, &CrossRefItem::updateLabel);
|
||||
m_update_connection << connect(m_element, &Element::linkedElementChanged, this, &CrossRefItem::linkedChanged);
|
||||
m_update_connection
|
||||
<< connect(project,
|
||||
&QETProject::projectDiagramsOrderChanged,
|
||||
this, &CrossRefItem::updateLabel);
|
||||
m_update_connection << connect(project,
|
||||
&QETProject::diagramRemoved,
|
||||
this, &CrossRefItem::updateLabel);
|
||||
m_update_connection << connect(m_element,
|
||||
&Element::linkedElementChanged,
|
||||
this, &CrossRefItem::linkedChanged);
|
||||
linkedChanged();
|
||||
updateLabel();
|
||||
}
|
||||
@@ -126,7 +136,8 @@ void CrossRefItem::setUpConnection()
|
||||
@brief CrossRefItem::boundingRect
|
||||
@return the bounding rect of this item
|
||||
*/
|
||||
QRectF CrossRefItem::boundingRect() const {
|
||||
QRectF CrossRefItem::boundingRect() const
|
||||
{
|
||||
return m_bounding_rect;
|
||||
}
|
||||
|
||||
@@ -146,8 +157,8 @@ QPainterPath CrossRefItem::shape() const{
|
||||
if add_prefix is true,
|
||||
prefix (for power and delay contact) is added to the poistion text.
|
||||
*/
|
||||
QString CrossRefItem::elementPositionText(const Element *elmt,
|
||||
const bool &add_prefix) const
|
||||
QString CrossRefItem::elementPositionText(
|
||||
const Element *elmt, const bool &add_prefix) const
|
||||
{
|
||||
XRefProperties xrp =
|
||||
m_element->diagram()->project()->defaultXRefProperties(
|
||||
@@ -232,7 +243,8 @@ void CrossRefItem::updateLabel()
|
||||
@brief CrossRefItem::autoPos
|
||||
Calculate and set position automaticaly.
|
||||
*/
|
||||
void CrossRefItem::autoPos() {
|
||||
void CrossRefItem::autoPos()
|
||||
{
|
||||
//We calcul the position according to the snapTo of the xrefproperties
|
||||
if (m_properties.snapTo() == XRefProperties::Bottom)
|
||||
centerToBottomDiagram(this,
|
||||
@@ -285,9 +297,11 @@ bool CrossRefItem::sceneEvent(QEvent *event)
|
||||
@param option
|
||||
@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(widget)
|
||||
m_drawing.play(painter);
|
||||
@@ -406,9 +420,9 @@ void CrossRefItem::linkedChanged()
|
||||
{
|
||||
for(const QMetaObject::Connection& c : m_slave_connection)
|
||||
disconnect(c);
|
||||
|
||||
|
||||
m_slave_connection.clear();
|
||||
|
||||
|
||||
if(!isVisible())
|
||||
return;
|
||||
|
||||
@@ -423,7 +437,7 @@ void CrossRefItem::linkedChanged()
|
||||
this,
|
||||
&CrossRefItem::updateLabel);
|
||||
}
|
||||
|
||||
|
||||
updateLabel();
|
||||
}
|
||||
|
||||
@@ -431,7 +445,8 @@ void CrossRefItem::linkedChanged()
|
||||
@brief CrossRefItem::buildHeaderContact
|
||||
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;
|
||||
|
||||
//init the painter
|
||||
@@ -483,7 +498,7 @@ void CrossRefItem::buildHeaderContact() {
|
||||
*/
|
||||
void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
|
||||
{
|
||||
//No need to calcul if nothing is linked
|
||||
//No need to calcul if nothing is linked
|
||||
if (m_element->isFree()) return;
|
||||
|
||||
QStringList no_str, nc_str;
|
||||
@@ -495,14 +510,13 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
|
||||
nc_str.append(elementPositionText(elmt, true));
|
||||
}
|
||||
|
||||
|
||||
//There is no string to display, we return now
|
||||
//There is no string to display, we return now
|
||||
if (no_str.isEmpty() && nc_str.isEmpty()) return;
|
||||
|
||||
//this is the default size of cross ref item
|
||||
//this is the default size of cross ref item
|
||||
QRectF default_bounding(0, 0, 40, header + cross_min_heigth);
|
||||
|
||||
//Bounding rect of the NO text
|
||||
//Bounding rect of the NO text
|
||||
QRectF no_bounding;
|
||||
for (auto str : no_str)
|
||||
{
|
||||
@@ -510,13 +524,13 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
|
||||
no_bounding = no_bounding.united(bounding);
|
||||
no_bounding.setHeight(no_bounding.height() + bounding.height());
|
||||
}
|
||||
//Adjust according to the NO
|
||||
//Adjust according to the NO
|
||||
if (no_bounding.height() > default_bounding.height() - header)
|
||||
default_bounding.setHeight(no_bounding.height() + header); //adjust the height
|
||||
if (no_bounding.width() > default_bounding.width()/2)
|
||||
default_bounding.setWidth(no_bounding.width()*2); //adjust the width
|
||||
default_bounding.setWidth(no_bounding.width()*2);//adjust the width
|
||||
|
||||
//Bounding rect of the NC text
|
||||
//Bounding rect of the NC text
|
||||
QRectF nc_bounding;
|
||||
for (auto str : nc_str)
|
||||
{
|
||||
@@ -524,13 +538,13 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
|
||||
nc_bounding = nc_bounding.united(bounding);
|
||||
nc_bounding.setHeight(nc_bounding.height() + bounding.height());
|
||||
}
|
||||
//Adjust according to the NC
|
||||
//Adjust according to the NC
|
||||
if (nc_bounding.height() > default_bounding.height() - header)
|
||||
default_bounding.setHeight(nc_bounding.height() + header); //adjust the heigth
|
||||
if (nc_bounding.width() > default_bounding.width()/2)
|
||||
default_bounding.setWidth(nc_bounding.width()*2); //adjust the width
|
||||
default_bounding.setWidth(nc_bounding.width()*2);//adjust the width
|
||||
|
||||
//Minor adjustement for better visual
|
||||
//Minor adjustement for better visual
|
||||
default_bounding.adjust(0, 0, 4, 0);
|
||||
m_shape_path.addRect(default_bounding);
|
||||
prepareGeometryChange();
|
||||
@@ -544,26 +558,26 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
|
||||
*/
|
||||
void CrossRefItem::drawAsCross(QPainter &painter)
|
||||
{
|
||||
//calcul the size of the cross
|
||||
//calcul the size of the cross
|
||||
setUpCrossBoundingRect(painter);
|
||||
m_hovered_contacts_map.clear();
|
||||
|
||||
//Bounding rect is empty that mean there's no contact to draw
|
||||
//Bounding rect is empty that mean there's no contact to draw
|
||||
if (boundingRect().isEmpty()) return;
|
||||
|
||||
//draw the cross
|
||||
//draw the cross
|
||||
QRectF br = boundingRect();
|
||||
painter.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line
|
||||
painter.drawLine(0, header, br.width(), header); //horizontal line
|
||||
|
||||
//Add the symbolic contacts
|
||||
//Add the symbolic contacts
|
||||
buildHeaderContact();
|
||||
QPointF p((m_bounding_rect.width()/4) - (m_hdr_no_ctc.width()/2), 0);
|
||||
painter.drawPicture (p, m_hdr_no_ctc);
|
||||
p.setX((m_bounding_rect.width() * 3/4) - (m_hdr_nc_ctc.width()/2));
|
||||
painter.drawPicture (p, m_hdr_nc_ctc);
|
||||
|
||||
//and fill it
|
||||
//and fill it
|
||||
fillCrossRef(painter);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,10 +50,10 @@ class CrossRefItem : public QGraphicsObject
|
||||
//Methods
|
||||
public:
|
||||
explicit CrossRefItem(Element *elmt);
|
||||
explicit CrossRefItem(Element *elmt,
|
||||
DynamicElementTextItem *text);
|
||||
explicit CrossRefItem(Element *elmt,
|
||||
ElementTextItemGroup *group);
|
||||
explicit CrossRefItem(
|
||||
Element *elmt, DynamicElementTextItem *text);
|
||||
explicit CrossRefItem(
|
||||
Element *elmt, ElementTextItemGroup *group);
|
||||
~CrossRefItem() override;
|
||||
private:
|
||||
void init();
|
||||
|
||||
@@ -49,7 +49,8 @@ DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem *paren
|
||||
@brief DiagramImageItem::~DiagramImageItem
|
||||
Destructor
|
||||
*/
|
||||
DiagramImageItem::~DiagramImageItem() {
|
||||
DiagramImageItem::~DiagramImageItem()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +107,8 @@ void DiagramImageItem::setPixmap(const QPixmap &pixmap) {
|
||||
if no pixmap are set, return a default QRectF
|
||||
@return a QRectF represent the bounding rectangle
|
||||
*/
|
||||
QRectF DiagramImageItem::boundingRect() const {
|
||||
QRectF DiagramImageItem::boundingRect() const
|
||||
{
|
||||
if (!pixmap_.isNull()) {
|
||||
return (QRectF(pixmap_.rect()));
|
||||
} else {
|
||||
@@ -119,7 +121,8 @@ QRectF DiagramImageItem::boundingRect() const {
|
||||
@brief DiagramImageItem::name
|
||||
@return the generic name of this item (picture)
|
||||
*/
|
||||
QString DiagramImageItem::name() const {
|
||||
QString DiagramImageItem::name() const
|
||||
{
|
||||
return tr("une image");
|
||||
}
|
||||
|
||||
@@ -163,7 +166,8 @@ bool DiagramImageItem::fromXml(const QDomElement &e)
|
||||
@param document Le document XML a utiliser
|
||||
@return L'element XML representant l'image
|
||||
*/
|
||||
QDomElement DiagramImageItem::toXml(QDomDocument &document) const {
|
||||
QDomElement DiagramImageItem::toXml(QDomDocument &document) const
|
||||
{
|
||||
QDomElement result = document.createElement("image");
|
||||
//write some attribute
|
||||
result.setAttribute("x", QString::number(pos().x()));
|
||||
|
||||
@@ -60,7 +60,8 @@ void DiagramTextItem::build()
|
||||
@brief DiagramTextItem::diagram
|
||||
@return The diagram of this item or 0 if this text isn't in a diagram
|
||||
*/
|
||||
Diagram *DiagramTextItem::diagram() const {
|
||||
Diagram *DiagramTextItem::diagram() const
|
||||
{
|
||||
return(qobject_cast<Diagram *>(scene()));
|
||||
}
|
||||
|
||||
@@ -70,7 +71,8 @@ Diagram *DiagramTextItem::diagram() const {
|
||||
This is used to be inherited by child class
|
||||
@return
|
||||
*/
|
||||
QDomElement DiagramTextItem::toXml(QDomDocument &) const {
|
||||
QDomElement DiagramTextItem::toXml(QDomDocument &) const
|
||||
{
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
@@ -80,7 +82,8 @@ QDomElement DiagramTextItem::toXml(QDomDocument &) const {
|
||||
@param movement Vecteur exprime en coordonnees locales
|
||||
@return le meme vecteur, exprime en coordonnees de la scene
|
||||
*/
|
||||
QPointF DiagramTextItem::mapMovementToScene(const QPointF &movement) const {
|
||||
QPointF DiagramTextItem::mapMovementToScene(const QPointF &movement) const
|
||||
{
|
||||
// on definit deux points en coordonnees locales
|
||||
QPointF local_origin(0.0, 0.0);
|
||||
QPointF local_movement_point(movement);
|
||||
@@ -99,7 +102,8 @@ QPointF DiagramTextItem::mapMovementToScene(const QPointF &movement) const {
|
||||
@param movement Vecteur exprime en coordonnees de la scene
|
||||
@return le meme vecteur, exprime en coordonnees locales
|
||||
*/
|
||||
QPointF DiagramTextItem::mapMovementFromScene(const QPointF &movement) const {
|
||||
QPointF DiagramTextItem::mapMovementFromScene(const QPointF &movement) const
|
||||
{
|
||||
// on definit deux points sur la scene
|
||||
QPointF scene_origin(0.0, 0.0);
|
||||
QPointF scene_movement_point(movement);
|
||||
@@ -118,7 +122,8 @@ QPointF DiagramTextItem::mapMovementFromScene(const QPointF &movement) const {
|
||||
@param movement Vecteur exprime en coordonnees locales
|
||||
@return le meme vecteur, exprime en coordonnees du parent
|
||||
*/
|
||||
QPointF DiagramTextItem::mapMovementToParent(const QPointF &movement) const {
|
||||
QPointF DiagramTextItem::mapMovementToParent(const QPointF &movement) const
|
||||
{
|
||||
// on definit deux points en coordonnees locales
|
||||
QPointF local_origin(0.0, 0.0);
|
||||
QPointF local_movement_point(movement);
|
||||
@@ -137,7 +142,8 @@ QPointF DiagramTextItem::mapMovementToParent(const QPointF &movement) const {
|
||||
@param movement Vecteur exprime en coordonnees du parent
|
||||
@return le meme vecteur, exprime en coordonnees locales
|
||||
*/
|
||||
QPointF DiagramTextItem::mapMovementFromParent(const QPointF &movement) const {
|
||||
QPointF DiagramTextItem::mapMovementFromParent(const QPointF &movement) const
|
||||
{
|
||||
// on definit deux points sur le parent
|
||||
QPointF parent_origin(0.0, 0.0);
|
||||
QPointF parent_movement_point(movement);
|
||||
@@ -170,7 +176,8 @@ void DiagramTextItem::setColor(const QColor& color)
|
||||
emit colorChanged(color);
|
||||
}
|
||||
|
||||
QColor DiagramTextItem::color() const {
|
||||
QColor DiagramTextItem::color() const
|
||||
{
|
||||
return defaultTextColor();
|
||||
}
|
||||
|
||||
@@ -221,7 +228,8 @@ void DiagramTextItem::setPlainText(const QString &text)
|
||||
m_is_html = false;
|
||||
}
|
||||
|
||||
bool DiagramTextItem::isHtml() const {
|
||||
bool DiagramTextItem::isHtml() const
|
||||
{
|
||||
return m_is_html;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,8 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
||||
Note that the text can return a parent element,
|
||||
even if the text belong to a group of this same element.
|
||||
*/
|
||||
Element *DynamicElementTextItem::parentElement() const {
|
||||
Element *DynamicElementTextItem::parentElement() const
|
||||
{
|
||||
return m_parent_element;
|
||||
}
|
||||
|
||||
@@ -312,7 +313,8 @@ void DynamicElementTextItem::refreshLabelConnection()
|
||||
@brief DynamicElementTextItem::textFrom
|
||||
@return what the final text is created from.
|
||||
*/
|
||||
DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const {
|
||||
DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const
|
||||
{
|
||||
return m_text_from;
|
||||
}
|
||||
|
||||
@@ -375,7 +377,8 @@ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_f
|
||||
@brief DynamicElementTextItem::text
|
||||
@return the text of this text
|
||||
*/
|
||||
QString DynamicElementTextItem::text() const {
|
||||
QString DynamicElementTextItem::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
@@ -442,7 +445,8 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
|
||||
@brief DynamicElementTextItem::infoName
|
||||
@return the info name of this text
|
||||
*/
|
||||
QString DynamicElementTextItem::infoName() const {
|
||||
QString DynamicElementTextItem::infoName() const
|
||||
{
|
||||
return m_info_name;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,10 @@ class ElementXmlRetroCompatibility
|
||||
{
|
||||
friend class Element;
|
||||
|
||||
static void loadSequential(const QDomElement &dom_element,
|
||||
const QString& seq,
|
||||
QStringList* list)
|
||||
static void loadSequential(
|
||||
const QDomElement &dom_element,
|
||||
const QString& seq,
|
||||
QStringList* list)
|
||||
{
|
||||
int i = 0;
|
||||
while (!dom_element.attribute(seq +
|
||||
@@ -53,8 +54,8 @@ class ElementXmlRetroCompatibility
|
||||
}
|
||||
}
|
||||
|
||||
static void loadSequential(const QDomElement &dom_element,
|
||||
Element *element)
|
||||
static void loadSequential(
|
||||
const QDomElement &dom_element, Element *element)
|
||||
{
|
||||
autonum::sequentialNumbers sn;
|
||||
|
||||
@@ -76,10 +77,11 @@ class ElementXmlRetroCompatibility
|
||||
@param state : state of the instanciation
|
||||
@param link_type
|
||||
*/
|
||||
Element::Element(const ElementsLocation &location,
|
||||
QGraphicsItem *parent,
|
||||
int *state,
|
||||
kind link_type) :
|
||||
Element::Element(
|
||||
const ElementsLocation &location,
|
||||
QGraphicsItem *parent,
|
||||
int *state,
|
||||
kind link_type) :
|
||||
QetGraphicsItem(parent),
|
||||
m_link_type (link_type),
|
||||
m_location (location)
|
||||
@@ -111,7 +113,8 @@ Element::Element(const ElementsLocation &location,
|
||||
| QGraphicsItem::ItemIsSelectable);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
connect(this, &Element::rotationChanged, [this]() {
|
||||
connect(this, &Element::rotationChanged, [this]()
|
||||
{
|
||||
for(QGraphicsItem *qgi : childItems())
|
||||
{
|
||||
if (Terminal *t = qgraphicsitem_cast<Terminal *>(qgi))
|
||||
@@ -133,7 +136,8 @@ Element::~Element()
|
||||
@brief Element::terminals
|
||||
@return the list of terminals of this element.
|
||||
*/
|
||||
QList<Terminal *> Element::terminals() const {
|
||||
QList<Terminal *> Element::terminals() const
|
||||
{
|
||||
return m_terminals;
|
||||
}
|
||||
|
||||
@@ -175,7 +179,8 @@ void Element::editProperty()
|
||||
/**
|
||||
@param hl true pour mettre l'element en evidence, false sinon
|
||||
*/
|
||||
void Element::setHighlighted(bool hl) {
|
||||
void Element::setHighlighted(bool hl)
|
||||
{
|
||||
m_must_highlight = hl;
|
||||
update();
|
||||
}
|
||||
@@ -196,9 +201,10 @@ void Element::displayHelpLine(bool b)
|
||||
@param painter
|
||||
@param options
|
||||
*/
|
||||
void Element::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *)
|
||||
void Element::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *)
|
||||
{
|
||||
if (m_must_highlight) {
|
||||
drawHighlight(painter, options);
|
||||
@@ -219,7 +225,8 @@ void Element::paint(QPainter *painter,
|
||||
/**
|
||||
@return Le rectangle delimitant le contour de l'element
|
||||
*/
|
||||
QRectF Element::boundingRect() const {
|
||||
QRectF Element::boundingRect() const
|
||||
{
|
||||
return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()),
|
||||
dimensions));
|
||||
}
|
||||
@@ -244,7 +251,8 @@ void Element::setSize(int wid, int hei)
|
||||
/**
|
||||
@return la taille de l'element sur le schema
|
||||
*/
|
||||
QSize Element::size() const {
|
||||
QSize Element::size() const
|
||||
{
|
||||
return(dimensions);
|
||||
}
|
||||
|
||||
@@ -253,7 +261,8 @@ QSize Element::size() const {
|
||||
Necessite que la taille ait deja ete definie
|
||||
@param hs Coordonnees du hotspot
|
||||
*/
|
||||
QPoint Element::setHotspot(QPoint hs) {
|
||||
QPoint Element::setHotspot(QPoint hs)
|
||||
{
|
||||
// la taille doit avoir ete definie
|
||||
prepareGeometryChange();
|
||||
if (dimensions.isNull()) hotspot_coord = QPoint(0, 0);
|
||||
@@ -269,7 +278,8 @@ QPoint Element::setHotspot(QPoint hs) {
|
||||
/**
|
||||
@return Le hotspot courant de l'element
|
||||
*/
|
||||
QPoint Element::hotspot() const {
|
||||
QPoint Element::hotspot() const
|
||||
{
|
||||
return(hotspot_coord);
|
||||
}
|
||||
|
||||
@@ -277,7 +287,8 @@ QPoint Element::hotspot() const {
|
||||
@brief Element::pixmap
|
||||
@return the pixmap of this element
|
||||
*/
|
||||
QPixmap Element::pixmap() {
|
||||
QPixmap Element::pixmap()
|
||||
{
|
||||
return ElementPictureFactory::instance()->pixmap(m_location);
|
||||
}
|
||||
|
||||
@@ -288,8 +299,10 @@ QPixmap Element::pixmap() {
|
||||
@param painter Le QPainter a utiliser pour dessiner les axes
|
||||
@param options Les options de style a prendre en compte
|
||||
*/
|
||||
void Element::drawAxes(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options) {
|
||||
void Element::drawAxes(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options)
|
||||
{
|
||||
Q_UNUSED(options);
|
||||
painter -> setPen(Qt::blue);
|
||||
painter -> drawLine(0, 0, 10, 0);
|
||||
@@ -308,8 +321,10 @@ void Element::drawAxes(QPainter *painter,
|
||||
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
||||
@param options Les options de style a prendre en compte
|
||||
*/
|
||||
void Element::drawSelection(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options) {
|
||||
void Element::drawSelection(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options)
|
||||
{
|
||||
Q_UNUSED(options);
|
||||
painter -> save();
|
||||
// Annulation des renderhints
|
||||
@@ -334,8 +349,10 @@ void Element::drawSelection(QPainter *painter,
|
||||
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
||||
@param options Les options de style a prendre en compte
|
||||
*/
|
||||
void Element::drawHighlight(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options) {
|
||||
void Element::drawHighlight(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options)
|
||||
{
|
||||
Q_UNUSED(options);
|
||||
painter -> save();
|
||||
|
||||
@@ -618,14 +635,13 @@ DynamicElementTextItem *Element::parseDynamicText(
|
||||
*/
|
||||
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
||||
{
|
||||
TerminalData* data = new TerminalData();
|
||||
if (!data->fromXml(dom_element)) {
|
||||
delete data;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TerminalData* data = new TerminalData();
|
||||
if (!data->fromXml(dom_element)) {
|
||||
delete data;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Terminal *new_terminal = new Terminal(data, this);
|
||||
Terminal *new_terminal = new Terminal(data, this);
|
||||
m_terminals << new_terminal;
|
||||
|
||||
//Sort from top to bottom and left to rigth
|
||||
@@ -681,10 +697,11 @@ bool Element::valideXml(QDomElement &e) {
|
||||
@param handle_inputs_rotation : apply the rotation of this element to his child text
|
||||
@return
|
||||
*/
|
||||
bool Element::fromXml(QDomElement &e,
|
||||
QHash<int,
|
||||
Terminal *> &table_id_adr,
|
||||
bool handle_inputs_rotation)
|
||||
bool Element::fromXml(
|
||||
QDomElement &e,
|
||||
QHash<int,
|
||||
Terminal *> &table_id_adr,
|
||||
bool handle_inputs_rotation)
|
||||
{
|
||||
m_state = QET::GILoadingFromXml;
|
||||
/*
|
||||
@@ -792,7 +809,7 @@ bool Element::fromXml(QDomElement &e,
|
||||
for(DynamicElementTextItem *deti : m_dynamic_text_list)
|
||||
delete deti;
|
||||
m_dynamic_text_list.clear();
|
||||
|
||||
|
||||
//************************//
|
||||
//***Dynamic texts item***//
|
||||
//************************//
|
||||
@@ -800,12 +817,11 @@ bool Element::fromXml(QDomElement &e,
|
||||
e,
|
||||
"dynamic_texts",
|
||||
DynamicElementTextItem::xmlTagName()))
|
||||
{
|
||||
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
||||
addDynamicTextItem(deti);
|
||||
deti->fromXml(qde);
|
||||
}
|
||||
|
||||
{
|
||||
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
||||
addDynamicTextItem(deti);
|
||||
deti->fromXml(qde);
|
||||
}
|
||||
|
||||
//************************//
|
||||
//***Element texts item***//
|
||||
@@ -822,9 +838,11 @@ bool Element::fromXml(QDomElement &e,
|
||||
{
|
||||
for(const QDomElement& dom_input : dom_inputs)
|
||||
{
|
||||
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
|
||||
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
|
||||
//that mean this is the good text
|
||||
//we use the same method used in ElementTextItem::fromXml
|
||||
//to compar and know if the input dom element is for one of the text stored.
|
||||
//The comparaison is made from the text position :
|
||||
//if the position of the text is the same as the position stored in 'input' dom element
|
||||
//that mean this is the good text
|
||||
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()),
|
||||
m_converted_text_from_xml_description.value(deti).x()) &&
|
||||
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()),
|
||||
@@ -851,9 +869,13 @@ bool Element::fromXml(QDomElement &e,
|
||||
if(dom_input.hasAttribute("usery"))
|
||||
xml_pos.setY(dom_input.attribute("usery", "0").toDouble());
|
||||
|
||||
//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
|
||||
//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
|
||||
//We need to use a QTransform to find the pos of this text from the saved pos of text item
|
||||
//the origin transformation point of PartDynamicTextField
|
||||
//is the top left corner, no matter the font size
|
||||
//The origin transformation point of PartTextField
|
||||
//is the middle of left edge, and so by definition,
|
||||
//change with the size of the font
|
||||
//We need to use a QTransform to find the pos of
|
||||
//this text from the saved pos of text item
|
||||
|
||||
deti->setPos(xml_pos);
|
||||
deti->setRotation(rotation);
|
||||
@@ -869,9 +891,11 @@ bool Element::fromXml(QDomElement &e,
|
||||
transform.translate(xml_pos.x(), xml_pos.y());
|
||||
deti->setPos(transform.map(pos));
|
||||
|
||||
//dom_input and deti matched we remove the dom_input from inputs list,
|
||||
//to avoid unnecessary checking made below
|
||||
//we also move deti from the m_converted_text_from_xml_description to m_dynamic_text_list
|
||||
//dom_input and deti matched we remove
|
||||
//the dom_input from inputs list,
|
||||
//to avoid unnecessary checking made below
|
||||
//we also move deti from the
|
||||
//m_converted_text_from_xml_description to m_dynamic_text_list
|
||||
inputs.removeAll(dom_input);
|
||||
m_dynamic_text_list.append(deti);
|
||||
m_converted_text_from_xml_description.remove(deti);
|
||||
@@ -880,14 +904,14 @@ bool Element::fromXml(QDomElement &e,
|
||||
}
|
||||
}
|
||||
|
||||
//###Firts case : if this is the first time the user open the project since text item are converted to dynamic text,
|
||||
//in the previous opening of the project, every texts field present in the element description was created.
|
||||
//At save time, the values of each of them was save in the 'input' dom element.
|
||||
//The loop upper is made for the first case, to import the values in 'input' to the new converted dynamic texts field.
|
||||
//###Second case : this is not the first time the user open the project since text item are converted to dynamic text.
|
||||
//That mean, in a previous opening of the project, the text item was already converted and save as a dynamic text field.
|
||||
//So there isn't 'input' dom element in the project, and every dynamic text item present in m_converted_text_from_xml_description
|
||||
//need to be deleted (because already exist in m_dynamic_text_list, from a previous save)
|
||||
//###Firts case : if this is the first time the user open the project since text item are converted to dynamic text,
|
||||
//in the previous opening of the project, every texts field present in the element description was created.
|
||||
//At save time, the values of each of them was save in the 'input' dom element.
|
||||
//The loop upper is made for the first case, to import the values in 'input' to the new converted dynamic texts field.
|
||||
//###Second case : this is not the first time the user open the project since text item are converted to dynamic text.
|
||||
//That mean, in a previous opening of the project, the text item was already converted and save as a dynamic text field.
|
||||
//So there isn't 'input' dom element in the project, and every dynamic text item present in m_converted_text_from_xml_description
|
||||
//need to be deleted (because already exist in m_dynamic_text_list, from a previous save)
|
||||
for (DynamicElementTextItem *deti : m_converted_text_from_xml_description.keys())
|
||||
delete deti;
|
||||
m_converted_text_from_xml_description.clear();
|
||||
@@ -1127,9 +1151,10 @@ bool Element::fromXml(QDomElement &e,
|
||||
\~ @return The XML element representing this electrical element
|
||||
\~French L'element XML representant cet element electrique
|
||||
*/
|
||||
QDomElement Element::toXml(QDomDocument &document,
|
||||
QHash<Terminal *,
|
||||
int> &table_adr_id) const
|
||||
QDomElement Element::toXml(
|
||||
QDomDocument &document,
|
||||
QHash<Terminal *,
|
||||
int> &table_adr_id) const
|
||||
{
|
||||
QDomElement element = document.createElement("element");
|
||||
|
||||
@@ -1199,7 +1224,7 @@ QDomElement Element::toXml(QDomDocument &document,
|
||||
element.appendChild(links_uuids);
|
||||
}
|
||||
|
||||
//save information of this element
|
||||
//save information of this element
|
||||
if (! m_element_informations.keys().isEmpty()) {
|
||||
QDomElement infos =
|
||||
document.createElement("elementInformations");
|
||||
@@ -1207,7 +1232,7 @@ QDomElement Element::toXml(QDomDocument &document,
|
||||
element.appendChild(infos);
|
||||
}
|
||||
|
||||
//Dynamic texts
|
||||
//Dynamic texts
|
||||
QDomElement dyn_text = document.createElement("dynamic_texts");
|
||||
for (DynamicElementTextItem *deti : m_dynamic_text_list)
|
||||
dyn_text.appendChild(deti->toXml(document));
|
||||
@@ -1313,7 +1338,8 @@ void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
||||
Texts in text-groups belonging to this element are not returned by this function.
|
||||
@see ElementTextItemGroup::texts
|
||||
*/
|
||||
QList<DynamicElementTextItem *> Element::dynamicTextItems() const {
|
||||
QList<DynamicElementTextItem *> Element::dynamicTextItems() const
|
||||
{
|
||||
return m_dynamic_text_list;
|
||||
}
|
||||
|
||||
@@ -1514,7 +1540,7 @@ void Element::initLink(QETProject *prj)
|
||||
foreach (Element *elmt, ep.fromUuids(tmp_uuids_link)) {
|
||||
elmt->linkToElement(this);
|
||||
}
|
||||
tmp_uuids_link.clear();
|
||||
tmp_uuids_link.clear();
|
||||
}
|
||||
|
||||
QString Element::linkTypeToString() const
|
||||
@@ -1546,9 +1572,9 @@ QString Element::linkTypeToString() const
|
||||
*/
|
||||
void Element::setElementInformations(DiagramContext dc)
|
||||
{
|
||||
if (m_element_informations == dc) {
|
||||
return;
|
||||
}
|
||||
if (m_element_informations == dc) {
|
||||
return;
|
||||
}
|
||||
|
||||
DiagramContext old_info = m_element_informations;
|
||||
m_element_informations = dc;
|
||||
@@ -1563,7 +1589,8 @@ void Element::setElementInformations(DiagramContext dc)
|
||||
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) {
|
||||
bool comparPos(const Element *elmt1, const Element *elmt2)
|
||||
{
|
||||
//Compare folio first
|
||||
if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex())
|
||||
return elmt1->diagram()->folioIndex()
|
||||
@@ -1616,7 +1643,8 @@ void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
Also highlight linked elements
|
||||
@param e QGraphicsSceneHoverEvent
|
||||
*/
|
||||
void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
|
||||
void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
foreach (Element *elmt, linkedElements())
|
||||
@@ -1633,7 +1661,8 @@ void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
|
||||
Also un-highlight linked elements
|
||||
@param e QGraphicsSceneHoverEvent
|
||||
*/
|
||||
void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
||||
void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
foreach (Element *elmt, linkedElements())
|
||||
@@ -1696,7 +1725,8 @@ void Element::setUpFormula(bool code_letter)
|
||||
@brief Element::getPrefix
|
||||
get Element Prefix
|
||||
*/
|
||||
QString Element::getPrefix() const{
|
||||
QString Element::getPrefix() const
|
||||
{
|
||||
return m_prefix;
|
||||
}
|
||||
|
||||
@@ -1704,7 +1734,8 @@ QString Element::getPrefix() const{
|
||||
@brief Element::setPrefix
|
||||
set Element Prefix
|
||||
*/
|
||||
void Element::setPrefix(QString prefix) {
|
||||
void Element::setPrefix(QString prefix)
|
||||
{
|
||||
m_prefix = std::move(prefix);
|
||||
}
|
||||
|
||||
@@ -1721,7 +1752,8 @@ void Element::freezeLabel(bool freeze)
|
||||
@brief Element::freezeNewAddedElement
|
||||
Freeze this label if needed
|
||||
*/
|
||||
void Element::freezeNewAddedElement() {
|
||||
void Element::freezeNewAddedElement()
|
||||
{
|
||||
if (this->diagram()->freezeNewElements()
|
||||
|| this->diagram()->project()->isFreezeNewElements()) {
|
||||
freezeLabel(true);
|
||||
@@ -1753,10 +1785,12 @@ QString Element::actualLabel()
|
||||
@brief Element::name
|
||||
@return the human name of this element
|
||||
*/
|
||||
QString Element::name() const {
|
||||
QString Element::name() const
|
||||
{
|
||||
return m_names.name(m_location.baseName());
|
||||
}
|
||||
|
||||
ElementsLocation Element::location() const {
|
||||
ElementsLocation Element::location() const
|
||||
{
|
||||
return m_location;
|
||||
}
|
||||
|
||||
@@ -48,13 +48,14 @@ class Element : public QetGraphicsItem
|
||||
Used to know the kind of this element
|
||||
(master, slave, report ect...)
|
||||
*/
|
||||
enum kind {Simple = 1,
|
||||
NextReport = 2,
|
||||
PreviousReport = 4,
|
||||
AllReport = 6,
|
||||
Master = 8,
|
||||
Slave = 16,
|
||||
Terminale = 32};
|
||||
enum kind {
|
||||
Simple = 1,
|
||||
NextReport = 2,
|
||||
PreviousReport = 4,
|
||||
AllReport = 6,
|
||||
Master = 8,
|
||||
Slave = 16,
|
||||
Terminale = 32};
|
||||
|
||||
Element(const ElementsLocation &location,
|
||||
QGraphicsItem * = nullptr,
|
||||
@@ -76,16 +77,19 @@ class Element : public QetGraphicsItem
|
||||
|
||||
signals:
|
||||
void linkedElementChanged(); //This signal is emited when the linked elements with this element change
|
||||
void elementInfoChange(DiagramContext old_info,
|
||||
DiagramContext new_info);
|
||||
void elementInfoChange(
|
||||
DiagramContext old_info,
|
||||
DiagramContext new_info);
|
||||
void textAdded(DynamicElementTextItem *deti);
|
||||
void textRemoved(DynamicElementTextItem *deti);
|
||||
void textsGroupAdded(ElementTextItemGroup *group);
|
||||
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group);
|
||||
void textAddedToGroup(DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
void textRemovedFromGroup(DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
void textAddedToGroup(
|
||||
DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
void textRemovedFromGroup(
|
||||
DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
|
||||
|
||||
public:
|
||||
@@ -125,13 +129,15 @@ class Element : public QetGraphicsItem
|
||||
QPoint hotspot() const;
|
||||
void editProperty() override;
|
||||
static bool valideXml(QDomElement &);
|
||||
virtual bool fromXml(QDomElement &,
|
||||
QHash<int,
|
||||
Terminal *> &,
|
||||
bool = false);
|
||||
virtual QDomElement toXml(QDomDocument &,
|
||||
QHash<Terminal *,
|
||||
int> &) const;
|
||||
virtual bool fromXml(
|
||||
QDomElement &,
|
||||
QHash<int,
|
||||
Terminal *> &,
|
||||
bool = false);
|
||||
virtual QDomElement toXml(
|
||||
QDomDocument &,
|
||||
QHash<Terminal *,
|
||||
int> &) const;
|
||||
QUuid uuid() const;
|
||||
int orientation() const;
|
||||
|
||||
@@ -144,10 +150,12 @@ class Element : public QetGraphicsItem
|
||||
void removeTextGroup(ElementTextItemGroup *group);
|
||||
ElementTextItemGroup *textGroup(const QString &name) const;
|
||||
QList<ElementTextItemGroup *> textGroups() const;
|
||||
bool addTextToGroup(DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
bool removeTextFromGroup(DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
bool addTextToGroup(
|
||||
DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
bool removeTextFromGroup(
|
||||
DynamicElementTextItem *text,
|
||||
ElementTextItemGroup *group);
|
||||
|
||||
//METHODS related to linked element
|
||||
bool isFree() const;
|
||||
@@ -165,10 +173,12 @@ class Element : public QetGraphicsItem
|
||||
void setSize(int, int);
|
||||
|
||||
private:
|
||||
void drawSelection(QPainter *,
|
||||
const QStyleOptionGraphicsItem *);
|
||||
void drawHighlight(QPainter *,
|
||||
const QStyleOptionGraphicsItem *);
|
||||
void drawSelection(
|
||||
QPainter *,
|
||||
const QStyleOptionGraphicsItem *);
|
||||
void drawHighlight(
|
||||
QPainter *,
|
||||
const QStyleOptionGraphicsItem *);
|
||||
bool buildFromXml(const QDomElement &, int * = nullptr);
|
||||
bool parseElement(const QDomElement &dom);
|
||||
bool parseInput(const QDomElement &dom_element);
|
||||
@@ -178,9 +188,10 @@ class Element : public QetGraphicsItem
|
||||
|
||||
//Reimplemented from QGraphicsItem
|
||||
public:
|
||||
void paint(QPainter *,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
void paint(
|
||||
QPainter *,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
QRectF boundingRect() const override;
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
@@ -190,9 +201,15 @@ class Element : public QetGraphicsItem
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
|
||||
protected:
|
||||
// m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml)
|
||||
// are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item
|
||||
// and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml
|
||||
// m_converted_text_from_description,
|
||||
// when a element is created from his description,
|
||||
// the old element text item (tagged as 'input' in the xml)
|
||||
// are converted to dynamic text field,
|
||||
// the QPointF is the original position of the text item,
|
||||
// because the origin transformation point of text item
|
||||
// and dynamic text item are not the same,
|
||||
// so we must to keep a track of this value,
|
||||
// to be use in the function element::fromXml
|
||||
QHash <DynamicElementTextItem *, QPointF>
|
||||
m_converted_text_from_xml_description;
|
||||
|
||||
@@ -227,7 +244,8 @@ class Element : public QetGraphicsItem
|
||||
|
||||
bool comparPos(const Element * elmt1, const Element * elmt2);
|
||||
|
||||
inline bool Element::isFree() const {
|
||||
inline bool Element::isFree() const
|
||||
{
|
||||
return (connected_elements.isEmpty());
|
||||
}
|
||||
|
||||
@@ -239,7 +257,8 @@ inline bool Element::isFree() const {
|
||||
3 = 270°
|
||||
@return the current orientation of this element
|
||||
*/
|
||||
inline int Element::orientation() const {
|
||||
inline int Element::orientation() const
|
||||
{
|
||||
return(QET::correctAngle(rotation())/90);
|
||||
}
|
||||
|
||||
@@ -247,18 +266,19 @@ inline int Element::orientation() const {
|
||||
@brief Element::uuid
|
||||
@return the uuid of this element
|
||||
*/
|
||||
inline QUuid Element::uuid() const {
|
||||
return m_uuid;
|
||||
}
|
||||
inline QUuid Element::uuid() const
|
||||
{return m_uuid;}
|
||||
|
||||
/**
|
||||
@brief Element::linkedElements
|
||||
@return the list of linked elements, the list is sorted by position
|
||||
*/
|
||||
inline QList <Element *> Element::linkedElements() {
|
||||
std::sort(connected_elements.begin(),
|
||||
connected_elements.end(),
|
||||
comparPos);
|
||||
inline QList <Element *> Element::linkedElements()
|
||||
{
|
||||
std::sort(
|
||||
connected_elements.begin(),
|
||||
connected_elements.end(),
|
||||
comparPos);
|
||||
return connected_elements;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,16 +79,25 @@ void ElementTextItemGroup::addToGroup(QGraphicsItem *item)
|
||||
updateAlignment();
|
||||
|
||||
DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item);
|
||||
connect(deti, &DynamicElementTextItem::fontChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::plainTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textWidthChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::fontChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textFromChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::infoNameChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::compositeTextChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::plainTextChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
connect(deti, &DynamicElementTextItem::textWidthChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
|
||||
connect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateXref);
|
||||
connect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateXref);
|
||||
connect(deti, &DynamicElementTextItem::textFromChanged,
|
||||
this, &ElementTextItemGroup::updateXref);
|
||||
connect(deti, &DynamicElementTextItem::infoNameChanged,
|
||||
this, &ElementTextItemGroup::updateXref);
|
||||
|
||||
updateXref();
|
||||
}
|
||||
@@ -101,8 +110,11 @@ void ElementTextItemGroup::addToGroup(QGraphicsItem *item)
|
||||
void ElementTextItemGroup::removeFromGroup(QGraphicsItem *item)
|
||||
{
|
||||
QGraphicsItemGroup::removeFromGroup(item);
|
||||
//the item transformation is not reseted, we must to do it, because for exemple if the group rotation is 45°
|
||||
//When item is removed from group, visually the item is unchanged (so 45°) but if we call item->rotation() the returned value is 0.
|
||||
//the item transformation is not reseted, we must to do it,
|
||||
// because for exemple if the group rotation is 45°
|
||||
//When item is removed from group,
|
||||
// visually the item is unchanged (so 45°)
|
||||
// but if we call item->rotation() the returned value is 0.
|
||||
item->resetTransform();
|
||||
item->setRotation(this->rotation());
|
||||
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
@@ -110,16 +122,25 @@ void ElementTextItemGroup::removeFromGroup(QGraphicsItem *item)
|
||||
|
||||
if(DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(item))
|
||||
{
|
||||
disconnect(deti, &DynamicElementTextItem::fontChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::compositeTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::plainTextChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textWidthChanged, this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::fontChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textFromChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::infoNameChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::compositeTextChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::plainTextChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
disconnect(deti, &DynamicElementTextItem::textWidthChanged,
|
||||
this, &ElementTextItemGroup::updateAlignment);
|
||||
|
||||
disconnect(deti, &DynamicElementTextItem::textFromChanged, this, &ElementTextItemGroup::updateXref);
|
||||
disconnect(deti, &DynamicElementTextItem::infoNameChanged, this, &ElementTextItemGroup::updateXref);
|
||||
disconnect(deti, &DynamicElementTextItem::textFromChanged,
|
||||
this, &ElementTextItemGroup::updateXref);
|
||||
disconnect(deti, &DynamicElementTextItem::infoNameChanged,
|
||||
this, &ElementTextItemGroup::updateXref);
|
||||
|
||||
updateXref();
|
||||
}
|
||||
@@ -285,13 +306,28 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
|
||||
connect(m_parent_element, &Element::rotationChanged, this, &ElementTextItemGroup::autoPos);
|
||||
if(m_parent_element->linkType() == Element::Master)
|
||||
{
|
||||
//We use timer to let the time of the parent element xref to be updated, befor update the position of this group
|
||||
//because the position of this group is related to the size of the parent element Xref
|
||||
m_linked_changed_timer = connect(m_parent_element, &Element::linkedElementChanged,
|
||||
[this]() {QTimer::singleShot(200, this, &ElementTextItemGroup::autoPos);});
|
||||
//We use timer to let the time of the parent element
|
||||
// xref to be updated,
|
||||
// befor update the position of this group
|
||||
//because the position of this group is related
|
||||
// to the size of the parent element Xref
|
||||
m_linked_changed_timer = connect(
|
||||
m_parent_element,
|
||||
&Element::linkedElementChanged,
|
||||
[this]()
|
||||
{QTimer::singleShot(200,
|
||||
this,
|
||||
&ElementTextItemGroup::autoPos);}
|
||||
);
|
||||
if(m_parent_element->diagram())
|
||||
m_XrefChanged_timer = connect(m_parent_element->diagram()->project(), &QETProject::XRefPropertiesChanged,
|
||||
[this]() {QTimer::singleShot(200, this, &ElementTextItemGroup::autoPos);});
|
||||
m_XrefChanged_timer = connect(
|
||||
m_parent_element->diagram()->project(),
|
||||
&QETProject::XRefPropertiesChanged,
|
||||
[this]()
|
||||
{QTimer::singleShot(200,
|
||||
this,
|
||||
&ElementTextItemGroup::autoPos);}
|
||||
);
|
||||
}
|
||||
autoPos();
|
||||
}
|
||||
@@ -299,8 +335,10 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
disconnect(m_parent_element, &Element::yChanged, this, &ElementTextItemGroup::autoPos);
|
||||
disconnect(m_parent_element, &Element::rotationChanged, this, &ElementTextItemGroup::autoPos);
|
||||
disconnect(m_parent_element, &Element::yChanged,
|
||||
this, &ElementTextItemGroup::autoPos);
|
||||
disconnect(m_parent_element, &Element::rotationChanged,
|
||||
this, &ElementTextItemGroup::autoPos);
|
||||
if(m_parent_element->linkType() == Element::Master)
|
||||
{
|
||||
disconnect(m_linked_changed_timer);
|
||||
@@ -319,7 +357,8 @@ void ElementTextItemGroup::setFrame(const bool frame)
|
||||
emit frameChanged(m_frame);
|
||||
}
|
||||
|
||||
bool ElementTextItemGroup::frame() const {
|
||||
bool ElementTextItemGroup::frame() const
|
||||
{
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
@@ -383,7 +422,8 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
|
||||
dom_element.setAttribute("vertical_adjustment", m_vertical_adjustment);
|
||||
dom_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
|
||||
dom_element.setAttribute("hold_to_bottom_page", m_hold_to_bottom_of_page == true ? "true" : "false");
|
||||
dom_element.setAttribute("hold_to_bottom_page",
|
||||
m_hold_to_bottom_of_page == true ? "true" : "false");
|
||||
|
||||
QDomElement dom_texts = dom_document.createElement("texts");
|
||||
for(DynamicElementTextItem *deti : texts())
|
||||
@@ -411,8 +451,17 @@ void ElementTextItemGroup::fromXml(QDomElement &dom_element)
|
||||
|
||||
setName(dom_element.attribute("name", "no name"));
|
||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
setAlignment(Qt::Alignment(me.keyToValue(dom_element.attribute("alignment").toStdString().data())));
|
||||
|
||||
setAlignment(
|
||||
Qt::Alignment(
|
||||
me.keyToValue(
|
||||
dom_element.attribute(
|
||||
"alignment")
|
||||
.toStdString()
|
||||
.data()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
setPos(dom_element.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(0)).toDouble());
|
||||
|
||||
@@ -448,7 +497,10 @@ void ElementTextItemGroup::fromXml(QDomElement &dom_element)
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void ElementTextItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void ElementTextItemGroup::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
@@ -460,7 +512,8 @@ void ElementTextItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
t.setStyle(Qt::DashDotLine);
|
||||
t.setCosmetic(true);
|
||||
painter->setPen(t);
|
||||
painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
|
||||
painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1),
|
||||
10, 10);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
@@ -502,15 +555,16 @@ void ElementTextItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
*/
|
||||
QRectF ElementTextItemGroup::boundingRect() const
|
||||
{
|
||||
//If we refer to the Qt doc, the bounding rect of a QGraphicsItemGroup,
|
||||
//is the bounding of all childrens in the group
|
||||
//When add an item in the group, the bounding rect is good, but
|
||||
//if we move an item already in the group, the bounding rect of the group stay unchanged.
|
||||
//We reimplement this function to avoid this behavior.
|
||||
//If we refer to the Qt doc, the bounding rect of a QGraphicsItemGroup,
|
||||
//is the bounding of all childrens in the group
|
||||
//When add an item in the group, the bounding rect is good, but
|
||||
//if we move an item already in the group, the bounding rect of the group stay unchanged.
|
||||
//We reimplement this function to avoid this behavior.
|
||||
QRectF rect;
|
||||
for(QGraphicsItem *qgi : texts())
|
||||
{
|
||||
QRectF r(qgi->pos(), QSize(qgi->boundingRect().width(), qgi->boundingRect().height()));
|
||||
QRectF r(qgi->pos(), QSize(qgi->boundingRect().width(),
|
||||
qgi->boundingRect().height()));
|
||||
rect = rect.united(r);
|
||||
}
|
||||
return rect;
|
||||
@@ -567,7 +621,8 @@ void ElementTextItemGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
|
||||
{
|
||||
if(diagram() && m_first_move)
|
||||
diagram()->elementTextsMover().beginMovement(diagram(), this);
|
||||
diagram()->elementTextsMover().beginMovement(diagram(),
|
||||
this);
|
||||
|
||||
if(m_first_move)
|
||||
{
|
||||
@@ -611,7 +666,8 @@ void ElementTextItemGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
QGraphicsItemGroup::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void ElementTextItemGroup::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
void ElementTextItemGroup::mouseDoubleClickEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(m_slave_Xref_item)
|
||||
{
|
||||
|
||||
@@ -46,7 +46,8 @@ IndependentTextItem::IndependentTextItem(const QString &text) :
|
||||
{}
|
||||
|
||||
/// Destructeur
|
||||
IndependentTextItem::~IndependentTextItem() {
|
||||
IndependentTextItem::~IndependentTextItem()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
@param qgi : parent QGraphicItem
|
||||
@param state : int used to know if the creation of element have error
|
||||
*/
|
||||
MasterElement::MasterElement(const ElementsLocation &location,
|
||||
QGraphicsItem *qgi,
|
||||
int *state) :
|
||||
MasterElement::MasterElement(
|
||||
const ElementsLocation &location,
|
||||
QGraphicsItem *qgi,
|
||||
int *state) :
|
||||
Element(location, qgi, state, Element::Master)
|
||||
{}
|
||||
|
||||
@@ -38,7 +39,8 @@ MasterElement::MasterElement(const ElementsLocation &location,
|
||||
@brief MasterElement::~MasterElement
|
||||
default destructor
|
||||
*/
|
||||
MasterElement::~MasterElement() {
|
||||
MasterElement::~MasterElement()
|
||||
{
|
||||
unlinkAllElements();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,12 @@ class CrossRefItem;
|
||||
class MasterElement : public Element
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
explicit MasterElement(const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
|
||||
explicit MasterElement(
|
||||
const ElementsLocation &,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
~MasterElement() override;
|
||||
|
||||
void linkToElement (Element *elmt) override;
|
||||
@@ -43,7 +46,9 @@ class MasterElement : public Element
|
||||
QRectF XrefBoundingRect() const;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
QVariant itemChange(
|
||||
GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
|
||||
private:
|
||||
void xrefPropertiesChanged();
|
||||
|
||||
@@ -67,7 +67,8 @@ void QetGraphicsItem::setPos(qreal x, qreal y) {
|
||||
@brief QetGraphicsItem::state
|
||||
@return the current state of this item
|
||||
*/
|
||||
QET::GraphicsItemState QetGraphicsItem::state() const {
|
||||
QET::GraphicsItemState QetGraphicsItem::state() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,24 +28,26 @@ class QetGraphicsItem : public QGraphicsObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//constructor destructor
|
||||
//constructor destructor
|
||||
QetGraphicsItem(QGraphicsItem *parent = nullptr);
|
||||
~QetGraphicsItem() override = 0;
|
||||
|
||||
//public methode
|
||||
Diagram *diagram () const;
|
||||
virtual void setPos (const QPointF &p);
|
||||
virtual void setPos (qreal x, qreal y);
|
||||
//public methode
|
||||
Diagram *diagram () const;
|
||||
virtual void setPos (const QPointF &p);
|
||||
virtual void setPos (qreal x, qreal y);
|
||||
|
||||
virtual bool isMovable () const {return is_movable_;}
|
||||
virtual bool isMovable () const
|
||||
{return is_movable_;}
|
||||
virtual void setMovable (bool movable) { is_movable_ = movable;}
|
||||
|
||||
virtual void editProperty () {}
|
||||
virtual QString name ()const {return QString("");}
|
||||
virtual void editProperty () {}
|
||||
virtual QString name ()const
|
||||
{return QString("");}
|
||||
|
||||
QET::GraphicsItemState state() const;
|
||||
|
||||
//protected method
|
||||
//protected method
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
@@ -203,7 +203,8 @@ void QetShapeItem::setYRadius(qreal Y)
|
||||
@brief QetShapeItem::pointCount
|
||||
@return the number of point in the polygon
|
||||
*/
|
||||
int QetShapeItem::pointsCount() const {
|
||||
int QetShapeItem::pointsCount() const
|
||||
{
|
||||
return m_polygon.size();
|
||||
}
|
||||
|
||||
@@ -246,7 +247,8 @@ void QetShapeItem::removePoints(int number)
|
||||
@brief QetShapeItem::boundingRect
|
||||
@return the bounding rect of this item
|
||||
*/
|
||||
QRectF QetShapeItem::boundingRect() const {
|
||||
QRectF QetShapeItem::boundingRect() const
|
||||
{
|
||||
return shape().boundingRect().adjusted(-6, -6, 6, 6);
|
||||
}
|
||||
|
||||
@@ -265,9 +267,10 @@ QPainterPath QetShapeItem::shape() const
|
||||
path.lineTo(m_P2);
|
||||
break;
|
||||
case Rectangle:
|
||||
path.addRoundedRect(QRectF(m_P1, m_P2),
|
||||
m_xRadius,
|
||||
m_yRadius);
|
||||
path.addRoundedRect(
|
||||
QRectF(m_P1, m_P2),
|
||||
m_xRadius,
|
||||
m_yRadius);
|
||||
break;
|
||||
case Ellipse:
|
||||
path.addEllipse(QRectF(m_P1, m_P2));
|
||||
@@ -319,19 +322,19 @@ void QetShapeItem::paint(
|
||||
painter -> drawPath (shape());
|
||||
painter -> restore ();
|
||||
}
|
||||
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Line: painter->drawLine(QLineF(m_P1, m_P2)); break;
|
||||
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case Line: painter->drawLine(QLineF(m_P1, m_P2)); break;
|
||||
case Rectangle: painter->drawRoundedRect(QRectF(m_P1, m_P2),
|
||||
m_xRadius,
|
||||
m_yRadius); break;
|
||||
case Ellipse: painter->drawEllipse(QRectF(m_P1, m_P2)); break;
|
||||
case Ellipse: painter->drawEllipse(QRectF(m_P1, m_P2)); break;
|
||||
case Polygon: m_closed ? painter->drawPolygon(m_polygon)
|
||||
: painter->drawPolyline(m_polygon); break;
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1005,7 +1008,8 @@ void QetShapeItem::editProperty()
|
||||
@brief QetShapeItem::name
|
||||
@return the name of the curent shape.
|
||||
*/
|
||||
QString QetShapeItem::name() const {
|
||||
QString QetShapeItem::name() const
|
||||
{
|
||||
switch (m_shapeType) {
|
||||
case Line: return tr("une ligne");
|
||||
case Rectangle: return tr("un rectangle");
|
||||
|
||||
@@ -62,7 +62,11 @@ class QetShapeItem : public QetGraphicsItem
|
||||
|
||||
enum { Type = UserType + 1008 };
|
||||
|
||||
QetShapeItem(QPointF, QPointF = QPointF(0,0), ShapeType = Line, QGraphicsItem *parent = nullptr);
|
||||
QetShapeItem(
|
||||
QPointF,
|
||||
QPointF = QPointF(0,0),
|
||||
ShapeType = Line,
|
||||
QGraphicsItem *parent = nullptr);
|
||||
~QetShapeItem() override;
|
||||
|
||||
//Enable the use of qgraphicsitem_cast to safely cast a
|
||||
@@ -106,13 +110,21 @@ class QetShapeItem : public QetGraphicsItem
|
||||
QPainterPath shape() const override;
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override;
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(
|
||||
GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
bool sceneEventFilter(
|
||||
QGraphicsItem *watched,
|
||||
QEvent *event) override;
|
||||
void contextMenuEvent(
|
||||
QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
void switchResizeMode();
|
||||
@@ -129,24 +141,24 @@ class QetShapeItem : public QetGraphicsItem
|
||||
private:
|
||||
ShapeType m_shapeType;
|
||||
QPen m_pen;
|
||||
QBrush m_brush;
|
||||
QBrush m_brush;
|
||||
QPointF m_P1,
|
||||
m_P2,
|
||||
m_old_P1,
|
||||
m_old_P2,
|
||||
m_context_menu_pos;
|
||||
m_P2,
|
||||
m_old_P1,
|
||||
m_old_P2,
|
||||
m_context_menu_pos;
|
||||
QPolygonF m_polygon, m_old_polygon;
|
||||
bool m_hovered;
|
||||
int m_vector_index;
|
||||
bool m_closed = false,
|
||||
m_modifie_radius_equaly = false;
|
||||
int m_resize_mode = 1;
|
||||
int m_vector_index;
|
||||
bool m_closed = false,
|
||||
m_modifie_radius_equaly = false;
|
||||
int m_resize_mode = 1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
QAction *m_insert_point,
|
||||
*m_remove_point;
|
||||
qreal m_xRadius = 0,
|
||||
m_yRadius = 0,
|
||||
m_old_xRadius,
|
||||
m_old_yRadius;
|
||||
QAction *m_insert_point,
|
||||
*m_remove_point;
|
||||
qreal m_xRadius = 0,
|
||||
m_yRadius = 0,
|
||||
m_old_xRadius,
|
||||
m_old_yRadius;
|
||||
};
|
||||
#endif // QETSHAPEITEM_H
|
||||
|
||||
@@ -30,14 +30,18 @@ class ReportElement : public Element
|
||||
Q_OBJECT
|
||||
|
||||
public :
|
||||
explicit ReportElement(const ElementsLocation &,const QString& link_type, QGraphicsItem * = nullptr, int * = nullptr);
|
||||
explicit ReportElement(
|
||||
const ElementsLocation &,
|
||||
const QString& link_type,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
~ReportElement() override;
|
||||
void linkToElement(Element *) override;
|
||||
void unlinkAllElements() override;
|
||||
void unlinkElement(Element *elmt) override;
|
||||
|
||||
private:
|
||||
int m_inverse_report;
|
||||
int m_inverse_report;
|
||||
};
|
||||
|
||||
#endif // REPORTELEMENT_H
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
@param qgi
|
||||
@param state
|
||||
*/
|
||||
SimpleElement::SimpleElement(const ElementsLocation &location,
|
||||
QGraphicsItem *qgi,
|
||||
int *state) :
|
||||
SimpleElement::SimpleElement(
|
||||
const ElementsLocation &location,
|
||||
QGraphicsItem *qgi,
|
||||
int *state) :
|
||||
Element(location, qgi, state, Element::Simple)
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief SimpleElement::~SimpleElement
|
||||
*/
|
||||
SimpleElement::~SimpleElement() {}
|
||||
SimpleElement::~SimpleElement()
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief SimpleElement::initLink
|
||||
|
||||
@@ -31,9 +31,10 @@ class SimpleElement : public Element {
|
||||
Q_OBJECT
|
||||
|
||||
public :
|
||||
explicit SimpleElement(const ElementsLocation &,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
explicit SimpleElement(
|
||||
const ElementsLocation &,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
~SimpleElement() override;
|
||||
|
||||
void initLink(QETProject *project) override;
|
||||
|
||||
@@ -40,7 +40,8 @@ SlaveElement::SlaveElement(const ElementsLocation &location,
|
||||
@brief SlaveElement::~SlaveElement
|
||||
default destructor
|
||||
*/
|
||||
SlaveElement::~SlaveElement() {
|
||||
SlaveElement::~SlaveElement()
|
||||
{
|
||||
unlinkAllElements();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ class SlaveElement : public Element
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SlaveElement (const ElementsLocation &,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
explicit SlaveElement (
|
||||
const ElementsLocation &,
|
||||
QGraphicsItem * = nullptr,
|
||||
int * = nullptr);
|
||||
~SlaveElement() override;
|
||||
void linkToElement(Element *elmt) override;
|
||||
void unlinkAllElements() override;
|
||||
|
||||
@@ -40,12 +40,11 @@ const qreal Terminal::Z = 1000;
|
||||
@param name of terminal
|
||||
@param hiddenName
|
||||
*/
|
||||
void Terminal::init(QString number,
|
||||
QString name,
|
||||
bool hiddenName) {
|
||||
|
||||
void Terminal::init(
|
||||
QString number, QString name, bool hiddenName)
|
||||
{
|
||||
hovered_color_ = Terminal::neutralColor;
|
||||
|
||||
|
||||
// calcul de la position du point d'amarrage a l'element
|
||||
dock_elmt_ = d->m_pos;
|
||||
switch(d->m_orientation) {
|
||||
@@ -61,7 +60,7 @@ void Terminal::init(QString number,
|
||||
name_terminal_ = std::move(name);
|
||||
name_terminal_hidden = hiddenName;
|
||||
// par defaut : pas de conducteur
|
||||
|
||||
|
||||
// QRectF null
|
||||
br_ = new QRectF();
|
||||
previous_terminal_ = nullptr;
|
||||
@@ -82,7 +81,12 @@ void Terminal::init(QString number,
|
||||
\param name
|
||||
\param hiddenName
|
||||
*/
|
||||
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName)
|
||||
void Terminal::init(
|
||||
QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString number,
|
||||
QString name,
|
||||
bool hiddenName)
|
||||
{
|
||||
// definition du pount d'amarrage pour un conducteur
|
||||
d->m_pos = pf;
|
||||
@@ -132,12 +136,13 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
||||
@param hiddenName hide or show the name
|
||||
@param e Element auquel cette borne appartient
|
||||
*/
|
||||
Terminal::Terminal(QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString num,
|
||||
QString name,
|
||||
bool hiddenName,
|
||||
Element *e) :
|
||||
Terminal::Terminal(
|
||||
QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString num,
|
||||
QString name,
|
||||
bool hiddenName,
|
||||
Element *e) :
|
||||
QGraphicsObject (e),
|
||||
d(new TerminalData(this)),
|
||||
parent_element_ (e)
|
||||
@@ -160,7 +165,8 @@ Terminal::Terminal(TerminalData* data, Element* e) :
|
||||
La destruction de la borne entraine la destruction des conducteurs
|
||||
associes.
|
||||
*/
|
||||
Terminal::~Terminal() {
|
||||
Terminal::~Terminal()
|
||||
{
|
||||
foreach(Conductor *c, conductors_) delete c;
|
||||
delete br_;
|
||||
}
|
||||
@@ -172,7 +178,8 @@ Terminal::~Terminal() {
|
||||
pivote. Sinon elle renvoie son sens normal.
|
||||
@return L'orientation actuelle de la Terminal.
|
||||
*/
|
||||
Qet::Orientation Terminal::orientation() const {
|
||||
Qet::Orientation Terminal::orientation() const
|
||||
{
|
||||
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
||||
// orientations actuelle et par defaut de l'element
|
||||
int ori_cur = elt -> orientation();
|
||||
@@ -192,7 +199,8 @@ Qet::Orientation Terminal::orientation() const {
|
||||
@brief Terminal::setNumber
|
||||
@param number
|
||||
*/
|
||||
void Terminal::setNumber(QString number) {
|
||||
void Terminal::setNumber(QString number)
|
||||
{
|
||||
number_terminal_ = std::move(number);
|
||||
}
|
||||
|
||||
@@ -201,7 +209,8 @@ void Terminal::setNumber(QString number) {
|
||||
@param name : QString
|
||||
@param hiddenName : bool
|
||||
*/
|
||||
void Terminal::setName(QString name, bool hiddenName) {
|
||||
void Terminal::setName(QString name, bool hiddenName)
|
||||
{
|
||||
name_terminal_ = std::move(name);
|
||||
name_terminal_hidden = hiddenName;
|
||||
}
|
||||
@@ -215,13 +224,16 @@ void Terminal::setName(QString name, bool hiddenName) {
|
||||
bool Terminal::addConductor(Conductor *conductor)
|
||||
{
|
||||
if (!conductor) return(false);
|
||||
|
||||
Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)),
|
||||
"Terminal::addConductor",
|
||||
"The conductor must be linked exactly once to this terminal");
|
||||
|
||||
//Get the other terminal where the conductor must be linked
|
||||
Terminal *other_terminal = (conductor -> terminal1 == this)
|
||||
? conductor->terminal2 : conductor->terminal1;
|
||||
|
||||
Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)), "Terminal::addConductor", "The conductor must be linked exactly once to this terminal");
|
||||
|
||||
//Get the other terminal where the conductor must be linked
|
||||
Terminal *other_terminal = (conductor -> terminal1 == this) ? conductor->terminal2 : conductor->terminal1;
|
||||
|
||||
//Check if this terminal isn't already linked with other_terminal
|
||||
//Check if this terminal isn't already linked with other_terminal
|
||||
foreach (Conductor* cond, conductors_)
|
||||
if (cond -> terminal1 == other_terminal || cond -> terminal2 == other_terminal)
|
||||
return false; //They already a conductor linked to this and other_terminal
|
||||
@@ -250,35 +262,37 @@ void Terminal::removeConductor(Conductor *conductor)
|
||||
@param p Le QPainter a utiliser
|
||||
@param options Les options de dessin
|
||||
*/
|
||||
void Terminal::paint(QPainter *p,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *) {
|
||||
void Terminal::paint(
|
||||
QPainter *p,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *)
|
||||
{
|
||||
// en dessous d'un certain zoom, les bornes ne sont plus dessinees
|
||||
if (options && options -> levelOfDetail < 0.5) return;
|
||||
|
||||
|
||||
p -> save();
|
||||
|
||||
//annulation des renderhints
|
||||
p -> setRenderHint(QPainter::Antialiasing, false);
|
||||
p -> setRenderHint(QPainter::TextAntialiasing, false);
|
||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
|
||||
// on travaille avec les coordonnees de l'element parent
|
||||
QPointF c = mapFromParent(d->m_pos);
|
||||
QPointF e = mapFromParent(dock_elmt_);
|
||||
|
||||
|
||||
QPen t;
|
||||
t.setWidthF(1.0);
|
||||
|
||||
|
||||
if (options && options -> levelOfDetail < 1.0) {
|
||||
t.setCosmetic(true);
|
||||
}
|
||||
|
||||
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(Qt::red);
|
||||
p -> setPen(t);
|
||||
p -> drawLine(c, e);
|
||||
|
||||
|
||||
// dessin du point d'amarrage au conducteur en bleu
|
||||
t.setColor(hovered_color_);
|
||||
p -> setPen(t);
|
||||
@@ -288,11 +302,11 @@ void Terminal::paint(QPainter *p,
|
||||
p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
|
||||
} else p -> drawPoint(c);
|
||||
|
||||
//Draw help line if needed,
|
||||
//Draw help line if needed,
|
||||
if (diagram() && m_draw_help_line)
|
||||
{
|
||||
//Draw the help line with same orientation of terminal
|
||||
//Only if there isn't docked conductor
|
||||
//Draw the help line with same orientation of terminal
|
||||
//Only if there isn't docked conductor
|
||||
if (conductors().isEmpty())
|
||||
{
|
||||
if (!m_help_line)
|
||||
@@ -312,14 +326,14 @@ void Terminal::paint(QPainter *p,
|
||||
}
|
||||
}
|
||||
|
||||
//Map the line (in scene coordinate) to m_help_line coordinate
|
||||
//Map the line (in scene coordinate) to m_help_line coordinate
|
||||
line.setP1(m_help_line -> mapFromScene(line.p1()));
|
||||
line.setP2(m_help_line -> mapFromScene(line.p2()));
|
||||
m_help_line -> setPen(pen);
|
||||
m_help_line -> setLine(line);
|
||||
}
|
||||
|
||||
//Draw the help line perpendicular to the terminal
|
||||
//Draw the help line perpendicular to the terminal
|
||||
if (!m_help_line_a)
|
||||
{
|
||||
m_help_line_a = new QGraphicsLineItem(this);
|
||||
@@ -415,7 +429,8 @@ QLineF Terminal::HelpLine() const
|
||||
@brief Terminal::boundingRect
|
||||
@return Le rectangle (en precision flottante) delimitant la borne et ses alentours.
|
||||
*/
|
||||
QRectF Terminal::boundingRect() const {
|
||||
QRectF Terminal::boundingRect() const
|
||||
{
|
||||
if (br_ -> isNull())
|
||||
{
|
||||
qreal dcx = d->m_pos.x();
|
||||
@@ -497,7 +512,8 @@ Terminal* Terminal::alignedWithTerminal() const
|
||||
@brief Terminal::hoverEnterEvent
|
||||
Gere l'entree de la souris sur la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
|
||||
void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *)
|
||||
{
|
||||
hovered_ = true;
|
||||
update();
|
||||
}
|
||||
@@ -506,14 +522,14 @@ void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
|
||||
@brief Terminal::hoverMoveEvent
|
||||
Gere les mouvements de la souris sur la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverMoveEvent(QGraphicsSceneHoverEvent *) {
|
||||
}
|
||||
void Terminal::hoverMoveEvent(QGraphicsSceneHoverEvent *) {}
|
||||
|
||||
/**
|
||||
@brief Terminal::hoverLeaveEvent
|
||||
Gere le fait que la souris sorte de la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
|
||||
{
|
||||
hovered_ = false;
|
||||
update();
|
||||
}
|
||||
@@ -523,7 +539,8 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
Gere le fait qu'on enfonce un bouton de la souris sur la Borne.
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
if (Diagram *diag = diagram()) {
|
||||
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
|
||||
diag -> setConductorStop(e -> scenePos());
|
||||
@@ -537,10 +554,11 @@ void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
Gere le fait qu'on bouge la souris sur la Borne.
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
// pendant la pose d'un conducteur, on adopte un autre curseur
|
||||
//setCursor(Qt::CrossCursor);
|
||||
|
||||
|
||||
// d'un mouvement a l'autre, il faut retirer l'effet hover de la borne precedente
|
||||
if (previous_terminal_) {
|
||||
if (previous_terminal_ == this) hovered_ = true;
|
||||
@@ -583,7 +601,7 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
} else {
|
||||
other_terminal -> hovered_color_ = allowedColor;
|
||||
}
|
||||
|
||||
|
||||
other_terminal -> hovered_ = true;
|
||||
other_terminal -> update();
|
||||
}
|
||||
@@ -667,7 +685,8 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
||||
@brief Terminal::updateConductor
|
||||
Update the path of conductor docked to this terminal
|
||||
*/
|
||||
void Terminal::updateConductor() {
|
||||
void Terminal::updateConductor()
|
||||
{
|
||||
foreach (Conductor *conductor, conductors_)
|
||||
conductor->updatePath();
|
||||
}
|
||||
@@ -712,7 +731,8 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
|
||||
@brief Terminal::conductors
|
||||
@return La liste des conducteurs lies a cette borne
|
||||
*/
|
||||
QList<Conductor *> Terminal::conductors() const {
|
||||
QList<Conductor *> Terminal::conductors() const
|
||||
{
|
||||
return(conductors_);
|
||||
}
|
||||
|
||||
@@ -722,7 +742,8 @@ QList<Conductor *> Terminal::conductors() const {
|
||||
@param doc Le Document XML a utiliser pour creer l'element XML
|
||||
@return un QDomElement representant cette borne
|
||||
*/
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const
|
||||
{
|
||||
QDomElement qdo = doc.createElement("terminal");
|
||||
|
||||
// for backward compatibility
|
||||
@@ -743,7 +764,8 @@ QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
@param terminal Le QDomElement a analyser
|
||||
@return true si le QDomElement passe en parametre est une borne, false sinon
|
||||
*/
|
||||
bool Terminal::valideXml(QDomElement &terminal) {
|
||||
bool Terminal::valideXml(QDomElement &terminal)
|
||||
{
|
||||
// verifie le nom du tag
|
||||
if (terminal.tagName() != "terminal") return(false);
|
||||
|
||||
@@ -785,7 +807,8 @@ bool Terminal::valideXml(QDomElement &terminal) {
|
||||
@return true si la borne "se reconnait"
|
||||
(memes coordonnes, meme orientation), false sinon
|
||||
*/
|
||||
bool Terminal::fromXml(QDomElement &terminal) {
|
||||
bool Terminal::fromXml(QDomElement &terminal)
|
||||
{
|
||||
number_terminal_ = terminal.attribute("number");
|
||||
name_terminal_ = terminal.attribute("name");
|
||||
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
||||
@@ -802,7 +825,8 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
||||
@return the position, relative to the scene, of the docking point for
|
||||
conductors.
|
||||
*/
|
||||
QPointF Terminal::dockConductor() const {
|
||||
QPointF Terminal::dockConductor() const
|
||||
{
|
||||
return(mapToScene(d->m_pos));
|
||||
}
|
||||
|
||||
@@ -811,7 +835,8 @@ QPointF Terminal::dockConductor() const {
|
||||
@return le Diagram auquel cette borne appartient,
|
||||
ou 0 si cette borne est independant
|
||||
*/
|
||||
Diagram *Terminal::diagram() const {
|
||||
Diagram *Terminal::diagram() const
|
||||
{
|
||||
return(qobject_cast<Diagram *>(scene()));
|
||||
}
|
||||
|
||||
@@ -819,11 +844,13 @@ Diagram *Terminal::diagram() const {
|
||||
@brief Terminal::parentElement
|
||||
@return L'element auquel cette borne est rattachee
|
||||
*/
|
||||
Element *Terminal::parentElement() const {
|
||||
Element *Terminal::parentElement() const
|
||||
{
|
||||
return(parent_element_);
|
||||
}
|
||||
|
||||
QUuid Terminal::uuid() const {
|
||||
QUuid Terminal::uuid() const
|
||||
{
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
@@ -838,9 +865,10 @@ QUuid Terminal::uuid() const {
|
||||
false return only terminal in the same diagram of t
|
||||
@return the list of terminal at the same potential
|
||||
*/
|
||||
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram)
|
||||
QList<Terminal *> relatedPotentialTerminal (
|
||||
const Terminal *terminal, const bool all_diagram)
|
||||
{
|
||||
// If terminal parent element is a folio report.
|
||||
// If terminal parent element is a folio report.
|
||||
if (all_diagram && terminal -> parentElement() -> linkType() & Element::AllReport)
|
||||
{
|
||||
QList <Element *> elmt_list = terminal -> parentElement() -> linkedElements();
|
||||
@@ -849,7 +877,7 @@ QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool
|
||||
return (elmt_list.first()->terminals());
|
||||
}
|
||||
}
|
||||
// If terminal parent element is a Terminal element.
|
||||
// If terminal parent element is a Terminal element.
|
||||
else if (terminal -> parentElement() -> linkType() & Element::Terminale)
|
||||
{
|
||||
QList <Terminal *> terminals = terminal->parentElement()->terminals();
|
||||
|
||||
@@ -159,7 +159,8 @@ class Terminal : public QGraphicsObject
|
||||
@brief Terminal::conductorsCount
|
||||
@return the number of conductors attached to the terminal.
|
||||
*/
|
||||
inline int Terminal::conductorsCount() const {
|
||||
inline int Terminal::conductorsCount() const
|
||||
{
|
||||
return(conductors_.size());
|
||||
}
|
||||
|
||||
@@ -167,7 +168,8 @@ inline int Terminal::conductorsCount() const {
|
||||
@brief Terminal::number
|
||||
@return the number of terminal.
|
||||
*/
|
||||
inline QString Terminal::number() const {
|
||||
inline QString Terminal::number() const
|
||||
{
|
||||
return(number_terminal_);
|
||||
}
|
||||
|
||||
@@ -175,7 +177,8 @@ inline QString Terminal::number() const {
|
||||
@brief Terminal::name
|
||||
@return the name of terminal.
|
||||
*/
|
||||
inline QString Terminal::name() const {
|
||||
inline QString Terminal::name() const
|
||||
{
|
||||
return(name_terminal_);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ TerminalElement::TerminalElement(const ElementsLocation &location,
|
||||
Element(location, qgi, state, Element::Terminale)
|
||||
{}
|
||||
|
||||
TerminalElement::~TerminalElement() {}
|
||||
TerminalElement::~TerminalElement()
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief TerminalElement::initLink
|
||||
|
||||
Reference in New Issue
Block a user