1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Jochen Becher
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "sceneinspector.h"
27 
28 #include "qmt/diagram_scene/diagramsceneconstants.h"
29 #include "qmt/diagram_scene/diagramscenemodel.h"
30 #include "qmt/diagram_scene/capabilities/moveable.h"
31 #include "qmt/diagram_scene/capabilities/resizable.h"
32 #include "qmt/diagram_ui/diagramsmanager.h"
33 #include "qmt/infrastructure/qmtassert.h"
34 
35 #include <QSizeF>
36 #include <QGraphicsItem>
37 
38 namespace qmt {
39 
SceneInspector(QObject * parent)40 SceneInspector::SceneInspector(QObject *parent)
41     : QObject(parent)
42 {
43 }
44 
~SceneInspector()45 SceneInspector::~SceneInspector()
46 {
47 }
48 
setDiagramsManager(DiagramsManager * diagramsManager)49 void SceneInspector::setDiagramsManager(DiagramsManager *diagramsManager)
50 {
51     m_diagramsManager = diagramsManager;
52 }
53 
rasterSize() const54 QSizeF SceneInspector::rasterSize() const
55 {
56     return QSizeF(RASTER_WIDTH, RASTER_HEIGHT);
57 }
58 
minimalSize(const DElement * element,const MDiagram * diagram) const59 QSizeF SceneInspector::minimalSize(const DElement *element, const MDiagram *diagram) const
60 {
61     DiagramSceneModel *diagramSceneModel = m_diagramsManager->diagramSceneModel(diagram);
62     QMT_CHECK(diagramSceneModel);
63     if (diagramSceneModel) {
64         const QGraphicsItem *item = diagramSceneModel->graphicsItem(const_cast<DElement *>(element));
65         QMT_CHECK(item);
66         if (item) {
67             if (auto resizable = dynamic_cast<const IResizable *>(item))
68                 return resizable->minimumSize();
69         }
70     }
71     QMT_CHECK(false);
72     return QSizeF();
73 }
74 
moveable(const DElement * element,const MDiagram * diagram) const75 IMoveable *SceneInspector::moveable(const DElement *element, const MDiagram *diagram) const
76 {
77     DiagramSceneModel *diagramSceneModel = m_diagramsManager->diagramSceneModel(diagram);
78     QMT_CHECK(diagramSceneModel);
79     if (diagramSceneModel) {
80         QGraphicsItem *item = diagramSceneModel->graphicsItem(const_cast<DElement *>(element));
81         QMT_CHECK(item);
82         if (item) {
83             if (auto moveable = dynamic_cast<IMoveable *>(item))
84                 return moveable;
85         }
86     }
87     QMT_CHECK(false);
88     return nullptr;
89 }
90 
resizable(const DElement * element,const MDiagram * diagram) const91 IResizable *SceneInspector::resizable(const DElement *element, const MDiagram *diagram) const
92 {
93     DiagramSceneModel *diagramSceneModel = m_diagramsManager->diagramSceneModel(diagram);
94     QMT_CHECK(diagramSceneModel);
95     if (diagramSceneModel) {
96         QGraphicsItem *item = diagramSceneModel->graphicsItem(const_cast<DElement *>(element));
97         QMT_CHECK(item);
98         if (item) {
99             if (auto resizeable = dynamic_cast<IResizable *>(item))
100                 return resizeable;
101         }
102     }
103     QMT_CHECK(false);
104     return nullptr;
105 }
106 
107 } // namespace qmt
108