TerminalStripLayoutPattern is now shared

TerminalStripLayoutPattern class is now a shared pointer between all
terminal strip item.
QETProject have now a new class : ProjectPropertiesHandler
the goal of this class is to manage every kind of properties used in the
project, this class will be strongly used in future.
This commit is contained in:
joshua
2023-01-04 22:40:18 +01:00
parent c6739b5bec
commit 4da7f6cd13
13 changed files with 278 additions and 52 deletions

View File

@@ -28,8 +28,10 @@
* @param strip
* @param pattern
*/
TerminalStripDrawer::TerminalStripDrawer(QPointer<TerminalStrip> strip) :
m_strip(strip)
TerminalStripDrawer::TerminalStripDrawer(QPointer<TerminalStrip> strip,
QSharedPointer<TerminalStripLayoutPattern> layout) :
m_strip(strip),
m_pattern(layout)
{}
void TerminalStripDrawer::setStrip(TerminalStrip *strip)
@@ -43,7 +45,7 @@ void TerminalStripDrawer::setStrip(TerminalStrip *strip)
*/
void TerminalStripDrawer::paint(QPainter *painter)
{
if (m_strip)
if (m_strip && m_pattern)
{
//To draw text, QPainter need a Qrect. Instead of create an instance
//for each text, we re-use the same instance of QRect.
@@ -61,42 +63,42 @@ void TerminalStripDrawer::paint(QPainter *painter)
painter->setBrush(brush_);
//Draw header
painter->drawRect(m_pattern.m_header_rect);
painter->drawRect(m_pattern->m_header_rect);
//Draw the header text
painter->save();
if (m_pattern.m_header_text_orientation == Qt::Horizontal)
if (m_pattern->m_header_text_orientation == Qt::Horizontal)
{
text_rect.setRect(0,m_pattern.m_header_rect.y(),m_pattern.m_header_rect.width(),m_pattern.m_header_rect.height());
text_rect.setRect(0,m_pattern->m_header_rect.y(),m_pattern->m_header_rect.width(),m_pattern->m_header_rect.height());
}
else
{
painter->translate(m_pattern.m_header_rect.bottomLeft());
painter->translate(m_pattern->m_header_rect.bottomLeft());
painter->rotate(270);
text_rect.setRect(0,0,m_pattern.m_header_rect.height(),m_pattern.m_header_rect.width());
text_rect.setRect(0,0,m_pattern->m_header_rect.height(),m_pattern->m_header_rect.width());
}
const auto text_{m_strip->installation() + " " + m_strip->location() + " " + m_strip->name()};
painter->drawText(text_rect, text_, m_pattern.headerTextOption());
painter->drawText(text_rect, text_, m_pattern->headerTextOption());
painter->restore();
//Move painter pos to next drawing
painter->translate(m_pattern.m_header_rect.width(),0);
painter->translate(m_pattern->m_header_rect.width(),0);
int x_offset{m_pattern.m_header_rect.width()};
int x_offset{m_pattern->m_header_rect.width()};
//Draw spacer
painter->drawRect(m_pattern.m_spacer_rect);
painter->drawRect(m_pattern->m_spacer_rect);
//Move painter pos to next drawing
painter->translate(m_pattern.m_spacer_rect.width(),0);
x_offset += m_pattern.m_spacer_rect.width();
painter->translate(m_pattern->m_spacer_rect.width(),0);
x_offset += m_pattern->m_spacer_rect.width();
//Draw terminals
const auto terminals_text_rect{m_pattern.m_terminals_text_rect};
const auto terminals_text_orientation{m_pattern.m_terminals_text_orientation};
const auto terminals_text_option{m_pattern.terminalsTextOption()};
const auto terminals_text_rect{m_pattern->m_terminals_text_rect};
const auto terminals_text_orientation{m_pattern->m_terminals_text_orientation};
const auto terminals_text_option{m_pattern->terminalsTextOption()};
QRect terminal_rect;
QHash<QUuid, QVector<QPointF>> bridges_anchor_points;
@@ -117,7 +119,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
break;
}
terminal_rect = m_pattern.m_terminal_rect[index_];
terminal_rect = m_pattern->m_terminal_rect[index_];
//Draw terminal rect
painter->drawRect(terminal_rect);
@@ -148,8 +150,8 @@ void TerminalStripDrawer::paint(QPainter *painter)
if (const auto bridge_ = shared_real_terminal->bridge())
{
const auto x_anchor{terminal_rect.width()/2};
const auto y_anchor {m_pattern.m_bridge_point_y_offset[index_]};
const auto radius_anchor{m_pattern.m_bridge_point_d/2};
const auto y_anchor {m_pattern->m_bridge_point_y_offset[index_]};
const auto radius_anchor{m_pattern->m_bridge_point_d/2};
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(QPointF(x_anchor, y_anchor),
@@ -188,45 +190,65 @@ QRectF TerminalStripDrawer::boundingRect() const
return QRect{0, 0, width(), height()};;
}
void TerminalStripDrawer::setLayout(QSharedPointer<TerminalStripLayoutPattern> layout)
{
m_pattern = layout;
}
bool TerminalStripDrawer::haveLayout() const
{
return !m_pattern.isNull();
}
int TerminalStripDrawer::height() const
{
auto height_{m_pattern.m_header_rect.y() + m_pattern.m_header_rect.height()};
if (m_pattern)
{
auto height_{m_pattern->m_header_rect.y() + m_pattern->m_header_rect.height()};
height_ = std::max(height_, m_pattern.m_spacer_rect.y() + m_pattern.m_spacer_rect.height());
height_ = std::max(height_, m_pattern->m_spacer_rect.y() + m_pattern->m_spacer_rect.height());
for (const auto &rect : m_pattern.m_terminal_rect) {
height_ = std::max(height_, rect.y() + rect.height());
for (const auto &rect : m_pattern->m_terminal_rect) {
height_ = std::max(height_, rect.y() + rect.height());
}
return height_;
}
return height_;
return 0;
}
int TerminalStripDrawer::width() const
{
int width_{m_pattern.m_header_rect.width() + m_pattern.m_spacer_rect.width()};
if (m_strip)
if (m_pattern)
{
//Loop over physical terminals
for (const auto &physical_t : m_strip->physicalTerminal())
int width_{m_pattern->m_header_rect.width() + m_pattern->m_spacer_rect.width()};
if (m_strip)
{
//Get the good offset according to how many level have the current physical terminal
const QVector<QSharedPointer<RealTerminal>> real_terminal{physical_t->realTerminals()};
const auto real_t_count{real_terminal.size()};
const auto offset_{4 - real_t_count};
//Loop over real terminals
for (auto i=0 ; i<real_t_count ; ++i)
//Loop over physical terminals
for (const auto &physical_t : m_strip->physicalTerminal())
{
const auto index_ = offset_ + i;
if (index_ >= 4) {
break;
}
//Get the good offset according to how many level have the current physical terminal
const QVector<QSharedPointer<RealTerminal>> real_terminal{physical_t->realTerminals()};
const auto real_t_count{real_terminal.size()};
const auto offset_{4 - real_t_count};
width_ += m_pattern.m_terminal_rect[index_].width();
//Loop over real terminals
for (auto i=0 ; i<real_t_count ; ++i)
{
const auto index_ = offset_ + i;
if (index_ >= 4) {
break;
}
width_ += m_pattern->m_terminal_rect[index_].width();
}
}
}
return width_;
}
return width_;
return 0;
}