Commit 8737282c681667d9fd6e9c6ab9c585925c4bf995

Authored by Klemens Schölhorn
Committed by David Gräff
1 parent 490026e9

Add checkbox to display inverted channels

openhantek/src/docks/VoltageDock.cpp
... ... @@ -47,6 +47,8 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags
47 47 this->gainComboBox.append(new QComboBox());
48 48 this->gainComboBox[channel]->addItems(this->gainStrings);
49 49  
  50 + this->invertCheckBox.append(new QCheckBox(tr("Invert")));
  51 +
50 52 this->usedCheckBox.append(new QCheckBox(settings->scope.voltage[channel].name));
51 53 }
52 54  
... ... @@ -54,9 +56,10 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags
54 56 this->dockLayout->setColumnMinimumWidth(0, 64);
55 57 this->dockLayout->setColumnStretch(1, 1);
56 58 for (int channel = 0; channel < settings->scope.voltage.count(); ++channel) {
57   - this->dockLayout->addWidget(this->usedCheckBox[channel], channel * 2, 0);
58   - this->dockLayout->addWidget(this->gainComboBox[channel], channel * 2, 1);
59   - this->dockLayout->addWidget(this->miscComboBox[channel], channel * 2 + 1, 1);
  59 + this->dockLayout->addWidget(this->usedCheckBox[channel], channel * 3, 0);
  60 + this->dockLayout->addWidget(this->gainComboBox[channel], channel * 3, 1);
  61 + this->dockLayout->addWidget(this->miscComboBox[channel], channel * 3 + 1, 1);
  62 + this->dockLayout->addWidget(this->invertCheckBox[channel], channel * 3 + 2, 1);
60 63 }
61 64  
62 65 this->dockWidget = new QWidget();
... ... @@ -65,6 +68,7 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags
65 68 // Connect signals and slots
66 69 for (int channel = 0; channel < settings->scope.voltage.count(); ++channel) {
67 70 connect(this->gainComboBox[channel], SIGNAL(currentIndexChanged(int)), this, SLOT(gainSelected(int)));
  71 + connect(this->invertCheckBox[channel], SIGNAL(toggled(bool)), this, SLOT(invertSwitched(bool)));
68 72 connect(this->miscComboBox[channel], SIGNAL(currentIndexChanged(int)), this, SLOT(miscSelected(int)));
69 73 connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, SLOT(usedSwitched(bool)));
70 74 }
... ... @@ -192,3 +196,19 @@ void VoltageDock::usedSwitched(bool checked) {
192 196 emit usedChanged(channel, checked);
193 197 }
194 198 }
  199 +
  200 +/// \brief Called when the invert checkbox is switched.
  201 +/// \param checked The check-state of the checkbox.
  202 +void VoltageDock::invertSwitched(bool checked) {
  203 + int channel;
  204 +
  205 + // Which checkbox was it?
  206 + for (channel = 0; channel < settings->scope.voltage.count(); ++channel)
  207 + if (this->sender() == this->invertCheckBox[channel]) break;
  208 +
  209 + // Send signal if it was one of the checkboxes
  210 + if (channel < settings->scope.voltage.count()) {
  211 + settings->scope.voltage[channel].inverted = checked;
  212 + // Should we emit an event here?
  213 + }
  214 +}
... ...
openhantek/src/docks/VoltageDock.h
... ... @@ -39,6 +39,7 @@ class VoltageDock : public QDockWidget {
39 39 QList<QCheckBox *> usedCheckBox; ///< Enable/disable a specific channel
40 40 QList<QComboBox *> gainComboBox; ///< Select the vertical gain for the channels
41 41 QList<QComboBox *> miscComboBox; ///< Select coupling for real and mode for math channels
  42 + QList<QCheckBox *> invertCheckBox; ///< Select if the channels should be displayed inverted
42 43  
43 44 DsoSettings *settings; ///< The settings provided by the parent class
44 45  
... ... @@ -51,6 +52,7 @@ class VoltageDock : public QDockWidget {
51 52 void gainSelected(int index);
52 53 void miscSelected(int index);
53 54 void usedSwitched(bool checked);
  55 + void invertSwitched(bool checked);
54 56  
55 57 signals:
56 58 void couplingChanged(unsigned int channel, Dso::Coupling coupling); ///< A coupling has been selected
... ...
openhantek/src/glgenerator.cpp
... ... @@ -232,12 +232,13 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) {
232 232 result->data(channel)->voltage.sample.begin();
233 233 const double gain = settings->voltage[channel].gain;
234 234 const double offset = settings->voltage[channel].offset;
  235 + const double invert = settings->voltage[channel].inverted ? -1.0 : 1.0;
235 236  
236 237 std::advance(dataIterator, swTriggerStart - preTrigSamples);
237 238  
238 239 for (unsigned int position = 0; position < sampleCount; ++position) {
239 240 *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2;
240   - *(glIterator++) = *(dataIterator++) / gain + offset;
  241 + *(glIterator++) = invert * (*(dataIterator++) / gain + offset);
241 242 }
242 243 } else {
243 244 std::vector<double>::const_iterator dataIterator =
... ... @@ -292,10 +293,12 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) {
292 293 const double yGain = settings->voltage[yChannel].gain;
293 294 const double xOffset = settings->voltage[xChannel].offset;
294 295 const double yOffset = settings->voltage[yChannel].offset;
  296 + const double xInvert = settings->voltage[xChannel].inverted ? -1.0 : 1.0;
  297 + const double yInvert = settings->voltage[yChannel].inverted ? -1.0 : 1.0;
295 298  
296 299 for (unsigned int position = 0; position < sampleCount; ++position) {
297   - *(glIterator++) = *(xIterator++) / xGain + xOffset;
298   - *(glIterator++) = *(yIterator++) / yGain + yOffset;
  300 + *(glIterator++) = xInvert * (*(xIterator++) / xGain + xOffset);
  301 + *(glIterator++) = yInvert * (*(yIterator++) / yGain + yOffset);
299 302 }
300 303 } else {
301 304 // Delete all vector arrays
... ...
openhantek/src/scopesettings.h
... ... @@ -45,6 +45,7 @@ struct DsoSettingsScopeSpectrum {
45 45 struct DsoSettingsScopeVoltage {
46 46 double gain; ///< The vertical resolution in V/div
47 47 int misc; ///< Different enums, coupling for real- and mode for math-channels
  48 + bool inverted; ///< true if the channel is inverted (mirrored on cross-axis)
48 49 QString name; ///< Name of this channel
49 50 double offset; ///< Vertical offset in divs
50 51 double trigger; ///< Trigger level in V
... ...