mapsViewDialog.cpp 2.41 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "dialogs/mapsViewDialog.h"
2 3 4 5

#include "window.h"
#include "view.h"
#include "plugin.h"
6
#include "mapHandler.h"
7 8 9 10

#include <QMessageBox>
#include <QMouseEvent>

Pierre Kraemer's avatar
Pierre Kraemer committed
11 12 13 14 15 16
namespace CGoGN
{

namespace SCHNApps
{

17 18 19
MapsViewDialog::MapsViewDialog(Window* window, View* view) :
	QDialog(view),
	m_window(window),
20 21
	m_view(view),
	b_refreshingUI(false)
22
{
23 24
	setupUi(this);
	setWindowTitle(m_view->getName() + QString(" : maps"));
25

26
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapsChanged()));
27

28 29
	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));
30

31 32 33
	connect(m_window, SIGNAL(viewAndMapLinked(View*, MapHandlerGen*)), this, SLOT(selectMap(View*, MapHandlerGen*)));
	connect(m_window, SIGNAL(viewAndMapUnlinked(View*, MapHandlerGen*)), this, SLOT(deselectMap(View*, MapHandlerGen*)));

34 35
	QList<MapHandlerGen*> maps = m_window->getMapsList();
	foreach(MapHandlerGen* m, maps)
36 37 38 39 40 41
		mapList->addItem(m->getName());
}

MapsViewDialog::~MapsViewDialog()
{}

42
void MapsViewDialog::selectedMapsChanged()
43
{
44
	if(!b_refreshingUI)
45
	{
46 47 48 49
		for(int i = 0; i < mapList->count(); ++i)
		{
			QString mapName = mapList->item(i)->text();
			MapHandlerGen* map = m_window->getMap(mapName);
50

51 52 53 54 55 56 57 58 59
			if(mapList->item(i)->isSelected() && !m_view->isLinkedToMap(map))
				m_window->linkViewAndMap(m_view, map);

			else if(!mapList->item(i)->isSelected() && m_view->isLinkedToMap(map))
				m_window->unlinkViewAndMap(m_view, map);
		}
	}
}

60
void MapsViewDialog::selectMap(View* view, MapHandlerGen* m)
61 62 63
{
	if(view == m_view)
	{
64
		QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
65 66 67 68 69 70 71 72
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(true);
			b_refreshingUI = false;
		}
	}
}
73

74
void MapsViewDialog::deselectMap(View* view, MapHandlerGen* m)
75 76 77
{
	if(view == m_view)
	{
78
		QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
79 80 81 82 83 84
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(false);
			b_refreshingUI = false;
		}
85 86 87
	}
}

88
void MapsViewDialog::addMapToList(MapHandlerGen* m)
89 90 91 92
{
	mapList->addItem(m->getName());
}

93
void MapsViewDialog::removeMapFromList(MapHandlerGen* m)
94
{
95 96 97
	QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];
98
}
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102

} // namespace SCHNApps

} // namespace CGoGN