Skip to content

Commit

Permalink
fix crash in editors, enable close in editors, disable expanding inst…
Browse files Browse the repository at this point in the history
…ance to prevent crash on dbl click, force the room editor to constantly redraw
  • Loading branch information
fundies committed Nov 22, 2019
1 parent 78adb67 commit bf3d6be
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 15 deletions.
7 changes: 2 additions & 5 deletions Editors/BackgroundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ BackgroundEditor::BackgroundEditor(ProtoModel* model, QWidget* parent)
: BaseEditor(model, parent), ui(new Ui::BackgroundEditor) {
ui->setupUi(this);

connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);

ui->backgroundView->SetResourceModel(resMapper->GetModel());

resMapper->addMapping(ui->smoothCheckBox, Background::kSmoothEdgesFieldNumber);
Expand All @@ -40,11 +42,6 @@ void BackgroundEditor::dataChanged(const QModelIndex& topLeft, const QModelIndex
ui->backgroundView->update();
}

void BackgroundEditor::on_actionSave_triggered() {
resMapper->SetDirty(false);
this->parentWidget()->close();
}

void BackgroundEditor::on_actionZoomIn_triggered() {
ui->backgroundView->SetZoom(ui->backgroundView->GetZoom() * 2);
}
Expand Down
1 change: 0 additions & 1 deletion Editors/BackgroundEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BackgroundEditor : public BaseEditor {
private slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVariant &oldValue = QVariant(0),
const QVector<int> &roles = QVector<int>()) override;
void on_actionSave_triggered();
void on_actionZoomIn_triggered();
void on_actionZoomOut_triggered();
void on_actionZoom_triggered();
Expand Down
7 changes: 6 additions & 1 deletion Editors/BaseEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void BaseEditor::closeEvent(QCloseEvent* event) {
return;
} else if (reply == QMessageBox::No) {
nodeMapper->clearMapping();
nodeMapper->RestoreBuffer();
resMapper->RestoreBuffer();
resMapper->clearMapping();
}
}
Expand All @@ -45,3 +45,8 @@ void BaseEditor::dataChanged(const QModelIndex& topLeft, const QModelIndex& /*bo
emit ResourceRenamed(n->type_case(), oldValue.toString(), QString::fromStdString(n->name()));
}
}

void BaseEditor::OnSave() {
resMapper->SetDirty(false);
this->parentWidget()->close();
}
1 change: 1 addition & 0 deletions Editors/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class BaseEditor : public QWidget {
public slots:
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVariant &oldValue = QVariant(0), const QVector<int> &roles = QVector<int>());
void OnSave();

protected:
ModelMapper *nodeMapper;
Expand Down
2 changes: 2 additions & 0 deletions Editors/CodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
CodeEditor::CodeEditor(ProtoModel *model, QWidget *parent) : BaseEditor(model, parent), ui(new Ui::CodeEditor) {
ui->setupUi(this);

connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);

cursorPositionLabel = new QLabel(ui->statusBar);
lineCountLabel = new QLabel(ui->statusBar);

Expand Down
1 change: 1 addition & 0 deletions Editors/FontEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

FontEditor::FontEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::FontEditor) {
ui->setupUi(this);
connect(ui->saveButton, &QAbstractButton::pressed, this, &BaseEditor::OnSave);
}

FontEditor::~FontEditor() { delete ui; }
1 change: 1 addition & 0 deletions Editors/ObjectEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

ObjectEditor::ObjectEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::ObjectEditor) {
ui->setupUi(this);
connect(ui->saveButton, &QAbstractButton::pressed, this, &BaseEditor::OnSave);
}

ObjectEditor::~ObjectEditor() { delete ui; }
1 change: 1 addition & 0 deletions Editors/PathEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

PathEditor::PathEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::PathEditor) {
ui->setupUi(this);
connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);
}

PathEditor::~PathEditor() { delete ui; }
2 changes: 2 additions & 0 deletions Editors/RoomEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#include <QMouseEvent>

#include <algorithm>
#include <QDebug>

using View = buffers::resources::Room::View;

RoomEditor::RoomEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::RoomEditor) {
ui->setupUi(this);
connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);

ProtoModel* roomModel = model->GetSubModel(TreeNode::kRoomFieldNumber);
ui->roomView->SetResourceModel(roomModel);
Expand Down
21 changes: 15 additions & 6 deletions Editors/RoomEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -207,10 +216,10 @@
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<attribute name="horizontalHeaderMinimumSectionSize">
<number>24</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<attribute name="horizontalHeaderDefaultSectionSize">
<number>24</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
Expand All @@ -219,10 +228,10 @@
<attribute name="verticalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<attribute name="verticalHeaderMinimumSectionSize">
<number>24</number>
</attribute>
<attribute name="verticalHeaderMinimumSectionSize">
<attribute name="verticalHeaderDefaultSectionSize">
<number>24</number>
</attribute>
</widget>
Expand Down Expand Up @@ -1278,8 +1287,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>694</width>
<height>569</height>
<width>712</width>
<height>572</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down
1 change: 1 addition & 0 deletions Editors/SoundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

SoundEditor::SoundEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::SoundEditor) {
ui->setupUi(this);
connect(ui->saveButton, &QAbstractButton::pressed, this, &BaseEditor::OnSave);
}

SoundEditor::~SoundEditor() { delete ui; }
2 changes: 2 additions & 0 deletions Editors/SpriteEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
SpriteEditor::SpriteEditor(ProtoModel* model, QWidget* parent) : BaseEditor(model, parent), ui(new Ui::SpriteEditor) {
ui->setupUi(this);

connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);

spriteModel =
new SpriteModel(static_cast<buffers::resources::Sprite*>(model->GetSubModel(TreeNode::kSpriteFieldNumber)->GetBuffer())->mutable_subimages(), this);

Expand Down
4 changes: 2 additions & 2 deletions Editors/SpriteEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>608</width>
<height>311</height>
<width>631</width>
<height>312</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down
2 changes: 2 additions & 0 deletions Widgets/RoomView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void RoomView::paintEvent(QPaintEvent* /* event */) {
this->paintInstances(painter, room);
this->paintBackgrounds(painter, room, true);
this->paintGrid(painter, room);

update(); // request repaint constantly
}

void RoomView::paintTiles(QPainter& painter, Room* room) {
Expand Down

0 comments on commit bf3d6be

Please sign in to comment.