Skip to content

Commit 4ed5d9a

Browse files
committed
plot: add a button to save the current plot as different file formats
1 parent e3db2fc commit 4ed5d9a

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/MainWindow.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,3 +1562,32 @@ void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *changeitem, int
15621562
}
15631563
updatePlot(m_currentPlotModel, false);
15641564
}
1565+
1566+
void MainWindow::on_butSavePlot_clicked()
1567+
{
1568+
QString fileName = QFileDialog::getSaveFileName(this, tr("Choose a filename to save under"));
1569+
if(!fileName.isEmpty())
1570+
{
1571+
if(fileName.endsWith(".png", Qt::CaseInsensitive))
1572+
{
1573+
ui->plotWidget->savePng(fileName);
1574+
}
1575+
else if(fileName.endsWith(".jpg", Qt::CaseInsensitive))
1576+
{
1577+
ui->plotWidget->saveJpg(fileName);
1578+
}
1579+
else if(fileName.endsWith(".pdf", Qt::CaseInsensitive))
1580+
{
1581+
ui->plotWidget->savePdf(fileName);
1582+
}
1583+
else if(fileName.endsWith(".bmp", Qt::CaseInsensitive))
1584+
{
1585+
ui->plotWidget->saveBmp(fileName);
1586+
}
1587+
else
1588+
{
1589+
fileName += ".png";
1590+
ui->plotWidget->savePng(fileName);
1591+
}
1592+
}
1593+
}

src/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private slots:
167167
virtual void httpresponse(QNetworkReply* reply);
168168
virtual void updatePlot(SqliteTableModel* model, bool update = true);
169169
void on_treePlotColumns_itemChanged(QTreeWidgetItem *item, int column);
170+
void on_butSavePlot_clicked();
170171
};
171172

172173
#endif

src/MainWindow.ui

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,66 @@
997997
</widget>
998998
</widget>
999999
</item>
1000+
<item>
1001+
<widget class="QWidget" name="widget" native="true">
1002+
<layout class="QHBoxLayout" name="horizontalLayout_4">
1003+
<property name="leftMargin">
1004+
<number>0</number>
1005+
</property>
1006+
<property name="topMargin">
1007+
<number>0</number>
1008+
</property>
1009+
<property name="rightMargin">
1010+
<number>0</number>
1011+
</property>
1012+
<property name="bottomMargin">
1013+
<number>0</number>
1014+
</property>
1015+
<item>
1016+
<spacer name="horizontalSpacer_4">
1017+
<property name="orientation">
1018+
<enum>Qt::Horizontal</enum>
1019+
</property>
1020+
<property name="sizeHint" stdset="0">
1021+
<size>
1022+
<width>40</width>
1023+
<height>20</height>
1024+
</size>
1025+
</property>
1026+
</spacer>
1027+
</item>
1028+
<item>
1029+
<widget class="QPushButton" name="butSavePlot">
1030+
<property name="toolTip">
1031+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save current plot...&lt;/p&gt;&lt;p&gt;File format choosen by extension (png, jpg, pdf, bmp)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1032+
</property>
1033+
<property name="statusTip">
1034+
<string>Save current plot...</string>
1035+
</property>
1036+
<property name="text">
1037+
<string/>
1038+
</property>
1039+
<property name="icon">
1040+
<iconset resource="icons/icons.qrc">
1041+
<normaloff>:/icons/save_table</normaloff>:/icons/save_table</iconset>
1042+
</property>
1043+
<property name="checkable">
1044+
<bool>false</bool>
1045+
</property>
1046+
<property name="autoDefault">
1047+
<bool>false</bool>
1048+
</property>
1049+
<property name="default">
1050+
<bool>false</bool>
1051+
</property>
1052+
<property name="flat">
1053+
<bool>false</bool>
1054+
</property>
1055+
</widget>
1056+
</item>
1057+
</layout>
1058+
</widget>
1059+
</item>
10001060
</layout>
10011061
</widget>
10021062
</item>

0 commit comments

Comments
 (0)