File: PropertyPanelController.cpp

package info (click to toggle)
mygui 3.4.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,800 kB
  • sloc: cpp: 122,825; ansic: 30,231; xml: 15,792; cs: 12,601; tcl: 776; python: 397; makefile: 38
file content (77 lines) | stat: -rw-r--r-- 2,043 bytes parent folder | download | duplicates (2)
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
/*!
	@file
	@author		Albert Semenov
	@date		07/2012
*/

#include "Precompiled.h"
#include "PropertyPanelController.h"
#include "DataSelectorManager.h"
#include "DataManager.h"
#include "ScopeManager.h"
#include "DataTypeManager.h"
#include "DataUtility.h"

namespace tools
{

	PropertyPanelController::PropertyPanelController() :
		mControl(nullptr),
		mParentType(nullptr)
	{
	}

	void PropertyPanelController::setTarget(Control* _control)
	{
		mControl = _control->findControl<PropertyPanelControl>();
	}

	void PropertyPanelController::activate()
	{
		ScopeManager::getInstance().eventChangeScope.connect(this, &PropertyPanelController::notifyChangeScope);
		notifyChangeScope(ScopeManager::getInstance().getCurrentScope());
	}

	void PropertyPanelController::deactivate()
	{
		ScopeManager::getInstance().eventChangeScope.disconnect(this);
	}

	void PropertyPanelController::notifyChangeScope(const std::string& _scope)
	{
		if (mParentType != nullptr)
		{
			DataSelectorManager::getInstance().getEvent(mParentType->getName())->disconnect(this);
			mParentType = nullptr;
		}

		mParentType = DataTypeManager::getInstance().getParentType(_scope);

		if (mParentType != nullptr)
		{
			DataSelectorManager::getInstance().getEvent(mParentType->getName())->connect(this, &PropertyPanelController::notifyChangeDataSelector);

			DataPtr parentData = DataUtility::getSelectedDataByType(mParentType->getName());
			notifyChangeDataSelector(parentData, false);
		}
	}

	void PropertyPanelController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection)
	{
		if (mControl != nullptr)
		{
			DataPtr selected = _data != nullptr ? _data->getChildSelected() : nullptr;

			// выделяем только данные с типом скопа
			if (selected != nullptr)
			{
				if (selected->getType()->getName() != ScopeManager::getInstance().getCurrentScope() &&
					selected->getType()->getFriend() != ScopeManager::getInstance().getCurrentScope())
				selected = nullptr;
			}

			mControl->setCurrentData(selected);
		}
	}

}