Smaller fixes and added Qt5 support

This commit is contained in:
feedc0de committed 2022-01-15 06:35:21 +01:00
1 parent 25e522fd8a
commit 9135c2f20c
20 files changed
+498 -58

No files matched your search

+69 -9
View File
@@ -92,9 +92,32 @@ bool ObjectEventsModel::addEvent(Object::EventType eventType)
return false;
}
beginResetModel();
m_events[eventType];
endResetModel();
// temporary copy to find row before inserting, as its needed for beginInsertRows()
auto tempevents = m_events;
const auto &tempInsertResult = tempevents.insert(std::make_pair(eventType, ActionsContainer{}));
if (!tempInsertResult.second)
{
qWarning() << "temp inserting failed!";
return false;
}
const auto tempNewRow = std::distance(std::begin(tempevents), tempInsertResult.first);
beginInsertRows({}, tempNewRow, tempNewRow);
const auto &insertResult = m_events.insert(std::make_pair(eventType, ActionsContainer{}));
if (!insertResult.second)
{
qWarning() << "inserting failed!";
return false;
}
const auto newRow = std::distance(std::begin(m_events), insertResult.first);
Q_ASSERT(tempNewRow == newRow);
endInsertRows();
return true;
}
@@ -108,11 +131,46 @@ bool ObjectEventsModel::changeEvent(Object::EventType eventType, Object::EventTy
return false;
}
beginResetModel();
auto value = std::move(iter->second);
if (eventType == newEventType)
{
qWarning() << "same event again";
return true;
}
auto container = std::move(iter->second);
const auto oldRow = std::distance(std::begin(m_events), iter);
beginRemoveRows({}, oldRow, oldRow);
m_events.erase(iter);
m_events[newEventType] = std::move(value);
endResetModel();
endRemoveRows();
// temporary copy to find row before inserting, as its needed for beginInsertRows()
auto tempevents = m_events;
const auto &tempInsertResult = tempevents.insert(std::make_pair(newEventType, ActionsContainer{}));
if (!tempInsertResult.second)
{
qWarning() << "temp inserting failed!";
return false;
}
const auto tempNewRow = std::distance(std::begin(tempevents), tempInsertResult.first);
beginInsertRows({}, tempNewRow, tempNewRow);
const auto &insertResult = m_events.insert(std::make_pair(newEventType, std::move(container)));
if (!insertResult.second)
{
qWarning() << "inserting failed!";
return false;
}
const auto newRow = std::distance(std::begin(m_events), insertResult.first);
Q_ASSERT(tempNewRow == newRow);
endInsertRows();
return true;
}
@@ -126,9 +184,11 @@ bool ObjectEventsModel::removeEvent(Object::EventType eventType)
return false;
}
beginResetModel();
const auto row = std::distance(std::begin(m_events), iter);
beginRemoveRows({}, row, row);
m_events.erase(iter);
endResetModel();
endRemoveRows();
return true;
}
+1
View File
@@ -3,6 +3,7 @@
#include <QAbstractTableModel>
#include <vector>
#include <optional>
#include "projectcontainer.h"
+31
View File
@@ -660,6 +660,37 @@ bool ProjectTreeModel::setBackgroundPixmap(const Background &background, QPixmap
return true;
}
bool ProjectTreeModel::setObjectSpriteName(const Object &object, QString &&spriteName)
{
if (!m_project)
{
qWarning() << "unexpected null project";
return false;
}
auto &container = m_project->objects;
const auto iter = std::find_if(std::begin(container), std::end(container),
[&object](const auto &otherEntry){ return &object == &otherEntry; });
if (iter == std::cend(container))
{
qWarning() << "object not from this project!";
return false;
}
if (iter->spriteName == spriteName)
return true;
auto oldSpriteName = std::move(iter->spriteName);
iter->spriteName = std::move(spriteName);
const auto index = this->index(std::distance(std::begin(container), iter), 0, rootFor<Object>());
emit dataChanged(index, index, { Qt::DecorationRole });
emit objectSpriteNameChanged(object, std::move(oldSpriteName));
return true;
}
template<typename T>
QVariant ProjectTreeModel::dataFor(const QModelIndex &index, int role) const
{
+11 -9
View File
@@ -73,6 +73,8 @@ public:
bool setBackgroundPixmap(const Background &background, QPixmap &&pixmap);
bool setObjectSpriteName(const Object &object, QString &&spriteName);
signals:
void errorOccured(const QString &message);
@@ -82,9 +84,9 @@ signals:
void pathCreated(const Path &path);
void scriptCreated(const Script &script);
void fontCreated(const Font &font);
void timeLineCreated(const TimeLine &font);
void objectCreated(const Object &font);
void roomCreated(const Room &font);
void timeLineCreated(const TimeLine &timeLine);
void objectCreated(const Object &object);
void roomCreated(const Room &room);
void spriteAboutToBeRemoved(const Sprite &sprite);
void soundAboutToBeRemoved(const Sound &sound);
@@ -92,9 +94,9 @@ signals:
void pathAboutToBeRemoved(const Path &path);
void scriptAboutToBeRemoved(const Script &script);
void fontAboutToBeRemoved(const Font &font);
void timeLineAboutToBeRemoved(const TimeLine &font);
void objectAboutToBeRemoved(const Object &font);
void roomAboutToBeRemoved(const Room &font);
void timeLineAboutToBeRemoved(const TimeLine &timeLine);
void objectAboutToBeRemoved(const Object &object);
void roomAboutToBeRemoved(const Room &room);
void spriteNameChanged(const Sprite &sprite, const QString &oldName);
void soundNameChanged(const Sound &sound, const QString &oldName);
@@ -102,9 +104,9 @@ signals:
void pathNameChanged(const Path &path, const QString &oldName);
void scriptNameChanged(const Script &script, const QString &oldName);
void fontNameChanged(const Font &font, const QString &oldName);
void timeLineNameChanged(const TimeLine &font, const QString &oldName);
void objectNameChanged(const Object &font, const QString &oldName);
void roomNameChanged(const Room &font, const QString &oldName);
void timeLineNameChanged(const TimeLine &timeLine, const QString &oldName);
void objectNameChanged(const Object &object, const QString &oldName);
void roomNameChanged(const Room &room, const QString &oldName);
void spritePixmapsChanged(const Sprite &sprite);