Commit 95db7eb4 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps : dialogs for plugins and maps linked to each view

parent e0664504
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MapsViewDialog</class>
<widget class="QDialog" name="MapsViewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>168</width>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
<string>MapsViewDialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="mapList">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="OKButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>OKButton</sender>
<signal>clicked()</signal>
<receiver>MapsViewDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>115</x>
<y>407</y>
</hint>
<hint type="destinationlabel">
<x>115</x>
<y>214</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PluginsViewDialog</class>
<widget class="QDialog" name="PluginsViewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>168</width>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
<string>PluginsViewDialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="pluginList">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="OKButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>OKButton</sender>
<signal>clicked()</signal>
<receiver>PluginsViewDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>115</x>
<y>407</y>
</hint>
<hint type="destinationlabel">
<x>115</x>
<y>214</y>
</hint>
</hints>
</connection>
</connections>
</ui>
#ifndef _MAPSVIEWDIALOG_H_
#define _MAPSVIEWDIALOG_H_
#include "ui_mapsViewDialog.h"
class Window;
class View;
class MapHandler;
class MapsViewDialog : public QDialog, Ui::MapsViewDialog
{
Q_OBJECT
public:
MapsViewDialog(Window* window, View* view);
~MapsViewDialog();
private:
Window* m_window;
View* m_view;
void selectCurrentMaps();
public slots:
void cb_selectedMapsChanged();
void cb_addMapToList(MapHandler* m);
void cb_removeMapFromList(MapHandler* m);
};
#endif
#ifndef _PLUGINSVIEWDIALOG_H_
#define _PLUGINSVIEWDIALOG_H_
#include "ui_pluginsViewDialog.h"
class Window;
class View;
class Plugin;
class PluginsViewDialog : public QDialog, Ui::PluginsViewDialog
{
Q_OBJECT
public:
PluginsViewDialog(Window* window, View* view);
~PluginsViewDialog();
private:
Window* m_window;
View* m_view;
void selectCurrentPlugins();
public slots:
void cb_selectedPluginsChanged();
void cb_addPluginToList(Plugin* p);
void cb_removePluginFromList(Plugin* p);
};
#endif
#include "mapsViewDialog.h"
#include "window.h"
#include "view.h"
#include "plugin.h"
#include <QMessageBox>
#include <QMouseEvent>
MapsViewDialog::MapsViewDialog(Window* window, View* view) :
QDialog(view),
m_window(window),
m_view(view)
{
this->setupUi(this);
this->setWindowTitle(m_view->getName() + QString(" : maps"));
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapsChanged()));
connect(m_window, SIGNAL(mapAdded(MapHandler*)), this, SLOT(cb_addMapToList(MapHandler*)));
connect(m_window, SIGNAL(mapRemoved(MapHandler*)), this, SLOT(cb_removeMapFromList(MapHandler*)));
QList<MapHandler*> maps = m_window->getMapsList();
foreach(MapHandler* m, maps)
mapList->addItem(m->getName());
}
MapsViewDialog::~MapsViewDialog()
{}
void MapsViewDialog::selectCurrentMaps()
{
QList<MapHandler*> currentMaps = m_view->getLinkedMaps();
QList<QString> currentMapsNames;
foreach(MapHandler* m, currentMaps)
currentMapsNames.push_back(m->getName());
for(int i = 0; i < mapList->count(); ++i)
{
if(currentMapsNames.contains(mapList->item(i)->text()))
mapList->item(i)->setSelected(true);
else
mapList->item(i)->setSelected(false);
}
}
void MapsViewDialog::cb_selectedMapsChanged()
{
for(int i = 0; i < mapList->count(); ++i)
{
QString mapName = mapList->item(i)->text();
MapHandler* map = m_window->getMap(mapName);
if(mapList->item(i)->isSelected() && !m_view->isLinkedToMap(map))
{
m_view->linkMap(map);
map->linkView(m_view);
}
else if(!mapList->item(i)->isSelected() && m_view->isLinkedToMap(map))
{
m_view->unlinkMap(map);
map->unlinkView(m_view);
}
}
}
void MapsViewDialog::cb_addMapToList(MapHandler* m)
{
mapList->addItem(m->getName());
}
void MapsViewDialog::cb_removeMapFromList(MapHandler* m)
{
for(int i = 0; i < mapList->count(); ++i)
{
if(mapList->item(i)->text() == m->getName())
{
delete mapList->item(i);
return;
}
}
}
#include "pluginsViewDialog.h"
#include "window.h"
#include "view.h"
#include "plugin.h"
#include <QMessageBox>
#include <QMouseEvent>
PluginsViewDialog::PluginsViewDialog(Window* window, View* view) :
QDialog(view),
m_window(window),
m_view(view)
{
this->setupUi(this);
this->setWindowTitle(m_view->getName() + QString(" : plugins"));
connect(pluginList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedPluginsChanged()));
connect(m_window, SIGNAL(pluginAdded(Plugin*)), this, SLOT(cb_addPluginToList(Plugin*)));
connect(m_window, SIGNAL(pluginRemoved(Plugin*)), this, SLOT(cb_removePluginFromList(Plugin*)));
QList<Plugin*> plugins = m_window->getPluginsList();
foreach(Plugin* p, plugins)
{
if(p->getProvidesRendering())
pluginList->addItem(p->getName());
}
}
PluginsViewDialog::~PluginsViewDialog()
{}
void PluginsViewDialog::selectCurrentPlugins()
{
QList<Plugin*> currentPlugins = m_view->getLinkedPlugins();
QList<QString> currentPluginsNames;
foreach(Plugin* p, currentPlugins)
currentPluginsNames.push_back(p->getName());
for(int i = 0; i < pluginList->count(); ++i)
{
if(currentPluginsNames.contains(pluginList->item(i)->text()))
pluginList->item(i)->setSelected(true);
else
pluginList->item(i)->setSelected(false);
}
}
void PluginsViewDialog::cb_selectedPluginsChanged()
{
for(int i = 0; i < pluginList->count(); ++i)
{
QString pluginName = pluginList->item(i)->text();
Plugin* plugin = m_window->getPlugin(pluginName);
if(pluginList->item(i)->isSelected() && !m_view->isLinkedToPlugin(plugin))
{
m_view->linkPlugin(plugin);
plugin->linkView(m_view);
}
else if(!pluginList->item(i)->isSelected() && m_view->isLinkedToPlugin(plugin))
{
m_view->unlinkPlugin(plugin);
plugin->unlinkView(m_view);
}
}
m_view->updateGL();
}
void PluginsViewDialog::cb_addPluginToList(Plugin* p)
{
pluginList->addItem(p->getName());
}
void PluginsViewDialog::cb_removePluginFromList(Plugin* p)
{
for(int i = 0; i < pluginList->count(); ++i)
{
if(pluginList->item(i)->text() == p->getName())
{
delete pluginList->item(i);
return;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment