fix preview scene memory leak, fix borders

This commit is contained in:
garak 2019-05-22 18:28:50 -04:00 committed by huderlem
parent f750c56e29
commit 8f2e47e937
2 changed files with 20 additions and 19 deletions

View file

@ -33,7 +33,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>337</width>
<width>373</width>
<height>334</height>
</rect>
</property>
@ -123,33 +123,20 @@
<layout class="QVBoxLayout" name="verticalLayout_Options">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Map</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_MapSelection">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
@ -275,6 +262,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>

View file

@ -23,6 +23,7 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_) :
}
MapImageExporter::~MapImageExporter() {
delete scene;
delete ui;
}
@ -31,7 +32,7 @@ void MapImageExporter::saveImage() {
QString filepath = QFileDialog::getSaveFileName(this, "Export Map Image", defaultFilepath,
"Image Files (*.png *.jpg *.bmp)");
if (!filepath.isEmpty()) {
this->ui->graphicsView_Preview->grab(this->ui->graphicsView_Preview->sceneRect().toRect()).save(filepath);
this->preview.save(filepath);
this->close();
}
}
@ -67,8 +68,8 @@ void MapImageExporter::updatePreview() {
// draw map border
// note: this will break when allowing map to be selected from drop down maybe
int borderHeight = 0, borderWidth = 0;
if (showUpConnections || showDownConnections || showLeftConnections || showRightConnections) showBorder = true;
if (showBorder) {
bool forceDrawBorder = showUpConnections || showDownConnections || showLeftConnections || showRightConnections;
if (showBorder || forceDrawBorder) {
borderHeight = 32 * 3, borderWidth = 32 * 3;
QPixmap newPreview = QPixmap(map->pixmap.width() + borderWidth * 2, map->pixmap.height() + borderHeight * 2);
QPainter borderPainter(&newPreview);