mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-04-15 12:09:24 +02:00
Checkbox for toggling visibility of layers (+ some cleanup)
This commit is contained in:
@@ -64,9 +64,12 @@ void DestinationGLCanvas::doDraw()
|
||||
glPushMatrix();
|
||||
|
||||
MappingManager& mappingManager = MainWindow::getInstance().getMappingManager();
|
||||
for (int i=0; i<mappingManager.nMappings(); i++)
|
||||
std::vector<Layer::ptr> layers = mappingManager.getVisibleLayers();
|
||||
for (std::vector<Layer::ptr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
|
||||
{
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(mappingManager.getMapping(i));
|
||||
Mapping::ptr mapping = (*it)->getMapping();
|
||||
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(mapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
|
||||
|
||||
@@ -59,16 +59,7 @@ void MainWindow::handleSourceItemSelectionChanged()
|
||||
uint idx = item->data(Qt::UserRole).toUInt();
|
||||
std::cout << "idx=" << idx << std::endl;
|
||||
setCurrentPaint(idx);
|
||||
|
||||
// Reconstruct shape item list.
|
||||
shapeList->clear();
|
||||
removeCurrentMapping(); // de-select current mapping to avoid being stuck with the last selection
|
||||
// Retrieve all mappings associated to paint.
|
||||
std::map<uint, Mapping::ptr> mappings = getMappingManager().getPaintMappingsById(idx);
|
||||
for (std::map<uint, Mapping::ptr>::iterator it = mappings.begin(); it != mappings.end(); ++it)
|
||||
{
|
||||
addMappingItem(it->first);
|
||||
}
|
||||
removeCurrentMapping();
|
||||
|
||||
// Update canvases.
|
||||
sourceCanvas->update();
|
||||
@@ -78,13 +69,15 @@ void MainWindow::handleSourceItemSelectionChanged()
|
||||
//destinationCanvas->repaint();
|
||||
}
|
||||
|
||||
void MainWindow::handleShapeItemSelectionChanged()
|
||||
void MainWindow::handleLayerItemSelectionChanged()
|
||||
{
|
||||
std::cout << "shape selection changed" << std::endl;
|
||||
QListWidgetItem* item = shapeList->currentItem();
|
||||
QListWidgetItem* item = layerList->currentItem();
|
||||
uint idx = item->data(Qt::UserRole).toUInt();
|
||||
std::cout << "idx=" << idx << std::endl;
|
||||
setCurrentMapping(idx);
|
||||
Mapping::ptr mapping = mappingManager->getLayerById(idx)->getMapping();
|
||||
setCurrentPaint(mapping->getPaint()->getId());
|
||||
setCurrentMapping(mapping->getId());
|
||||
sourceCanvas->update();
|
||||
destinationCanvas->update();
|
||||
//sourceCanvas->switchImage(idx);
|
||||
@@ -92,6 +85,15 @@ void MainWindow::handleShapeItemSelectionChanged()
|
||||
//destinationCanvas->repaint();
|
||||
}
|
||||
|
||||
void MainWindow::handleLayerItemChanged(QListWidgetItem* item)
|
||||
{
|
||||
uint layerId = item->data(Qt::UserRole).toUInt();
|
||||
Layer::ptr layer = mappingManager->getLayerById(layerId);
|
||||
layer->setVisible(item->checkState() == Qt::Checked);
|
||||
sourceCanvas->update();
|
||||
destinationCanvas->update();
|
||||
}
|
||||
|
||||
//void MainWindow::handleSourceSelectionChanged(const QItemSelection& selection)
|
||||
//{
|
||||
// std::cout << "selection changed" << std::endl;
|
||||
@@ -183,9 +185,10 @@ void MainWindow::addQuad()
|
||||
Shape::ptr inputQuad = Shape::ptr(Util::createQuadForTexture(texture.get(), sourceCanvas->width(), sourceCanvas->height()));
|
||||
|
||||
// Create texture mapping.
|
||||
uint mappingId = mappingManager->addMapping(Mapping::ptr(new TextureMapping(paint, outputQuad, inputQuad)));
|
||||
Mapping::ptr mapping(new TextureMapping(paint, outputQuad, inputQuad));
|
||||
mappingManager->addLayer(mapping);
|
||||
|
||||
addMappingItem(mappingId);
|
||||
addLayerItem(mapping->getId());
|
||||
}
|
||||
|
||||
void MainWindow::addTriangle()
|
||||
@@ -204,9 +207,10 @@ void MainWindow::addTriangle()
|
||||
Shape::ptr inputTriangle = Shape::ptr(Util::createTriangleForTexture(texture.get(), sourceCanvas->width(), sourceCanvas->height()));
|
||||
|
||||
// Create texture mapping.
|
||||
int mappingId = mappingManager->addMapping(Mapping::ptr(new TextureMapping(paint, inputTriangle, outputTriangle)));
|
||||
Mapping::ptr mapping(new TextureMapping(paint, inputTriangle, outputTriangle));
|
||||
mappingManager->addLayer(mapping);
|
||||
|
||||
addMappingItem(mappingId);
|
||||
addLayerItem(mapping->getId());
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
@@ -238,9 +242,9 @@ void MainWindow::createLayout()
|
||||
sourceList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
sourceList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
shapeList = new QListWidget;
|
||||
shapeList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
shapeList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
layerList = new QListWidget;
|
||||
layerList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
layerList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
sourceCanvas = new SourceGLCanvas;
|
||||
destinationCanvas = new DestinationGLCanvas(0, sourceCanvas);
|
||||
@@ -264,7 +268,7 @@ void MainWindow::createLayout()
|
||||
|
||||
resourceSplitter = new QSplitter(Qt::Horizontal);
|
||||
resourceSplitter->addWidget(sourceList);
|
||||
resourceSplitter->addWidget(shapeList);
|
||||
resourceSplitter->addWidget(layerList);
|
||||
|
||||
canvasSplitter = new QSplitter(Qt::Horizontal);
|
||||
canvasSplitter->addWidget(sourceCanvas);
|
||||
@@ -295,8 +299,11 @@ void MainWindow::createLayout()
|
||||
connect(sourceList, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(handleSourceItemSelectionChanged()));
|
||||
|
||||
connect(shapeList, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(handleShapeItemSelectionChanged()));
|
||||
connect(layerList, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(handleLayerItemSelectionChanged()));
|
||||
|
||||
connect(layerList, SIGNAL(itemChanged(QListWidgetItem*)),
|
||||
this, SLOT(handleLayerItemChanged(QListWidgetItem*)));
|
||||
// sourceList->setModel(sourcesModel);
|
||||
//
|
||||
// connect(sourceList->selectionModel(),
|
||||
@@ -580,10 +587,13 @@ bool MainWindow::importFile(const QString &fileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::addMappingItem(uint mappingId)
|
||||
void MainWindow::addLayerItem(uint layerId)
|
||||
{
|
||||
Mapping::ptr mapping = mappingManager->getMappingById(mappingId);
|
||||
Q_CHECK_PTR(mapping);
|
||||
Layer::ptr layer = mappingManager->getLayerById(layerId);
|
||||
Q_CHECK_PTR(layer);
|
||||
|
||||
Mapping::ptr mapping = layer->getMapping();
|
||||
uint mappingId = mapping->getId();
|
||||
|
||||
QString label;
|
||||
QIcon icon;
|
||||
@@ -607,11 +617,13 @@ void MainWindow::addMappingItem(uint mappingId)
|
||||
|
||||
// Add image to sourceList widget.
|
||||
QListWidgetItem* item = new QListWidgetItem(label);
|
||||
item->setData(Qt::UserRole, mappingId); // TODO: could possibly be replaced by a Paint pointer
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(Qt::Checked);
|
||||
item->setData(Qt::UserRole, layerId); // TODO: could possibly be replaced by a Paint pointer
|
||||
item->setIcon(icon);
|
||||
item->setSizeHint(QSize(item->sizeHint().width(), MainWindow::SHAPE_LIST_ITEM_HEIGHT));
|
||||
shapeList->addItem(item);
|
||||
shapeList->setCurrentItem(item);
|
||||
layerList->addItem(item);
|
||||
layerList->setCurrentItem(item);
|
||||
}
|
||||
|
||||
void MainWindow::clearWindow()
|
||||
|
||||
@@ -57,7 +57,8 @@ private slots:
|
||||
void updateStatusBar();
|
||||
|
||||
void handleSourceItemSelectionChanged();
|
||||
void handleShapeItemSelectionChanged();
|
||||
void handleLayerItemSelectionChanged();
|
||||
void handleLayerItemChanged(QListWidgetItem* item);
|
||||
void addQuad();
|
||||
void addTriangle();
|
||||
|
||||
@@ -78,7 +79,7 @@ private:
|
||||
bool saveFile(const QString &fileName);
|
||||
void setCurrentFile(const QString &fileName);
|
||||
bool importFile(const QString &fileName);
|
||||
void addMappingItem(uint mappingId);
|
||||
void addLayerItem(uint layerId);
|
||||
void clearWindow();
|
||||
QString strippedName(const QString &fullFileName);
|
||||
|
||||
@@ -112,7 +113,7 @@ private:
|
||||
QAction *addTriangleAction;
|
||||
|
||||
QListWidget* sourceList;
|
||||
QListWidget* shapeList;
|
||||
QListWidget* layerList;
|
||||
|
||||
SourceGLCanvas* sourceCanvas;
|
||||
DestinationGLCanvas* destinationCanvas;
|
||||
|
||||
@@ -79,10 +79,33 @@ uint MappingManager::addLayer(Mapping::ptr mapping)
|
||||
addMapping(mapping);
|
||||
Layer::ptr layer(new Layer);
|
||||
layer->setMapping(mapping);
|
||||
layers.push_back(layer);
|
||||
layerVector.push_back(layer);
|
||||
layerMap[layer->getId()] = layer;
|
||||
return layer->getId();
|
||||
}
|
||||
|
||||
std::vector<Layer::ptr> MappingManager::getVisibleLayers() const
|
||||
{
|
||||
std::vector<Layer::ptr> visible;
|
||||
bool hasSolo = false;
|
||||
for (std::vector<Layer::ptr>::const_iterator it = layerVector.begin(); it != layerVector.end(); ++it)
|
||||
{
|
||||
if ((*it)->isSolo())
|
||||
{
|
||||
hasSolo = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (std::vector<Layer::ptr>::const_iterator it = layerVector.begin(); it != layerVector.end(); ++it)
|
||||
{
|
||||
// Solo has priority over invisible (mute)
|
||||
if ( (hasSolo && (*it)->isSolo()) || (!hasSolo && (*it)->isVisible()) )
|
||||
visible.push_back(*it);
|
||||
}
|
||||
return visible;
|
||||
}
|
||||
|
||||
|
||||
//bool MappingManager::removeMapping(Mapping::ptr mapping)
|
||||
//{
|
||||
//}
|
||||
|
||||
@@ -40,7 +40,8 @@ private:
|
||||
std::vector<Mapping::ptr> mappingVector;
|
||||
std::map<uint, Mapping::ptr> mappingMap;
|
||||
|
||||
std::vector<Layer::ptr> layers;
|
||||
std::vector<Layer::ptr> layerVector;
|
||||
std::map<uint, Layer::ptr> layerMap;
|
||||
|
||||
public:
|
||||
/// Returns the list of mappings associated with given paint.
|
||||
@@ -61,9 +62,12 @@ public:
|
||||
Mapping::ptr getMapping(int i) { return mappingVector[i]; }
|
||||
Mapping::ptr getMappingById(uint id) { return mappingMap[id]; }
|
||||
|
||||
int nLayers() const { return layers.size(); }
|
||||
int nLayers() const { return layerVector.size(); }
|
||||
uint addLayer(Mapping::ptr mapping);
|
||||
Layer::ptr getLayer(int i) { return layers[i]; }
|
||||
Layer::ptr getLayer(int i) { return layerVector[i]; }
|
||||
Layer::ptr getLayerById(uint id) { return layerMap[id]; }
|
||||
|
||||
std::vector<Layer::ptr> getVisibleLayers() const;
|
||||
};
|
||||
|
||||
#endif /* MAPPINGMANAGER_H_ */
|
||||
|
||||
Reference in New Issue
Block a user