@@ -39,10 +39,9 @@ QPen QConstraintBase::s_defaultPenRed = QPen();
3939QPen QConstraintBase::s_penSelected = QPen();
4040
4141
42-
4342QConstraintBase::QConstraintBase ()
4443{
45- qDebug () << Q_FUNC_INFO;
44+ // qDebug() << Q_FUNC_INFO;
4645 setVisible ( s_show);
4746
4847 m_pen_req = s_defaultPenReq;
@@ -57,6 +56,23 @@ QConstraintBase::QConstraintBase()
5756 setFlag ( ItemSendsGeometryChanges, false );
5857}
5958
59+ QConstraintBase::QConstraintBase ( const QConstraintBase & other)
60+ {
61+ // qDebug() << Q_FUNC_INFO << m_sc;
62+ setVisible ( s_show);
63+
64+ setFlag ( ItemIsSelectable, true );
65+ setFlag ( ItemIsMovable, false );
66+ setFlag ( ItemSendsGeometryChanges, false );
67+
68+ m_altColor = other.m_altColor ;
69+ m_pen_req = other.m_pen_req ;
70+ m_pen_red = other.m_pen_red ;
71+
72+ m_is_required = other.m_is_required ;
73+ m_is_enforced = other.m_is_enforced ;
74+ }
75+
6076void QConstraintBase::mousePressEvent ( QGraphicsSceneMouseEvent * event )
6177{
6278 if ( event->button () == Qt::RightButton ) {
@@ -76,7 +92,6 @@ void QConstraintBase::serialize( QDataStream &out )
7692 out << m_pen_red;
7793 out << m_altColor;
7894
79- // out << m_markerSize;
8095 out << markerSize ();
8196 out << pos ();
8297 out << rotation ();
@@ -106,18 +121,21 @@ bool QConstraintBase::deserialize( QDataStream &in )
106121 return true ;
107122}
108123
109- void QConstraintBase::setColor ( const QColor & col) {
124+ void QConstraintBase::setColor ( const QColor & col)
125+ {
110126 m_pen_req.setColor (col);
111127 m_pen_red.setColor (col);
112128}
113129
114- void QConstraintBase::setLineWidth ( const int w) {
130+ void QConstraintBase::setLineWidth ( const int w)
131+ {
115132 m_pen_req.setWidth (w);
116133 m_pen_red.setWidth (w);
117134}
118135
119136
120- void QConstraintBase::setLineStyle ( const int s) {
137+ void QConstraintBase::setLineStyle ( const int s)
138+ {
121139 m_pen_req.setStyle ( Qt::PenStyle (s) );
122140 m_pen_red.setStyle ( Qt::PenStyle (s) );
123141}
@@ -137,7 +155,6 @@ void QOrthogonal::paint( QPainter *painter,
137155 const QStyleOptionGraphicsItem * option,
138156 QWidget * widget)
139157{
140-
141158 QPen pen = QPen ( m_is_required ? m_pen_req : m_pen_red);
142159 if ( !enforced () ) {
143160 pen.setColor ( Qt::cyan );
@@ -147,11 +164,10 @@ void QOrthogonal::paint( QPainter *painter,
147164 pen.setColor ( m_altColor);
148165 }
149166
150- painter->setPen (pen);
151- painter->drawRect ( /* square. */ rect () );
167+ painter->setPen ( pen );
168+ painter->drawRect ( rect () );
152169
153170 QConstraintBase::paint ( painter, option, widget);
154-
155171}
156172
157173QOrthogonal::QOrthogonal ()
@@ -162,49 +178,102 @@ QOrthogonal::QOrthogonal()
162178
163179void QOrthogonal::setMarkerSize ( const qreal s)
164180{
165- qDebug () << Q_FUNC_INFO;
181+ // qDebug() << Q_FUNC_INFO;
166182 setRect ( -s, -s, 2 *s, 2 *s );
167183}
168184
169185qreal QOrthogonal::markerSize () const
170186{
171- qDebug () << Q_FUNC_INFO;
187+ // qDebug() << Q_FUNC_INFO;
172188 return -rect ().x ();
173189}
174190
175191
176192void QOrthogonal::setGeometry ( const uStraightLineSegment &s,
177193 const uStraightLineSegment &t)
178194{
179- qDebug () << Q_FUNC_INFO;
195+ // qDebug() << Q_FUNC_INFO;
180196 Vector3d xh = s.hl ().cross ( t.hl () );
181197
182198 QConstraintBase::setPos ( m_sc*xh (0 )/xh (2 ), m_sc*xh (1 )/xh (2 ));
183- // qDebug() << pos();
184199 QConstraintBase::setRotation ( s.phi_deg () );
185200 QConstraintBase::update ();
186201}
187202
188203QCopunctual::QCopunctual ()
189204{
190- qDebug () << Q_FUNC_INFO;
205+ // qDebug() << Q_FUNC_INFO;
191206 const int s = s_defaultMarkerSize;
192207 setRect ( -s, -s, 2 *s, 2 *s );
193208}
194209
210+ QCopunctual::QCopunctual ( const QCopunctual & other)
211+ : QConstraintBase( other )
212+ {
213+ // qDebug() << Q_FUNC_INFO;
214+ }
215+
216+ QOrthogonal::QOrthogonal ( const QOrthogonal & other)
217+ : QConstraintBase( other)
218+ {
219+ // qDebug() << Q_FUNC_INFO;
220+ }
221+
222+ QParallel::QParallel ( const QParallel & other)
223+ : QConstraintBase( other )
224+ {
225+ // qDebug() << Q_FUNC_INFO;
226+ }
227+
228+ QIdentical::QIdentical ( const QIdentical & other)
229+ : QConstraintBase(other)
230+ {
231+ // qDebug() << Q_FUNC_INFO;
232+ }
233+
234+
195235void QCopunctual::setMarkerSize ( const qreal s)
196236{
197- qDebug () << Q_FUNC_INFO;
237+ // qDebug() << Q_FUNC_INFO;
198238 setRect ( -s, -s, 2 *s, 2 *s );
199239}
200240
201241qreal QCopunctual::markerSize () const
202242{
203- qDebug () << Q_FUNC_INFO;
243+ // qDebug() << Q_FUNC_INFO;
204244 return -rect ().x ();
205245}
206246
207247
248+ std::shared_ptr<QConstraintBase> QParallel::clone () const
249+ {
250+ auto T = std::shared_ptr<QParallel>( new QParallel (*this ) );
251+ T->setMarkerSize ( this ->markerSize () );
252+ return std::move (T);
253+ }
254+
255+ std::shared_ptr<QConstraintBase> QOrthogonal::clone () const
256+ {
257+ auto T = std::shared_ptr<QOrthogonal>( new QOrthogonal (*this ));
258+ T->setMarkerSize ( this ->markerSize () );
259+ return std::move (T);
260+ }
261+
262+ std::shared_ptr<QConstraintBase> QIdentical::clone () const
263+ {
264+ auto T = std::shared_ptr<QIdentical>( new QIdentical (*this ) );
265+ T->setMarkerSize ( this ->markerSize () );
266+ return std::move (T);
267+ }
268+
269+ std::shared_ptr<QConstraintBase> QCopunctual::clone () const
270+ {
271+ auto T = std::shared_ptr<QCopunctual>( new QCopunctual (*this ) );
272+ T->setMarkerSize ( this ->markerSize () );
273+ return std::move (T);
274+ }
275+
276+
208277
209278void QConstraintBase::setAltColor (const QColor & col)
210279{
@@ -240,7 +309,6 @@ void QCopunctual::paint( QPainter *painter,
240309 const QStyleOptionGraphicsItem * option,
241310 QWidget * widget)
242311{
243-
244312 QPen pen = QPen ( m_is_required ? m_pen_req : m_pen_red);
245313
246314 if ( showColor ()) {
@@ -265,7 +333,7 @@ void QCopunctual::paint( QPainter *painter,
265333void QCopunctual::setGeometry ( const uStraightLineSegment &s,
266334 const uStraightLineSegment &t)
267335{
268- qDebug () << Q_FUNC_INFO;
336+ // qDebug() << Q_FUNC_INFO;
269337 Vector3d xh = s.hl ().cross ( t.hl () );
270338 QConstraintBase::setPos ( m_sc*xh (0 )/xh (2 ), m_sc*xh (1 )/xh (2 ) );
271339}
@@ -280,14 +348,14 @@ QParallel::QParallel()
280348
281349void QParallel::setMarkerSize ( const qreal s)
282350{
283- qDebug () << Q_FUNC_INFO;
351+ // qDebug() << Q_FUNC_INFO;
284352 a.setLine ( +s_sc*s, -s*(1 -s_shear), +s_sc*s, s*(1 +s_shear));
285353 b.setLine ( -s_sc*s, -s*(1 +s_shear), -s_sc*s, s*(1 -s_shear));
286354}
287355
288356qreal QParallel::markerSize () const
289357{
290- qDebug () << Q_FUNC_INFO;
358+ // qDebug() << Q_FUNC_INFO;
291359 return a.line ().x1 ()/s_sc;
292360}
293361
@@ -317,7 +385,6 @@ void QParallel::paint( QPainter *painter,
317385 const QStyleOptionGraphicsItem * option,
318386 QWidget * widget)
319387{
320-
321388 QPen pen = QPen ( m_is_required ? m_pen_req : m_pen_red);
322389
323390 if ( showColor () ) {
@@ -346,7 +413,7 @@ QIdentical::QIdentical()
346413
347414void QIdentical::setMarkerSize ( const qreal s)
348415{
349- qDebug () << Q_FUNC_INFO;
416+ // qDebug() << Q_FUNC_INFO;
350417 setPolygon ( QPolygonF () << QPointF (-s, -s)
351418 << QPointF (+s, +s)
352419 << QPointF (+s, -s)
@@ -356,7 +423,7 @@ void QIdentical::setMarkerSize ( const qreal s)
356423
357424qreal QIdentical::markerSize () const
358425{
359- qDebug () << Q_FUNC_INFO;
426+ // qDebug() << Q_FUNC_INFO;
360427 // return -polygon().first().x();
361428 return -polygon ().at (0 ).x ();
362429}
@@ -404,25 +471,24 @@ void QIdentical::paint( QPainter *painter,
404471
405472}
406473
407- std::shared_ptr<QConstraintBase> QCopunctual::create () const
474+ std::shared_ptr<QConstraintBase> QCopunctual::create ()
408475{
409- return std::make_shared <QCopunctual>();
476+ return std::shared_ptr <QCopunctual>( new QCopunctual () );
410477}
411478
412- std::shared_ptr<QConstraintBase> QParallel::create () const
479+ std::shared_ptr<QConstraintBase> QParallel::create ()
413480{
414- return std::make_shared <QParallel>();
481+ return std::shared_ptr <QParallel>( new QParallel () );
415482}
416483
417- std::shared_ptr<QConstraintBase> QOrthogonal::create () const
484+ std::shared_ptr<QConstraintBase> QOrthogonal::create ()
418485{
419- std::shared_ptr<QOrthogonal> p = std::make_shared<QOrthogonal>();
420- return std::move (p);
486+ return std::shared_ptr<QOrthogonal>( new QOrthogonal ());
421487}
422488
423- std::shared_ptr<QConstraintBase> QIdentical::create () const
489+ std::shared_ptr<QConstraintBase> QIdentical::create ()
424490{
425- return std::make_shared <QIdentical>();
491+ return std::shared_ptr <QIdentical>( new QIdentical () );
426492}
427493
428494
0 commit comments