-
Notifications
You must be signed in to change notification settings - Fork 7
/
ToolManager.cpp
153 lines (139 loc) · 4.39 KB
/
ToolManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* The Simple Earth Project
* Copyright (C) 2022 HueSoft LLC
* Author: Hector Mendoza, hector.mendoza@huesoftllc.com
*
* This file is part of the Simple Earth Project.
*
* The Simple Earth Project is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "ToolManager.h"
//Singleton implementation
ToolManager* ToolManager::mInstance = NULL;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Constructor. Initializes attributes.
*/
ToolManager::ToolManager()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mCurrentToolIndex = -1;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Destructor.
*/
ToolManager::~ToolManager()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
//release all data
for (int i = 0; i < mToolList.size(); i++)
{
delete mToolList[i];
}
mToolList.clear();
mInstance = NULL;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Singleton pattern implementation. Returns the single instance of this class.
*
* @return The single instance of this object.
*/
ToolManager* ToolManager::getInstance()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
if (mInstance == NULL)
{
mInstance = new ToolManager();
}
return mInstance;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Adds a Tool to the tool list.
*
* @param tool New tool to add to the list
*/
void ToolManager::addTool(Tool* tool)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mToolList.append(tool);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Returns the handle to the tool that corresponds to the given ID.
*
* @param toolID String identifying the tool
* @return Handle to corresponding tool
*/
Tool* ToolManager::getTool(const QString& toolID)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
Tool* returnValue = NULL;
for (int i = 0; i < mToolList.size(); i++)
{
if (toolID == mToolList[i]->getToolID())
{
returnValue = mToolList[i];
break;
}
}
return returnValue;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Selects the tool with the given toolID as the current tool. If toolID is
* empty string (or not found), all windows will be hidden and all the tool
* buttons unchecked. Also no tool will be rendered.
*
* @param toolID String identifying tool
*/
void ToolManager::selectTool(const QString& toolID)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mCurrentToolIndex = -1;
for (int i = 0; i < mToolList.size(); i++)
{
if (toolID == mToolList[i]->getToolID())
{
//show dialog and set current index for tool to be rendered
//though there is no need to set tool button to checked if
//action was triggered by user, it is here in case this method
//is called programatically
mCurrentToolIndex = i;
mToolList[i]->getDialog()->show();
mToolList[i]->getToolButton()->setChecked(true);
}
else
{
//uncheck all other tool buttons and hide their dialogs
mToolList[i]->getDialog()->hide();
mToolList[i]->getToolButton()->setChecked(false);
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Calls the render method for the currently selected tool.
*/
void ToolManager::renderSelectedTool()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
if (mCurrentToolIndex >= 0 && mCurrentToolIndex < mToolList.size())
{
mToolList[mCurrentToolIndex]->render();
}
}