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

View file

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