fix multi event deletion crash, allow spinboxes to commit move history
This commit is contained in:
parent
2598ca2277
commit
4c154501f1
6 changed files with 60 additions and 32 deletions
|
@ -23,13 +23,12 @@ enum CommandId {
|
||||||
ID_EventCreate, // - done
|
ID_EventCreate, // - done
|
||||||
ID_EventDelete, // - done
|
ID_EventDelete, // - done
|
||||||
ID_EventSetData, // - ?
|
ID_EventSetData, // - ?
|
||||||
// Tileset editor history commands
|
|
||||||
// Region map editor history commands
|
// Region map editor history commands
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// TODO
|
///
|
||||||
class PaintMetatile : public QUndoCommand {
|
class PaintMetatile : public QUndoCommand {
|
||||||
public:
|
public:
|
||||||
PaintMetatile(Map *map,
|
PaintMetatile(Map *map,
|
||||||
|
@ -233,7 +232,7 @@ private:
|
||||||
///
|
///
|
||||||
class EventDelete : public QUndoCommand {
|
class EventDelete : public QUndoCommand {
|
||||||
public:
|
public:
|
||||||
EventDelete(Editor *editor, Map *map, Event *event,
|
EventDelete(Editor *editor, Map *map, QList<Event *> selectedEvents,
|
||||||
QUndoCommand *parent = nullptr);
|
QUndoCommand *parent = nullptr);
|
||||||
~EventDelete();
|
~EventDelete();
|
||||||
|
|
||||||
|
@ -245,7 +244,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Map *map;
|
Map *map;
|
||||||
Event *event;
|
QList<Event *> selectedEvents; // allow multiple deletion of events
|
||||||
Editor *editor;
|
Editor *editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -99,15 +99,8 @@ public:
|
||||||
bool hFlip = false;
|
bool hFlip = false;
|
||||||
bool usingSprite;
|
bool usingSprite;
|
||||||
|
|
||||||
void activate() { active = true; }
|
|
||||||
void deactivate() { active = false; }
|
|
||||||
bool isActive() { return active; }
|
|
||||||
|
|
||||||
DraggablePixmapItem *pixmapItem = nullptr;
|
DraggablePixmapItem *pixmapItem = nullptr;
|
||||||
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
|
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
|
||||||
|
|
||||||
private:
|
|
||||||
bool active = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EVENT_H
|
#endif // EVENT_H
|
||||||
|
|
|
@ -10,6 +10,9 @@ class NoScrollSpinBox : public QSpinBox
|
||||||
public:
|
public:
|
||||||
explicit NoScrollSpinBox(QWidget *parent = nullptr);
|
explicit NoScrollSpinBox(QWidget *parent = nullptr);
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
|
|
||||||
|
unsigned getActionId();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,6 @@ void PaintMetatile::undo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaintMetatile::mergeWith(const QUndoCommand *command) {
|
bool PaintMetatile::mergeWith(const QUndoCommand *command) {
|
||||||
// does an up merge
|
|
||||||
const PaintMetatile *other = static_cast<const PaintMetatile *>(command);
|
const PaintMetatile *other = static_cast<const PaintMetatile *>(command);
|
||||||
|
|
||||||
if (this->map != other->map)
|
if (this->map != other->map)
|
||||||
|
@ -312,6 +311,8 @@ bool EventMove::mergeWith(const QUndoCommand *command) {
|
||||||
if (actionId != other->actionId)
|
if (actionId != other->actionId)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// TODO: check that same events as well?
|
||||||
|
|
||||||
this->deltaX += other->deltaX;
|
this->deltaX += other->deltaX;
|
||||||
this->deltaY += other->deltaY;
|
this->deltaY += other->deltaY;
|
||||||
|
|
||||||
|
@ -360,7 +361,6 @@ void EventCreate::redo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventCreate::undo() {
|
void EventCreate::undo() {
|
||||||
//
|
|
||||||
map->removeEvent(event);
|
map->removeEvent(event);
|
||||||
|
|
||||||
if (editor->scene->items().contains(event->pixmapItem)) {
|
if (editor->scene->items().contains(event->pixmapItem)) {
|
||||||
|
@ -368,6 +368,8 @@ void EventCreate::undo() {
|
||||||
}
|
}
|
||||||
editor->selected_events->removeOne(event->pixmapItem);
|
editor->selected_events->removeOne(event->pixmapItem);
|
||||||
|
|
||||||
|
editor->updateSelectedEvents();
|
||||||
|
|
||||||
map->objectsChanged();
|
map->objectsChanged();
|
||||||
|
|
||||||
QUndoCommand::undo();
|
QUndoCommand::undo();
|
||||||
|
@ -377,15 +379,18 @@ void EventCreate::undo() {
|
||||||
************************************************************************
|
************************************************************************
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
EventDelete::EventDelete(Editor *editor, Map *map, Event *event,
|
EventDelete::EventDelete(Editor *editor, Map *map, QList<Event *> selectedEvents,
|
||||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||||
//
|
if (selectedEvents.size() > 1) {
|
||||||
setText("Delete Event");
|
setText("Delete Events");
|
||||||
|
} else {
|
||||||
|
setText("Delete Event");
|
||||||
|
}
|
||||||
|
|
||||||
this->editor = editor;
|
this->editor = editor;
|
||||||
|
|
||||||
this->map = map;
|
this->map = map;
|
||||||
this->event = event;
|
this->selectedEvents = selectedEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDelete::~EventDelete() {}
|
EventDelete::~EventDelete() {}
|
||||||
|
@ -393,22 +398,25 @@ EventDelete::~EventDelete() {}
|
||||||
void EventDelete::redo() {
|
void EventDelete::redo() {
|
||||||
QUndoCommand::redo();
|
QUndoCommand::redo();
|
||||||
|
|
||||||
map->removeEvent(event);
|
for (Event *event : selectedEvents) {
|
||||||
|
map->removeEvent(event);
|
||||||
|
|
||||||
if (editor->scene->items().contains(event->pixmapItem)) {
|
if (editor->scene->items().contains(event->pixmapItem)) {
|
||||||
editor->scene->removeItem(event->pixmapItem);
|
editor->scene->removeItem(event->pixmapItem);
|
||||||
|
}
|
||||||
|
editor->selected_events->removeOne(event->pixmapItem);
|
||||||
}
|
}
|
||||||
editor->selected_events->removeOne(event->pixmapItem);
|
|
||||||
|
|
||||||
map->objectsChanged();
|
map->objectsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDelete::undo() {
|
void EventDelete::undo() {
|
||||||
//
|
for (Event *event : selectedEvents) {
|
||||||
map->addEvent(event);
|
map->addEvent(event);
|
||||||
|
|
||||||
editor->project->loadEventPixmaps(map->getAllEvents());
|
editor->project->loadEventPixmaps(map->getAllEvents());
|
||||||
editor->addMapEvent(event);
|
editor->addMapEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
map->objectsChanged();
|
map->objectsChanged();
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,11 @@ void MainWindow::initEditor() {
|
||||||
undoView->setWindowTitle(tr("Edit History"));
|
undoView->setWindowTitle(tr("Edit History"));
|
||||||
undoView->show();
|
undoView->show();
|
||||||
undoView->setAttribute(Qt::WA_QuitOnClose, false);
|
undoView->setAttribute(Qt::WA_QuitOnClose, false);
|
||||||
|
|
||||||
|
//ui->comboBox_History->setMinimumContentsLength(20);
|
||||||
|
//ui->comboBox_History->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
||||||
|
//ui->comboBox_History->setModel(undoView->model());
|
||||||
|
//ui->comboBox_History->setView(undoView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initMiscHeapObjects() {
|
void MainWindow::initMiscHeapObjects() {
|
||||||
|
@ -1448,7 +1453,6 @@ void MainWindow::addNewEvent(QString event_type)
|
||||||
if (editor && editor->project) {
|
if (editor && editor->project) {
|
||||||
DraggablePixmapItem *object = editor->addNewEvent(event_type);
|
DraggablePixmapItem *object = editor->addNewEvent(event_type);
|
||||||
if (object) {
|
if (object) {
|
||||||
updateObjects();
|
|
||||||
editor->selectMapEvent(object, false);
|
editor->selectMapEvent(object, false);
|
||||||
} else {
|
} else {
|
||||||
QMessageBox msgBox(this);
|
QMessageBox msgBox(this);
|
||||||
|
@ -1557,16 +1561,24 @@ void MainWindow::updateSelectedObjects() {
|
||||||
EventPropertiesFrame *frame = new EventPropertiesFrame(item->event);
|
EventPropertiesFrame *frame = new EventPropertiesFrame(item->event);
|
||||||
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
|
||||||
QSpinBox *x = frame->ui->spinBox_x;
|
NoScrollSpinBox *x = frame->ui->spinBox_x;
|
||||||
QSpinBox *y = frame->ui->spinBox_y;
|
NoScrollSpinBox *y = frame->ui->spinBox_y;
|
||||||
QSpinBox *z = frame->ui->spinBox_z;
|
NoScrollSpinBox *z = frame->ui->spinBox_z;
|
||||||
|
|
||||||
x->setValue(item->event->x());
|
x->setValue(item->event->x());
|
||||||
connect(x, SIGNAL(valueChanged(QString)), item, SLOT(set_x(QString)));
|
connect(x, QOverload<int>::of(&QSpinBox::valueChanged), [this, item, x](int value) {
|
||||||
|
int delta = value - item->event->x();
|
||||||
|
if (delta)
|
||||||
|
editor->map->editHistory.push(new EventMove(QList<Event *>() << item->event, delta, 0, x->getActionId()));
|
||||||
|
});
|
||||||
connect(item, SIGNAL(xChanged(int)), x, SLOT(setValue(int)));
|
connect(item, SIGNAL(xChanged(int)), x, SLOT(setValue(int)));
|
||||||
|
|
||||||
y->setValue(item->event->y());
|
y->setValue(item->event->y());
|
||||||
connect(y, SIGNAL(valueChanged(QString)), item, SLOT(set_y(QString)));
|
connect(y, QOverload<int>::of(&QSpinBox::valueChanged), [this, item, y](int value) {
|
||||||
|
int delta = value - item->event->y();
|
||||||
|
if (delta)
|
||||||
|
editor->map->editHistory.push(new EventMove(QList<Event *>() << item->event, 0, delta, y->getActionId()));
|
||||||
|
});
|
||||||
connect(item, SIGNAL(yChanged(int)), y, SLOT(setValue(int)));
|
connect(item, SIGNAL(yChanged(int)), y, SLOT(setValue(int)));
|
||||||
|
|
||||||
z->setValue(item->event->elevation());
|
z->setValue(item->event->elevation());
|
||||||
|
@ -2102,6 +2114,7 @@ void MainWindow::on_toolButton_deleteObject_clicked()
|
||||||
if (editor && editor->selected_events) {
|
if (editor && editor->selected_events) {
|
||||||
if (editor->selected_events->length()) {
|
if (editor->selected_events->length()) {
|
||||||
DraggablePixmapItem *next_selected_event = nullptr;
|
DraggablePixmapItem *next_selected_event = nullptr;
|
||||||
|
QList<Event *> selectedEvents;
|
||||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
QString event_group = item->event->get("event_group_type");
|
QString event_group = item->event->get("event_group_type");
|
||||||
if (event_group != "heal_event_group") {
|
if (event_group != "heal_event_group") {
|
||||||
|
@ -2125,12 +2138,14 @@ void MainWindow::on_toolButton_deleteObject_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor->map->editHistory.push(new EventDelete(editor, editor->map, item->event));
|
item->event->setPixmapItem(item);
|
||||||
|
selectedEvents.append(item->event);
|
||||||
}
|
}
|
||||||
else { // don't allow deletion of heal locations
|
else { // don't allow deletion of heal locations
|
||||||
logWarn(QString("Cannot delete event of type '%1'").arg(item->event->get("event_type")));
|
logWarn(QString("Cannot delete event of type '%1'").arg(item->event->get("event_type")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
editor->map->editHistory.push(new EventDelete(editor, editor->map, selectedEvents));
|
||||||
if (next_selected_event) {
|
if (next_selected_event) {
|
||||||
editor->selectMapEvent(next_selected_event);
|
editor->selectMapEvent(next_selected_event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "noscrollspinbox.h"
|
#include "noscrollspinbox.h"
|
||||||
|
|
||||||
|
unsigned actionId = 0xffff;
|
||||||
|
|
||||||
NoScrollSpinBox::NoScrollSpinBox(QWidget *parent)
|
NoScrollSpinBox::NoScrollSpinBox(QWidget *parent)
|
||||||
: QSpinBox(parent)
|
: QSpinBox(parent)
|
||||||
{
|
{
|
||||||
|
@ -14,3 +16,11 @@ void NoScrollSpinBox::wheelEvent(QWheelEvent *event)
|
||||||
QSpinBox::wheelEvent(event);
|
QSpinBox::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NoScrollSpinBox::focusOutEvent(QFocusEvent *event) {
|
||||||
|
actionId++;
|
||||||
|
QSpinBox::focusOutEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned NoScrollSpinBox::getActionId() {
|
||||||
|
return actionId;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue