10#include <QtCore/QtGlobal>
11#include <QtWidgets/QMenu>
12#include <QtWidgets/QPushButton>
13#include <QtWidgets/QToolButton>
14#include <QtWidgets/QToolBar>
30template <
class Ui,
class Shape,
class ShapeModel>
33 istdgui::TDesignerGuiObserverCompBase<Ui, ShapeModel> >,
41 I_ASSIGN(m_defaultUnitInfoCompPtr,
"DefaultUnitInfo",
"Provide default information about the logical value units e.g. mm, this will be used if no unit information found in model",
false,
"DefaultUnitInfo");
42 I_ASSIGN(m_colorSchemaCompPtr,
"ShapeColorSchema",
"Color schema used by displayed shape",
false,
"ShapeColorSchema");
43 I_ASSIGN(m_fixedPositionAttrPtr,
"FixedPosition",
"If enabled, the shape position will be not editable",
true,
false);
44 I_ASSIGN(m_fixedPositionParamPtr,
"FixedPositionParam",
"If set, will be used instead of FixedPosition attribute",
false,
"FixedPositionParam");
45 I_ASSIGN(m_allowToolsMenuAttrPtr,
"ShowTools",
"Show extended shape edit tools",
true,
true);
46 I_ASSIGN(m_toolBarGuiCompPtr,
"ToolBarGui",
"Toolbar GUI object to fill with actions",
false,
"ToolBarGui");
47 I_ASSIGN(m_shapeToolTipAttrPtr,
"ShapeToolTip",
"Tool tip will be show on console",
false,
"");
99 QAbstractButton* m_menuButtonPtr;
101 typedef QSet<QAction*> Actions;
102 Actions m_toolBarActions;
107 I_ATTR(
bool, m_fixedPositionAttrPtr);
108 I_ATTR(
bool, m_allowToolsMenuAttrPtr);
110 I_TEXTATTR(m_shapeToolTipAttrPtr);
116template <
class Ui,
class Shape,
class ShapeModel>
119 m_menuButtonPtr(nullptr)
126template <
class Ui,
class Shape,
class ShapeModel>
129 if (BaseClass::OnModelAttached(modelPtr, changeMask)) {
130 const ShapesMap& shapesMap = BaseClass::GetShapesMap();
131 for (
typename ShapesMap::const_iterator iter = shapesMap.begin();
132 iter != shapesMap.end();
134 const Shapes& shapes = iter.value();
135 int shapesCount = shapes.GetCount();
136 for (
int shapeIndex = 0; shapeIndex < shapesCount; ++shapeIndex) {
137 Shape* shapePtr =
dynamic_cast<Shape*
>(shapes.GetAt(shapeIndex));
138 if (shapePtr !=
nullptr) {
140 shapePtr->SetVisible(
true);
154template <
class Ui,
class Shape,
class ShapeModel>
157 if (BaseClass::OnModelDetached(modelPtr)) {
158 const ShapesMap& shapesMap = BaseClass::GetShapesMap();
159 for (
typename ShapesMap::const_iterator iter = shapesMap.begin();
160 iter != shapesMap.end();
162 const Shapes& shapes = iter.value();
163 int shapesCount = shapes.GetCount();
164 for (
int shapeIndex = 0; shapeIndex < shapesCount; ++shapeIndex) {
165 Shape* shapePtr =
dynamic_cast<Shape*
>(shapes.GetAt(shapeIndex));
166 if (shapePtr !=
nullptr) {
171 shapePtr->SetVisible(
false);
186template <
class Ui,
class Shape,
class ShapeModel>
189 std::unique_ptr<iview::IShape> shapePtr = CreateShapeInstance();
191 interactiveShapePtr->SetEditablePosition(!IsPositionFixed());
193 if (m_colorSchemaCompPtr !=
nullptr) {
194 interactiveShapePtr->SetUserColorSchema(m_colorSchemaCompPtr.get());
197 if (m_shapeToolTipAttrPtr !=
nullptr) {
198 interactiveShapePtr->SetDefaultDescription(*m_shapeToolTipAttrPtr);
202 if (connectToModel) {
204 if (modelPtr !=
nullptr) {
206 shapePtr->SetVisible(
true);
217template <
class Ui,
class Shape,
class ShapeModel>
220 if (m_fixedPositionParamPtr !=
nullptr) {
221 return m_fixedPositionParamPtr->IsEnabled();
224 return *m_fixedPositionAttrPtr;
228template <
class Ui,
class Shape,
class ShapeModel>
231 return *m_allowToolsMenuAttrPtr;
235template <
class Ui,
class Shape,
class ShapeModel>
238 return m_toolBarGuiCompPtr !=
nullptr ?
dynamic_cast<QToolBar*
>(m_toolBarGuiCompPtr->GetWidget()) :
nullptr;
242template <
class Ui,
class Shape,
class ShapeModel>
247 const ShapeModel* objectPtr = BaseClass::GetObservedObject();
248 if (objectPtr !=
nullptr) {
250 if (calibrationProviderPtr !=
nullptr) {
252 if (calibrationPtr !=
nullptr) {
258 if (unitInfoPtr !=
nullptr) {
262 if (m_defaultUnitInfoCompPtr !=
nullptr) {
263 return m_defaultUnitInfoCompPtr->GetUnitName();
270template <
class Ui,
class Shape,
class ShapeModel>
273 return std::unique_ptr<iview::IShape>{
new Shape()};
277template <
class Ui,
class Shape,
class ShapeModel>
280 m_menuButtonPtr = buttonPtr;
282 if (buttonPtr ==
nullptr) {
286 if (!IsToolsMenuAllowed()) {
291 if (m_menuPtr ==
nullptr) {
292 m_menuPtr =
new QMenu(buttonPtr);
293 QObject::connect(m_menuPtr, SIGNAL(triggered(QAction*)),
this, SLOT(OnActionTriggered(QAction*)));
295 QPushButton* pushButtonPtr =
dynamic_cast<QPushButton*
>(buttonPtr);
296 if (pushButtonPtr !=
nullptr) {
297 pushButtonPtr->setMenu(m_menuPtr);
300 QToolButton* toolButtonPtr =
dynamic_cast<QToolButton*
>(buttonPtr);
301 if (toolButtonPtr !=
nullptr) {
302 toolButtonPtr->setMenu(m_menuPtr);
309template <
class Ui,
class Shape,
class ShapeModel>
316template <
class Ui,
class Shape,
class ShapeModel>
319 if (m_menuPtr !=
nullptr) {
322 if (PopulateActions(*m_menuPtr, modelPtr)) {
323 m_menuButtonPtr->setEnabled(
true);
326 m_menuButtonPtr->setEnabled(
false);
329 QToolBar* toolBarPtr = GetToolBar();
330 if (toolBarPtr !=
nullptr) {
332 auto toolbarKeys = toolBarPtr->actions();
333 QSet<QAction*> oldActions(toolbarKeys.begin(), toolbarKeys.end());
335 if (PopulateActions(*toolBarPtr, modelPtr)) {
336 auto newToolbarKeys = toolBarPtr->actions();
338 QSet<QAction*> newActions(newToolbarKeys.begin(), newToolbarKeys.end());
339 m_toolBarActions = newActions - oldActions;
341 toolBarPtr->setVisible(
true);
345 if (m_menuPtr ==
nullptr) {
346 QObject::connect(toolBarPtr, SIGNAL(actionTriggered(QAction*)),
this, SLOT(OnActionTriggered(QAction*)));
350 toolBarPtr->disconnect();
356template <
class Ui,
class Shape,
class ShapeModel>
359 if (m_menuButtonPtr !=
nullptr) {
360 m_menuButtonPtr->setEnabled(
false);
363 QToolBar* toolBarPtr = GetToolBar();
365 toolBarPtr->disconnect();
368 for (Actions::const_iterator iter = m_toolBarActions.constBegin(); iter != m_toolBarActions.constEnd(); ++iter) {
369 toolBarPtr->removeAction(*iter);
372 m_toolBarActions.clear();
379template <
class Ui,
class Shape,
class ShapeModel>
387template <
class Ui,
class Shape,
class ShapeModel>
390 bool areShapesVisible = !BaseClass::IsReadOnly();
391 auto shapePtr = CreateShape(BaseClass::GetObservedObject(),
true);
392 if (shapePtr !=
nullptr) {
393 shapePtr->SetVisible(areShapesVisible);
394 result.PushBack(shapePtr.release());
401template <
class Ui,
class Shape,
class ShapeModel>
404 m_menuButtonPtr =
nullptr;
405 if (m_menuPtr !=
nullptr) {
406 m_menuPtr->deleteLater();
411 BaseClass::OnGuiDestroyed();
415template <
class Ui,
class Shape,
class ShapeModel>
418 BaseClass::OnGuiShown();
420 OnModelAttachedAndGuiShown(BaseClass::GetObservedModel());
424template <
class Ui,
class Shape,
class ShapeModel>
427 OnModelDetachedOrGuiHidden(BaseClass::GetObservedModel());
429 BaseClass::OnGuiHidden();
435template <
class Ui,
class Shape,
class ShapeModel>
438 BaseClass::OnGuiModelAttached();
440 if (BaseClass::IsGuiShown()) {
441 OnModelAttachedAndGuiShown(BaseClass::GetObservedModel());
444 m_fixedPositionParamPtr.EnsureInitialized();
448template <
class Ui,
class Shape,
class ShapeModel>
451 OnModelDetachedOrGuiHidden(BaseClass::GetObservedModel());
453 BaseClass::OnGuiModelDetached();
459template <
class Ui,
class Shape,
class ShapeModel>
462 BaseClass::SetReadOnly(state);
463 BaseClass::SetAllShapesVisible(!state);
virtual const imath::IUnitInfo * GetArgumentUnitInfo() const =0
Get unit description of calibration input (transformation function argument).
Common interface for an object, which delivers a 2D-calibration.
virtual const ICalibration2d * GetCalibration() const =0
Get access to transformation object, which transforms a local logical coordinate system to global one...
bool IsPositionFixed() const
i2dgui::TViewExtenderCompBase< istdgui::TDesignerGuiObserverCompBase< Ui, ShapeModel > > BaseClass
void OnGuiShown() override
Called from widget event filter when slave widget is shown.
void SetReadOnly(bool state) override
Set flag that the model data can be changed.
bool OnModelDetached(imod::IModel *modelPtr) override
This call back function will be called, if an observable object is about to be detached.
virtual bool PopulateActions(QWidget &host, imod::IModel *modelPtr)
bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
This call back function will be called, if an observable object is about to be attached.
void OnGuiDestroyed() override
Called just before GUI is released.
virtual void OnModelAttachedAndGuiShown(imod::IModel *modelPtr)
virtual void OnModelDetachedOrGuiHidden(imod::IModel *modelPtr)
void OnGuiHidden() override
Called from widget event filter when slave widget is hidden.
bool IsToolsMenuAllowed() const
void OnGuiModelAttached() override
virtual std::unique_ptr< iview::IShape > CreateShapeInstance() const
Simple creation of shape instance.
virtual void OnActionTriggered(QAction *actionPtr)
QString GetUnitName() const
TShapeParamsGuiCompBase()
void CreateShapes(int sceneId, Shapes &result) override
QToolBar * GetToolBar() const
virtual void CreateToolsMenu(QAbstractButton *buttonPtr)
Maintenance of the tools actions.
void OnGuiModelDetached() override
std::unique_ptr< iview::IShape > CreateShape(const istd::IChangeable *objectPtr, bool connectToModel=false) const override
Create a graphical representation of the given 2D-object object.
BaseClass::ShapesMap ShapesMap
istd::TPointerVector< iview::IShape > Shapes
QMap< IViewProvider *, Shapes > ShapesMap
Common interface to get information about a measurement unit.
virtual QString GetUnitName() const =0
Get name of unit.
Common interface for model objects, that supports Model/Observer design pattern.
virtual void DetachObserver(IObserver *observerPtr)=0
Detaches model object from observer observerPtr.
virtual bool AttachObserver(IObserver *observerPtr)=0
Attaches model object to observer observerPtr.
virtual bool IsAttached(const IObserver *observerPtr) const =0
Returns true if observer observer is attached to this model object.
Interface for objects which can be enabled/disabled.
Set of change flags (its IDs).
Common interface for data model objects, which can be changed.
Common interface for GUI objects using in component context.
Base class of shape implementation with user interaction.
Defines set of standard pens, brushes and simple management of unions.
Interface for creation of visualization shapes of some geometrical object.
This package contains Qt based implementations for 2D graphic objects.