Commit 84371ad2eb9dc69f604bb12e093a9afc88d128e9

Authored by David Graeff
Committed by David Gräff
1 parent 8969a24d

Move exporter to own directory. There will come another raw-sample exporter at s…

…ome time. Move export settings there as well.
openhantek/src/exporter.cpp renamed to openhantek/src/exporting/exporter.cpp
... ... @@ -17,31 +17,34 @@
17 17  
18 18 #include "exporter.h"
19 19  
20   -#include "analyse/dataanalyzerresult.h"
21   -#include "glgenerator.h"
  20 +#include "controlspecification.h"
  21 +#include "post/graphgenerator.h"
  22 +#include "post/ppresult.h"
22 23 #include "settings.h"
23   -#include "viewconstants.h"
24 24 #include "utils/dsoStrings.h"
25 25 #include "utils/printutils.h"
  26 +#include "viewconstants.h"
26 27  
27 28 #define tr(msg) QCoreApplication::translate("Exporter", msg)
28 29  
29   -Exporter::Exporter(DsoSettings *settings, const QString &filename, ExportFormat format)
30   - : settings(settings), filename(filename), format(format) {}
  30 +Exporter::Exporter(const Dso::ControlSpecification *deviceSpecification, DsoSettings *settings, const QString &filename,
  31 + ExportFormat format)
  32 + : deviceSpecification(deviceSpecification), settings(settings), filename(filename), format(format) {}
31 33  
32   -Exporter *Exporter::createPrintExporter(DsoSettings *settings) {
  34 +Exporter *Exporter::createPrintExporter(const Dso::ControlSpecification *deviceSpecification, DsoSettings *settings) {
33 35 std::unique_ptr<QPrinter> printer = printPaintDevice(settings);
34 36 // Show the printing dialog
35 37 QPrintDialog dialog(printer.get());
36 38 dialog.setWindowTitle(tr("Print oscillograph"));
37 39 if (dialog.exec() != QDialog::Accepted) { return nullptr; }
38 40  
39   - Exporter *exporter = new Exporter(settings, QString(), EXPORT_FORMAT_PRINTER);
  41 + Exporter *exporter = new Exporter(deviceSpecification, settings, QString(), EXPORT_FORMAT_PRINTER);
40 42 exporter->selectedPrinter = std::move(printer);
41 43 return exporter;
42 44 }
43 45  
44   -Exporter *Exporter::createSaveToFileExporter(DsoSettings *settings) {
  46 +Exporter *Exporter::createSaveToFileExporter(const Dso::ControlSpecification *deviceSpecification,
  47 + DsoSettings *settings) {
45 48 QStringList filters;
46 49 filters << tr("Portable Document Format (*.pdf)") << tr("Image (*.png *.xpm *.jpg)")
47 50 << tr("Comma-Separated Values (*.csv)");
... ... @@ -51,7 +54,7 @@ Exporter *Exporter::createSaveToFileExporter(DsoSettings *settings) {
51 54 fileDialog.setAcceptMode(QFileDialog::AcceptSave);
52 55 if (fileDialog.exec() != QDialog::Accepted) return nullptr;
53 56  
54   - return new Exporter(settings, fileDialog.selectedFiles().first(),
  57 + return new Exporter(deviceSpecification, settings, fileDialog.selectedFiles().first(),
55 58 (ExportFormat)(EXPORT_FORMAT_PDF + filters.indexOf(fileDialog.selectedNameFilter())));
56 59 }
57 60  
... ... @@ -63,7 +66,7 @@ std::unique_ptr&lt;QPrinter&gt; Exporter::printPaintDevice(DsoSettings *settings) {
63 66 return printer;
64 67 }
65 68  
66   -bool Exporter::exportSamples(const DataAnalyzerResult *result) {
  69 +bool Exporter::exportSamples(const PPresult *result) {
67 70 if (this->format == EXPORT_FORMAT_CSV) { return exportCSV(result); }
68 71  
69 72 // Choose the color values we need
... ... @@ -77,7 +80,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
77 80  
78 81 if (this->format == EXPORT_FORMAT_IMAGE) {
79 82 // We need a QPixmap for image-export
80   - QPixmap *qPixmap = new QPixmap(settings->options.imageSize);
  83 + QPixmap *qPixmap = new QPixmap(settings->exporting.imageSize);
81 84 qPixmap->fill(colorValues->background);
82 85 paintDevice = std::unique_ptr<QPaintDevice>(qPixmap);
83 86 } else if (this->format == EXPORT_FORMAT_PRINTER) {
... ... @@ -146,9 +149,10 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
146 149 painter.setPen(colorValues->voltage[channel]);
147 150 painter.drawText(QRectF(0, top, lineHeight * 4, lineHeight), settings->scope.voltage[channel].name);
148 151 // Print coupling/math mode
149   - if ((unsigned int)channel < settings->deviceSpecification->channels)
150   - painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight),
151   - Dso::couplingString(settings->scope.coupling(channel, settings->deviceSpecification)));
  152 + if ((unsigned int)channel < deviceSpecification->channels)
  153 + painter.drawText(
  154 + QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight),
  155 + Dso::couplingString(settings->scope.coupling(channel, deviceSpecification)));
152 156 else
153 157 painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight),
154 158 Dso::mathModeString(settings->scope.voltage[channel].math));
... ... @@ -169,7 +173,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
169 173 // Amplitude string representation (4 significant digits)
170 174 painter.setPen(colorValues->text);
171 175 painter.drawText(QRectF(lineHeight * 6 + stretchBase * 4, top, stretchBase * 3, lineHeight),
172   - valueToString(result->data(channel)->amplitude, UNIT_VOLTS, 4),
  176 + valueToString(result->data(channel)->computeAmplitude(), UNIT_VOLTS, 4),
173 177 QTextOption(Qt::AlignRight));
174 178 // Frequency string representation (5 significant digits)
175 179 painter.drawText(QRectF(lineHeight * 6 + stretchBase * 7, top, stretchBase * 3, lineHeight),
... ... @@ -329,7 +333,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
329 333 return true;
330 334 }
331 335  
332   -bool Exporter::exportCSV(const DataAnalyzerResult *result) {
  336 +bool Exporter::exportCSV(const PPresult *result) {
333 337 QFile csvFile(this->filename);
334 338 if (!csvFile.open(QIODevice::WriteOnly | QIODevice::Text)) return false;
335 339  
... ...
openhantek/src/exporter.h renamed to openhantek/src/exporting/exporter.h
... ... @@ -6,34 +6,30 @@
6 6 #include <QPrinter>
7 7 #include <QSize>
8 8 #include <memory>
  9 +#include "exportsettings.h"
9 10  
10 11 class DsoSettings;
11   -class DataAnalyzerResult;
  12 +class PPresult;
12 13 struct DsoSettingsColorValues;
  14 +namespace Dso { struct ControlSpecification; }
13 15  
14   -////////////////////////////////////////////////////////////////////////////////
15   -/// \enum ExportFormat exporter.h
16   -/// \brief Possible file formats for the export.
17   -enum ExportFormat { EXPORT_FORMAT_PRINTER, EXPORT_FORMAT_PDF, EXPORT_FORMAT_IMAGE, EXPORT_FORMAT_CSV };
18   -
19   -////////////////////////////////////////////////////////////////////////////////
20   -/// \class Exporter exporter.h
21 16 /// \brief Exports the oscilloscope screen to a file or prints it.
22 17 class Exporter {
23 18 public:
24   - static Exporter *createPrintExporter(DsoSettings *settings);
25   - static Exporter *createSaveToFileExporter(DsoSettings *settings);
  19 + static Exporter *createPrintExporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings);
  20 + static Exporter *createSaveToFileExporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings);
26 21  
27 22 /// \brief Print the document (May be a file too)
28   - bool exportSamples(const DataAnalyzerResult *result);
  23 + bool exportSamples(const PPresult *result);
29 24  
30 25 private:
31   - Exporter(DsoSettings *settings, const QString &filename, ExportFormat format);
  26 + Exporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings, const QString &filename, ExportFormat format);
32 27 void setFormat(ExportFormat format);
33   - bool exportCSV(const DataAnalyzerResult *result);
  28 + bool exportCSV(const PPresult *result);
34 29 static std::unique_ptr<QPrinter> printPaintDevice(DsoSettings *settings);
35 30 void drawGrids(QPainter &painter, DsoSettingsColorValues *colorValues, double lineHeight, double scopeHeight,
36 31 int scopeWidth);
  32 + const Dso::ControlSpecification* deviceSpecification;
37 33 DsoSettings *settings;
38 34 std::unique_ptr<QPrinter> selectedPrinter;
39 35  
... ...
openhantek/src/exporting/exportsettings.h 0 → 100644
  1 +// SPDX-License-Identifier: GPL-2.0+
  2 +
  3 +#pragma once
  4 +
  5 +#include <QSize>
  6 +
  7 +/// \brief Holds the general options of the program.
  8 +struct DsoSettingsExport {
  9 + QSize imageSize = QSize(640, 480); ///< Size of exported images in pixels
  10 +};
  11 +
  12 +/// \brief Possible file formats for the export.
  13 +enum ExportFormat { EXPORT_FORMAT_PRINTER, EXPORT_FORMAT_PDF, EXPORT_FORMAT_IMAGE, EXPORT_FORMAT_CSV };
... ...
openhantek/src/scopesettings.h
... ... @@ -4,10 +4,10 @@
4 4  
5 5 #include <QString>
6 6  
7   -#include "analyse/enums.h"
8 7 #include "hantekdso/controlspecification.h"
9 8 #include "hantekdso/enums.h"
10 9 #include "hantekprotocol/definitions.h"
  10 +#include "post/enums.h"
11 11 #include <vector>
12 12  
13 13 #define MARKER_COUNT 2 ///< Number of markers
... ... @@ -21,9 +21,9 @@ struct DsoSettingsScopeHorizontal {
21 21  
22 22 unsigned int recordLength = 0; ///< Sample count
23 23  
24   - ///TODO Use ControlSettingsSamplerateTarget
25   - double timebase = 1e-3; ///< Timebase in s/div
26   - double samplerate = 1e6; ///< The samplerate of the oscilloscope in S
  24 + /// TODO Use ControlSettingsSamplerateTarget
  25 + double timebase = 1e-3; ///< Timebase in s/div
  26 + double samplerate = 1e6; ///< The samplerate of the oscilloscope in S
27 27 enum SamplerateSource { Samplerrate, Duration } samplerateSource = Samplerrate;
28 28 };
29 29  
... ... @@ -31,12 +31,12 @@ struct DsoSettingsScopeHorizontal {
31 31 /// TODO Use ControlSettingsTrigger
32 32 struct DsoSettingsScopeTrigger {
33 33 Dso::TriggerMode mode = Dso::TriggerMode::HARDWARE_SOFTWARE; ///< Automatic, normal or single trigger
34   - double position = 0.0; ///< Horizontal position for pretrigger
35   - Dso::Slope slope = Dso::Slope::Positive; ///< Rising or falling edge causes trigger
36   - unsigned int source = 0; ///< Channel that is used as trigger source
37   - bool special = false; ///< true if the trigger source is not a standard channel
38   - unsigned swTriggerThreshold = 7; ///< Software trigger, threshold
39   - unsigned swTriggerSampleSet = 11; ///< Software trigger, sample set
  34 + double position = 0.0; ///< Horizontal position for pretrigger
  35 + Dso::Slope slope = Dso::Slope::Positive; ///< Rising or falling edge causes trigger
  36 + unsigned int source = 0; ///< Channel that is used as trigger source
  37 + bool special = false; ///< true if the trigger source is not a standard channel
  38 + unsigned swTriggerThreshold = 7; ///< Software trigger, threshold
  39 + unsigned swTriggerSampleSet = 11; ///< Software trigger, sample set
40 40 };
41 41  
42 42 /// \brief Holds the settings for the spectrum analysis.
... ... @@ -51,17 +51,17 @@ struct DsoSettingsScopeSpectrum {
51 51 /// \brief Holds the settings for the normal voltage graphs.
52 52 /// TODO Use ControlSettingsVoltage
53 53 struct DsoSettingsScopeVoltage {
  54 + double offset = 0.0; ///< Vertical offset in divs
  55 + double trigger = 0.0; ///< Trigger level in V
54 56 unsigned gainStepIndex = 6; ///< The vertical resolution in V/div (default = 1.0)
55   - bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis)
56 57 union { ///< Different enums, coupling for real- and mode for math-channels
57 58 Dso::MathMode math;
58 59 unsigned couplingIndex = 0;
59 60 int rawValue;
60 61 };
61   - QString name; ///< Name of this channel
62   - double offset = 0.0; ///< Vertical offset in divs
63   - double trigger = 0.0; ///< Trigger level in V
64   - bool used = false; ///< true if this channel is enabled
  62 + QString name; ///< Name of this channel
  63 + bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis)
  64 + bool used = false; ///< true if this channel is enabled
65 65 };
66 66  
67 67 /// \brief Holds the settings for the oscilloscope.
... ... @@ -82,4 +82,6 @@ struct DsoSettingsScope {
82 82 Dso::Coupling coupling(ChannelID channel, const Dso::ControlSpecification *deviceSpecification) {
83 83 return deviceSpecification->couplings[voltage[channel].couplingIndex];
84 84 }
  85 + // Channels, including math channels
  86 + unsigned countChannels() { return (unsigned)voltage.size(); }
85 87 };
... ...
openhantek/src/settings.cpp
... ... @@ -11,9 +11,7 @@
11 11  
12 12 /// \brief Set the number of channels.
13 13 /// \param channels The new channel count, that will be applied to lists.
14   -DsoSettings::DsoSettings(const Dso::ControlSpecification* deviceSpecification)
15   - : deviceSpecification(deviceSpecification) {
16   -
  14 +DsoSettings::DsoSettings(const Dso::ControlSpecification* deviceSpecification) {
17 15 // Add new channels to the list
18 16 while (scope.spectrum.size() < deviceSpecification->channels) {
19 17 // Spectrum
... ... @@ -63,10 +61,11 @@ bool DsoSettings::setFilename(const QString &amp;filename) {
63 61 void DsoSettings::load() {
64 62 // General options
65 63 store->beginGroup("options");
66   - if (store->contains("alwaysSave")) options.alwaysSave = store->value("alwaysSave").toBool();
67   - if (store->contains("imageSize")) options.imageSize = store->value("imageSize").toSize();
68   - // If the window/* keys were found in this group, remove them from settings
69   - store->remove("window");
  64 + if (store->contains("alwaysSave")) alwaysSave = store->value("alwaysSave").toBool();
  65 + store->endGroup();
  66 +
  67 + store->beginGroup("exporting");
  68 + if (store->contains("imageSize")) exporting.imageSize = store->value("imageSize").toSize();
70 69 store->endGroup();
71 70  
72 71 // Oscilloscope settings
... ... @@ -170,8 +169,11 @@ void DsoSettings::load() {
170 169 void DsoSettings::save() {
171 170 // Main window layout and other general options
172 171 store->beginGroup("options");
173   - store->setValue("alwaysSave", options.alwaysSave);
174   - store->setValue("imageSize", options.imageSize);
  172 + store->setValue("alwaysSave", alwaysSave);
  173 + store->endGroup();
  174 +
  175 + store->beginGroup("exporting");
  176 + store->setValue("imageSize", exporting.imageSize);
175 177 store->endGroup();
176 178  
177 179 // Oszilloskope settings
... ...
openhantek/src/settings.h
... ... @@ -9,31 +9,20 @@
9 9  
10 10 #include "scopesettings.h"
11 11 #include "viewsettings.h"
  12 +#include "exporting/exportsettings.h"
12 13 #include "hantekdso/controlspecification.h"
13 14 #include "hantekdso/controlsettings.h"
14 15  
15   -////////////////////////////////////////////////////////////////////////////////
16   -/// \struct DsoSettingsOptions
17   -/// \brief Holds the general options of the program.
18   -struct DsoSettingsOptions {
19   - bool alwaysSave = true; ///< Always save the settings on exit
20   - QSize imageSize = QSize(640, 480); ///< Size of exported images in pixels
21   -};
22   -
23   -////////////////////////////////////////////////////////////////////////////////
24   -/// \class DsoSettings
25 16 /// \brief Holds the settings of the program.
26 17 class DsoSettings {
27 18 public:
28 19 explicit DsoSettings(const Dso::ControlSpecification* deviceSpecification);
29 20 bool setFilename(const QString &filename);
30 21  
31   - DsoSettingsOptions options; ///< General options of the program
  22 + DsoSettingsExport exporting; ///< General options of the program
32 23 DsoSettingsScope scope; ///< All oscilloscope related settings
33 24 DsoSettingsView view; ///< All view related settings
34   -
35   - // Read only access to device settings and device specification
36   - const Dso::ControlSpecification* deviceSpecification;
  25 + bool alwaysSave = true; ///< Always save the settings on exit
37 26  
38 27 QByteArray mainWindowGeometry; ///< Geometry of the main window
39 28 QByteArray mainWindowState; ///< State of docking windows and toolbars
... ...