2012-07-10 19:39:12 +00:00
|
|
|
#include "baseformlayer.h"
|
|
|
|
|
2012-08-02 19:26:22 +00:00
|
|
|
#include <QInputDialog>
|
|
|
|
|
2012-07-10 20:00:44 +00:00
|
|
|
BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true)
|
2012-07-10 19:39:12 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
_layers_original = NULL;
|
|
|
|
_layers_modified = NULL;
|
|
|
|
if (layers)
|
|
|
|
{
|
2012-11-10 17:05:01 +00:00
|
|
|
_layers_original = layers;
|
|
|
|
_layers_modified = layersCreateCopy(_layers_original);
|
2012-08-26 13:06:42 +00:00
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseFormLayer::~BaseFormLayer()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layersDelete(_layers_modified);
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 13:18:43 +00:00
|
|
|
void BaseFormLayer::revertConfig()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_original && _layers_modified)
|
|
|
|
{
|
|
|
|
layersCopy(_layers_original, _layers_modified);
|
|
|
|
layerSelectedEvent(currentLayer());
|
|
|
|
}
|
2012-07-11 13:18:43 +00:00
|
|
|
|
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::applyConfig()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_original && _layers_modified)
|
|
|
|
{
|
|
|
|
layersCopy(_layers_modified, _layers_original);
|
|
|
|
}
|
2012-07-11 13:18:43 +00:00
|
|
|
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
void BaseFormLayer::setLayers(Layers* layers)
|
|
|
|
{
|
|
|
|
_layers_original = layers;
|
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layersDelete(_layers_modified);
|
|
|
|
}
|
|
|
|
_layers_modified = layersCreateCopy(_layers_original);
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
2012-08-08 14:44:37 +00:00
|
|
|
void BaseFormLayer::afterLayerAdded(void*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-10 20:00:44 +00:00
|
|
|
void BaseFormLayer::configChangeEvent()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layerApply(layersGetLayer(_layers_modified, currentLayer()));
|
|
|
|
layersValidate(_layers_modified);
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
|
|
|
|
BaseForm::configChangeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList BaseFormLayer::getLayers()
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
2012-07-10 20:00:44 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
for (int i = 0; i < layersCount(_layers_modified); i++)
|
|
|
|
{
|
|
|
|
result << QString::fromUtf8(layersGetName(_layers_modified, i));
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::layerAddedEvent()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
2012-07-10 20:00:44 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
QString layer_name = QInputDialog::getText(this, tr("Create layer"), tr("Layer name :"), QLineEdit::Normal, tr("Unnamed layer"));
|
|
|
|
if (not layer_name.isEmpty())
|
2012-08-02 19:26:22 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
int layer = layersAddLayer(_layers_modified, NULL);
|
|
|
|
if (layer >= 0)
|
|
|
|
{
|
|
|
|
layersSetName(_layers_modified, layer, layer_name.toUtf8().data());
|
|
|
|
|
|
|
|
BaseForm::layerAddedEvent();
|
|
|
|
|
|
|
|
afterLayerAdded(layersGetLayer(_layers_modified, layer));
|
|
|
|
}
|
2012-08-02 19:26:22 +00:00
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::layerDeletedEvent(int layer)
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layersDeleteLayer(_layers_modified, layer);
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
|
|
|
|
BaseForm::layerDeletedEvent(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::layerMovedEvent(int layer, int new_position)
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layersMove(_layers_modified, layer, new_position);
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
|
|
|
|
BaseForm::layerMovedEvent(layer, new_position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::layerRenamedEvent(int layer, QString new_name)
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layersSetName(_layers_modified, layer, new_name.toUtf8().data());
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
|
|
|
|
BaseForm::layerRenamedEvent(layer, new_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseFormLayer::layerSelectedEvent(int layer)
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
if (_layers_modified)
|
|
|
|
{
|
|
|
|
layerGetCopy(layersGetLayer(_layers_modified, layer));
|
|
|
|
}
|
2012-07-10 20:00:44 +00:00
|
|
|
|
|
|
|
BaseForm::layerSelectedEvent(layer);
|
2012-07-10 19:39:12 +00:00
|
|
|
}
|