Skip to content

Commit 2a16f7b

Browse files
committed
refactor: Split UBItem and UBGraphicsItem into different files
The two classes are unrelated to each other. The split allows more precise includes in downstream users, and better separation of concerns for development.
1 parent f75d6c8 commit 2a16f7b

21 files changed

Lines changed: 233 additions & 143 deletions

src/adaptors/UBSvgSubsetAdaptor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "domain/UBGraphicsStrokesGroup.h"
5050
#include "domain/UBGraphicsGroupContainerItem.h"
5151
#include "domain/UBGraphicsGroupContainerItemDelegate.h"
52+
#include "domain/UBGraphicsItem.h"
5253
#include "domain/UBItem.h"
5354

5455
#include "gui/UBBackgroundRuling.h"

src/board/UBBoardController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "document/UBDocumentProxy.h"
6060

6161
#include "domain/UBGraphicsGroupContainerItem.h"
62+
#include "domain/UBGraphicsItem.h"
6263
#include "domain/UBGraphicsItemUndoCommand.h"
6364
#include "domain/UBGraphicsMediaItem.h"
6465
#include "domain/UBGraphicsPDFItem.h"

src/board/UBBoardView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#include "domain/UBGraphicsWidgetItem.h"
7070
#include "domain/UBGraphicsPDFItem.h"
7171
#include "domain/UBGraphicsPolygonItem.h"
72-
#include "domain/UBItem.h"
72+
#include "domain/UBGraphicsItem.h"
7373
#include "domain/UBGraphicsMediaItem.h"
7474
#include "domain/UBGraphicsSvgItem.h"
7575
#include "domain/UBGraphicsGroupContainerItem.h"

src/domain/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ target_sources(${PROJECT_NAME} PRIVATE
55
UBGraphicsGroupContainerItem.h
66
UBGraphicsGroupContainerItemDelegate.cpp
77
UBGraphicsGroupContainerItemDelegate.h
8+
UBGraphicsItem.cpp
9+
UBGraphicsItem.h
810
UBGraphicsItemDelegate.cpp
911
UBGraphicsItemDelegate.h
1012
UBGraphicsItemGroupUndoCommand.cpp

src/domain/UBGraphicsDelegateFrame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "board/UBBoardController.h"
3939
#include "board/UBBoardView.h"
4040

41+
#include "domain/UBGraphicsItem.h"
4142
#include "domain/UBGraphicsItemDelegate.h"
4243
#include "domain/UBGraphicsScene.h"
4344
#include "domain/UBResizableGraphicsItem.h"

src/domain/UBGraphicsGroupContainerItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "core/UB.h"
4242

43+
#include "domain/UBGraphicsItem.h"
4344
#include "domain/UBItem.h"
4445

4546
#include "frameworks/UBCoreGraphicsScene.h"

src/domain/UBGraphicsItem.cpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM)
3+
*
4+
* Copyright (C) 2013 Open Education Foundation
5+
*
6+
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
7+
* l'Education Numérique en Afrique (GIP ENA)
8+
*
9+
* This file is part of OpenBoard.
10+
*
11+
* OpenBoard is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, version 3 of the License,
14+
* with a specific linking exception for the OpenSSL project's
15+
* "OpenSSL" library (or with modified versions of it that use the
16+
* same license as the "OpenSSL" library).
17+
*
18+
* OpenBoard is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public License
24+
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
25+
*/
26+
27+
28+
29+
30+
#include "UBGraphicsItem.h"
31+
32+
#include "core/memcheck.h"
33+
34+
#include "domain/UBGraphicsPixmapItem.h"
35+
#include "domain/UBGraphicsTextItem.h"
36+
#include "domain/UBGraphicsSvgItem.h"
37+
#include "domain/UBGraphicsMediaItem.h"
38+
#include "domain/UBGraphicsStrokesGroup.h"
39+
#include "domain/UBGraphicsGroupContainerItem.h"
40+
#include "domain/UBGraphicsWidgetItem.h"
41+
#include "domain/UBGraphicsScene.h"
42+
#include "tools/UBGraphicsCurtainItem.h"
43+
#include "domain/UBGraphicsItemDelegate.h"
44+
45+
UBGraphicsItem::~UBGraphicsItem()
46+
{
47+
if (mDelegate!=NULL)
48+
delete mDelegate;
49+
}
50+
51+
void UBGraphicsItem::setDelegate(UBGraphicsItemDelegate* delegate)
52+
{
53+
Q_ASSERT(mDelegate==NULL);
54+
mDelegate = delegate;
55+
}
56+
57+
UBGraphicsItemDelegate *UBGraphicsItem::Delegate() const
58+
{
59+
return mDelegate;
60+
}
61+
62+
void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value)
63+
{
64+
item->setZValue(value);
65+
item->setData(UBGraphicsItemData::ItemOwnZValue, value);
66+
}
67+
68+
bool UBGraphicsItem::isFlippable(QGraphicsItem *item)
69+
{
70+
return item->data(UBGraphicsItemData::ItemFlippable).toBool();
71+
}
72+
73+
bool UBGraphicsItem::isRotatable(QGraphicsItem *item)
74+
{
75+
return item->data(UBGraphicsItemData::ItemRotatable).toBool();
76+
}
77+
78+
bool UBGraphicsItem::isLocked(QGraphicsItem *item)
79+
{
80+
return item->data(UBGraphicsItemData::ItemLocked).toBool();
81+
}
82+
83+
bool UBGraphicsItem::isHiddenOnDisplay(QGraphicsItem *item)
84+
{
85+
return item->data(UBGraphicsItemData::ItemIsHiddenOnDisplay).toBool();
86+
}
87+
88+
void UBGraphicsItem::remove(bool canUndo)
89+
{
90+
if (Delegate())
91+
Delegate()->remove(canUndo);
92+
}
93+
94+
UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem)
95+
{
96+
UBGraphicsItemDelegate *result = 0;
97+
98+
switch (static_cast<int>(pItem->type())) {
99+
case UBGraphicsPixmapItem::Type :
100+
result = (static_cast<UBGraphicsPixmapItem*>(pItem))->Delegate();
101+
break;
102+
case UBGraphicsTextItem::Type :
103+
result = (static_cast<UBGraphicsTextItem*>(pItem))->Delegate();
104+
break;
105+
case UBGraphicsSvgItem::Type :
106+
result = (static_cast<UBGraphicsSvgItem*>(pItem))->Delegate();
107+
break;
108+
case UBGraphicsMediaItem::Type:
109+
case UBGraphicsVideoItem::Type:
110+
case UBGraphicsAudioItem::Type:
111+
result = (static_cast<UBGraphicsMediaItem*>(pItem))->Delegate();
112+
break;
113+
case UBGraphicsStrokesGroup::Type :
114+
result = (static_cast<UBGraphicsStrokesGroup*>(pItem))->Delegate();
115+
break;
116+
case UBGraphicsGroupContainerItem::Type :
117+
result = (static_cast<UBGraphicsGroupContainerItem*>(pItem))->Delegate();
118+
break;
119+
case UBGraphicsWidgetItem::Type :
120+
result = (static_cast<UBGraphicsWidgetItem*>(pItem))->Delegate();
121+
break;
122+
case UBGraphicsCurtainItem::Type :
123+
result = (static_cast<UBGraphicsCurtainItem*>(pItem))->Delegate();
124+
break;
125+
}
126+
127+
return result;
128+
}

src/domain/UBGraphicsItem.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM)
3+
*
4+
* Copyright (C) 2013 Open Education Foundation
5+
*
6+
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
7+
* l'Education Numérique en Afrique (GIP ENA)
8+
*
9+
* This file is part of OpenBoard.
10+
*
11+
* OpenBoard is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, version 3 of the License,
14+
* with a specific linking exception for the OpenSSL project's
15+
* "OpenSSL" library (or with modified versions of it that use the
16+
* same license as the "OpenSSL" library).
17+
*
18+
* OpenBoard is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public License
24+
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
25+
*/
26+
27+
28+
29+
30+
#ifndef UBGRAPHICSITEM_H
31+
#define UBGRAPHICSITEM_H
32+
33+
#include <QGraphicsItem>
34+
35+
#include "UBGraphicsItemDelegate.h"
36+
37+
class UBGraphicsItem
38+
{
39+
protected:
40+
UBGraphicsItem() : mDelegate(NULL)
41+
{
42+
// NOOP
43+
}
44+
virtual ~UBGraphicsItem();
45+
void setDelegate(UBGraphicsItemDelegate* mDelegate);
46+
47+
public:
48+
virtual int type() const = 0;
49+
50+
UBGraphicsItemDelegate *Delegate() const;
51+
52+
static void assignZValue(QGraphicsItem*, qreal value);
53+
static bool isRotatable(QGraphicsItem *item);
54+
static bool isFlippable(QGraphicsItem *item);
55+
static bool isLocked(QGraphicsItem *item);
56+
static bool isHiddenOnDisplay(QGraphicsItem *item);
57+
58+
static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem);
59+
60+
void remove(bool canUndo = true);
61+
62+
private:
63+
UBGraphicsItemDelegate* mDelegate;
64+
};
65+
66+
#endif // UBGRAPHICSITEM_H

src/domain/UBGraphicsItemUndoCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
#include "core/UBApplication.h"
3939

4040
#include "UBGraphicsGroupContainerItem.h"
41+
#include "UBGraphicsItem.h"
4142
#include "UBGraphicsItemDelegate.h"
4243
#include "UBGraphicsPolygonItem.h"
4344
#include "UBGraphicsScene.h"
44-
#include "UBItem.h"
4545

4646
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(std::shared_ptr<UBGraphicsScene> pScene, const QSet<QGraphicsItem*>& pRemovedItems, const QSet<QGraphicsItem*>& pAddedItems, const GroupDataTable &groupsMap): UBUndoCommand()
4747
, mScene(pScene)

src/domain/UBGraphicsMediaItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#include "core/UB.h"
4242

43-
#include "domain/UBItem.h"
43+
#include "domain/UBGraphicsItem.h"
4444
#include "domain/UBMediaAssetItem.h"
4545
#include "domain/UBResizableGraphicsItem.h"
4646

0 commit comments

Comments
 (0)