mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Fix: #179 Paints and mappings renamings are now saved in file
This commit is contained in:
+39
-13
@@ -718,11 +718,11 @@ void MainWindow::deleteItem()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::cloneItem()
|
||||
void MainWindow::duplicateMappingItem()
|
||||
{
|
||||
if (currentSelectedItem)
|
||||
{
|
||||
cloneMappingItem(getItemId(*mappingList->currentItem()));
|
||||
duplicateMapping(getItemId(*mappingList->currentItem()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -747,17 +747,27 @@ void MainWindow::renameMappingItem()
|
||||
// Set current item editable and rename it
|
||||
QListWidgetItem* item = mappingList->currentItem();
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
// Used by context menu
|
||||
mappingList->editItem(item);
|
||||
// Switch to mapping tab.
|
||||
contentTab->setCurrentWidget(mappingSplitter);
|
||||
}
|
||||
|
||||
void MainWindow::renameMappingItem(uid mappingId, QString name)
|
||||
void MainWindow::renameMapping(uid mappingId, QString name)
|
||||
{
|
||||
if (mappingList->count() > 0) {
|
||||
mappingList->item(mappingId)->setText(name);
|
||||
Mapping::ptr mapping = mappingManager->getMappingById(mappingId);
|
||||
if (!mapping.isNull()) {
|
||||
getItemFromId(*mappingList, mappingId)->setText(name);
|
||||
mapping->setName(name);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::mappingListEditEnd(QWidget *editor)
|
||||
{
|
||||
QString name = reinterpret_cast<QLineEdit*>(editor)->text();
|
||||
renameMapping(getItemId(*mappingList->currentItem()), name);
|
||||
}
|
||||
|
||||
void MainWindow::deletePaintItem()
|
||||
{
|
||||
if(currentSelectedItem)
|
||||
@@ -775,17 +785,27 @@ void MainWindow::renamePaintItem()
|
||||
// Set current item editable and rename it
|
||||
QListWidgetItem* item = paintList->currentItem();
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
// Used by context menu
|
||||
paintList->editItem(item);
|
||||
// Switch to paint tab
|
||||
contentTab->setCurrentWidget(paintSplitter);
|
||||
}
|
||||
|
||||
void MainWindow::renamePaintItem(uid paintId, QString name)
|
||||
void MainWindow::renamePaint(uid paintId, QString name)
|
||||
{
|
||||
if (paintList->count() > 0) {
|
||||
paintList->item(paintId)->setText(name);
|
||||
Paint::ptr paint = mappingManager->getPaintById(paintId);
|
||||
if (!paint.isNull()) {
|
||||
getItemFromId(*paintList, paintId)->setText(name);
|
||||
paint->setName(name);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::paintListEditEnd(QWidget *editor)
|
||||
{
|
||||
QString name = reinterpret_cast<QLineEdit*>(editor)->text();
|
||||
renamePaint(getItemId(*paintList->currentItem()), name);
|
||||
}
|
||||
|
||||
void MainWindow::openRecentFile()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
@@ -1123,7 +1143,7 @@ void MainWindow::deleteMapping(uid mappingId)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::cloneMappingItem(uid mappingId)
|
||||
void MainWindow::duplicateMapping(uid mappingId)
|
||||
{
|
||||
// Current Mapping
|
||||
Mapping::ptr mappingPtr = mappingManager->getMappingById(mappingId);
|
||||
@@ -1430,7 +1450,7 @@ void MainWindow::createActions()
|
||||
cloneAction->setShortcut(tr("Ctrl+D"));
|
||||
cloneAction->setStatusTip(tr("Duplicate item"));
|
||||
cloneAction->setIconVisibleInMenu(false);
|
||||
connect(cloneAction, SIGNAL(triggered()), this, SLOT(cloneItem()));
|
||||
connect(cloneAction, SIGNAL(triggered()), this, SLOT(duplicateMappingItem()));
|
||||
|
||||
// Delete mapping.
|
||||
deleteMappingAction = new QAction(tr("Delete"), this);
|
||||
@@ -2462,6 +2482,12 @@ void MainWindow::connectProjectWidgets()
|
||||
|
||||
connect(paintList, SIGNAL(itemActivated(QListWidgetItem*)),
|
||||
this, SLOT(handleItemSelected(QListWidgetItem*)));
|
||||
// Rename Paint with double click
|
||||
connect(paintList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(renamePaintItem()));
|
||||
// When finish to edit mapping item
|
||||
connect(paintList->itemDelegate(), SIGNAL(commitData(QWidget*)),
|
||||
this, SLOT(paintListEditEnd(QWidget*)));
|
||||
|
||||
connect(mappingList, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(handleMappingItemSelectionChanged()));
|
||||
@@ -2483,9 +2509,9 @@ void MainWindow::connectProjectWidgets()
|
||||
// Rename mapping with double click
|
||||
connect(mappingList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(renameMappingItem()));
|
||||
// Rename Paint with double click
|
||||
connect(paintList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(renamePaintItem()));
|
||||
// When finish to edit mapping item
|
||||
connect(mappingList->itemDelegate(), SIGNAL(commitData(QWidget*)),
|
||||
this, SLOT(mappingListEditEnd(QWidget*)));
|
||||
}
|
||||
|
||||
void MainWindow::disconnectProjectWidgets()
|
||||
|
||||
+6
-4
@@ -93,12 +93,14 @@ private slots:
|
||||
// Edit menu.
|
||||
void deleteItem();
|
||||
// Context menu for mappings.
|
||||
void cloneItem();
|
||||
void duplicateMappingItem();
|
||||
void deleteMappingItem();
|
||||
void renameMappingItem();
|
||||
void mappingListEditEnd(QWidget* editor);
|
||||
// Context menu for paints
|
||||
void deletePaintItem();
|
||||
void renamePaintItem();
|
||||
void paintListEditEnd(QWidget* editor);
|
||||
|
||||
// Widget callbacks.
|
||||
void handlePaintItemSelectionChanged();
|
||||
@@ -179,7 +181,7 @@ public slots:
|
||||
void deleteMapping(uid mappingId);
|
||||
|
||||
/// Clone/duplicate a mapping
|
||||
void cloneMappingItem(uid mappingId);
|
||||
void duplicateMapping(uid mappingId);
|
||||
|
||||
/// Deletes/removes a paint and all associated mappigns.
|
||||
void deletePaint(uid paintId, bool replace);
|
||||
@@ -240,8 +242,8 @@ public:
|
||||
void addPaintItem(uid paintId, const QIcon& icon, const QString& name);
|
||||
void updatePaintItem(uid paintId, const QIcon& icon, const QString& name);
|
||||
void removePaintItem(uid paintId);
|
||||
void renameMappingItem(uid mappingId, QString name);
|
||||
void renamePaintItem(uid paintId, QString name);
|
||||
void renameMapping(uid mappingId, QString name);
|
||||
void renamePaint(uid paintId, QString name);
|
||||
void clearWindow();
|
||||
// Check if the file exists
|
||||
bool fileExists(const QString file);
|
||||
|
||||
@@ -59,6 +59,9 @@ private:
|
||||
float _opacity;
|
||||
int _depth; // depth of the layer
|
||||
|
||||
// Mapping name
|
||||
QString _name;
|
||||
|
||||
protected:
|
||||
/// Constructor.
|
||||
Mapping(Paint::ptr paint, MShape::ptr shape, uid id=NULL_UID);
|
||||
@@ -118,6 +121,10 @@ public:
|
||||
float getOpacity() const { return _opacity * _paint->getOpacity(); }
|
||||
|
||||
void setPaint(Paint::ptr p) { _paint = p; }
|
||||
// Set mapping name
|
||||
void setName(const QString& name) { _name = name; }
|
||||
// Get mapping name
|
||||
QString getName() const { return _name; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -211,13 +211,13 @@ void OscInterface::applyOscCommand(MainWindow &main_window, QVariantList & comma
|
||||
{
|
||||
int mappingId = command.at(2).toInt();
|
||||
QString mappingName = command.at(3).toString();
|
||||
main_window.renameMappingItem(mappingId, mappingName);
|
||||
main_window.renameMapping(mappingId, mappingName);
|
||||
}
|
||||
else if (path == "/mapmap/paint/media/rename" && typetags == "is")
|
||||
{
|
||||
int paintId = command.at(2).toInt();
|
||||
QString paintName = command.at(3).toString();
|
||||
main_window.renamePaintItem(paintId, paintName);
|
||||
main_window.renamePaint(paintId, paintName);
|
||||
}
|
||||
else if (path == "/mapmap/quit")
|
||||
{
|
||||
|
||||
@@ -100,6 +100,10 @@ void ProjectReader::parsePaint(const QDomElement& paint)
|
||||
uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat(), paintAttrType == "image", false, rate.toDouble());
|
||||
if (id == NULL_UID)
|
||||
_xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri));
|
||||
|
||||
// Restore Paint name
|
||||
if (!paintAttrName.isEmpty())
|
||||
_window->renamePaint(id, paintAttrName);
|
||||
}
|
||||
else if (paintAttrType == "color")
|
||||
{
|
||||
@@ -110,6 +114,9 @@ void ProjectReader::parsePaint(const QDomElement& paint)
|
||||
if (id == NULL_UID)
|
||||
_xml.raiseError(QObject::tr("Cannot create color with RGB hex code %1.").arg(rgb));
|
||||
|
||||
// Restore Paint name
|
||||
if (!paintAttrName.isEmpty())
|
||||
_window->renamePaint(id, paintAttrName);
|
||||
}
|
||||
else
|
||||
_xml.raiseError(QObject::tr("Unsupported paint type: %1.").arg(paintAttrType));
|
||||
@@ -120,6 +127,7 @@ void ProjectReader::parseMapping(const QDomElement& mapping)
|
||||
{
|
||||
uid id = NULL_UID;
|
||||
QString mappingAttrId = mapping.attribute("id", QString::number(NULL_UID));
|
||||
QString mappingAttrName = mapping.attribute("name", "");
|
||||
QString mappingAttrPaintId = mapping.attribute("paint_id", QString::number(NULL_UID));
|
||||
QString mappingAttrType = mapping.attribute("type", "");
|
||||
|
||||
@@ -218,6 +226,8 @@ void ProjectReader::parseMapping(const QDomElement& mapping)
|
||||
_window->setMappingVisible(id, isVisible);
|
||||
_window->setMappingSolo (id, isSolo);
|
||||
_window->setMappingLocked (id, isLocked);
|
||||
if (!mappingAttrName.isEmpty())
|
||||
_window->renameMapping(id, mappingAttrName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -54,7 +54,7 @@ void ProjectWriter::writeItem(Paint *item)
|
||||
{
|
||||
_xml.writeStartElement("paint");
|
||||
_xml.writeAttribute("id", QString::number(item->getId()));
|
||||
//_xml.writeAttribute("name", item->getName());
|
||||
_xml.writeAttribute("name", item->getName());
|
||||
_xml.writeAttribute("type", item->getType());
|
||||
|
||||
if (item->getType() == "media")
|
||||
@@ -142,6 +142,7 @@ void ProjectWriter::writeItem(Mapping *item)
|
||||
_xml.writeStartElement("mapping");
|
||||
qDebug() << "ID: " << item->getId() << endl;
|
||||
_xml.writeAttribute("id", QString::number(item->getId()));
|
||||
_xml.writeAttribute("name", item->getName());
|
||||
_xml.writeAttribute("paint_id", QString::number(item->getPaint()->getId()));
|
||||
_xml.writeAttribute("type", item->getType());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user