Commit 81b09a4d95544a79650300c911a165449518b3e6
1 parent
5d72ea94
Split dock window files
Showing
11 changed files
with
1032 additions
and
956 deletions
openhantek/src/docks/HorizontalDock.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#include <QCheckBox> | ||
| 4 | +#include <QCloseEvent> | ||
| 5 | +#include <QComboBox> | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLabel> | ||
| 8 | + | ||
| 9 | +#include <cmath> | ||
| 10 | + | ||
| 11 | +#include "dockwindows.h" | ||
| 12 | +#include "HorizontalDock.h" | ||
| 13 | + | ||
| 14 | +#include "utils/printutils.h" | ||
| 15 | +#include "utils/dsoStrings.h" | ||
| 16 | +#include "settings.h" | ||
| 17 | +#include "sispinbox.h" | ||
| 18 | + | ||
| 19 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 20 | +// class HorizontalDock | ||
| 21 | +/// \brief Initializes the horizontal axis docking window. | ||
| 22 | +/// \param settings The target settings object. | ||
| 23 | +/// \param parent The parent widget. | ||
| 24 | +/// \param flags Flags for the window manager. | ||
| 25 | +HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, | ||
| 26 | + Qt::WindowFlags flags) | ||
| 27 | + : QDockWidget(tr("Horizontal"), parent, flags) { | ||
| 28 | + this->settings = settings; | ||
| 29 | + | ||
| 30 | + // Initialize elements | ||
| 31 | + this->samplerateLabel = new QLabel(tr("Samplerate")); | ||
| 32 | + this->samplerateSiSpinBox = new SiSpinBox(UNIT_SAMPLES); | ||
| 33 | + this->samplerateSiSpinBox->setMinimum(1); | ||
| 34 | + this->samplerateSiSpinBox->setMaximum(1e8); | ||
| 35 | + this->samplerateSiSpinBox->setUnitPostfix("/s"); | ||
| 36 | + | ||
| 37 | + timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0; | ||
| 38 | + | ||
| 39 | + this->timebaseLabel = new QLabel(tr("Timebase")); | ||
| 40 | + this->timebaseSiSpinBox = new SiSpinBox(UNIT_SECONDS); | ||
| 41 | + this->timebaseSiSpinBox->setSteps(timebaseSteps); | ||
| 42 | + this->timebaseSiSpinBox->setMinimum(1e-9); | ||
| 43 | + this->timebaseSiSpinBox->setMaximum(3.6e3); | ||
| 44 | + | ||
| 45 | + this->frequencybaseLabel = new QLabel(tr("Frequencybase")); | ||
| 46 | + this->frequencybaseSiSpinBox = new SiSpinBox(UNIT_HERTZ); | ||
| 47 | + this->frequencybaseSiSpinBox->setMinimum(1.0); | ||
| 48 | + this->frequencybaseSiSpinBox->setMaximum(100e6); | ||
| 49 | + | ||
| 50 | + this->recordLengthLabel = new QLabel(tr("Record length")); | ||
| 51 | + this->recordLengthComboBox = new QComboBox(); | ||
| 52 | + | ||
| 53 | + this->formatLabel = new QLabel(tr("Format")); | ||
| 54 | + this->formatComboBox = new QComboBox(); | ||
| 55 | + for (int format = Dso::GRAPHFORMAT_TY; format < Dso::GRAPHFORMAT_COUNT; | ||
| 56 | + ++format) | ||
| 57 | + this->formatComboBox->addItem( | ||
| 58 | + Dso::graphFormatString((Dso::GraphFormat)format)); | ||
| 59 | + | ||
| 60 | + this->dockLayout = new QGridLayout(); | ||
| 61 | + this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 62 | + this->dockLayout->setColumnStretch(1, 1); | ||
| 63 | + this->dockLayout->addWidget(this->samplerateLabel, 0, 0); | ||
| 64 | + this->dockLayout->addWidget(this->samplerateSiSpinBox, 0, 1); | ||
| 65 | + this->dockLayout->addWidget(this->timebaseLabel, 1, 0); | ||
| 66 | + this->dockLayout->addWidget(this->timebaseSiSpinBox, 1, 1); | ||
| 67 | + this->dockLayout->addWidget(this->frequencybaseLabel, 2, 0); | ||
| 68 | + this->dockLayout->addWidget(this->frequencybaseSiSpinBox, 2, 1); | ||
| 69 | + this->dockLayout->addWidget(this->recordLengthLabel, 3, 0); | ||
| 70 | + this->dockLayout->addWidget(this->recordLengthComboBox, 3, 1); | ||
| 71 | + this->dockLayout->addWidget(this->formatLabel, 4, 0); | ||
| 72 | + this->dockLayout->addWidget(this->formatComboBox, 4, 1); | ||
| 73 | + | ||
| 74 | + this->dockWidget = new QWidget(); | ||
| 75 | + SetupDockWidget(this, dockWidget, dockLayout); | ||
| 76 | + | ||
| 77 | + // Connect signals and slots | ||
| 78 | + connect(this->samplerateSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 79 | + SLOT(samplerateSelected(double))); | ||
| 80 | + connect(this->timebaseSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 81 | + SLOT(timebaseSelected(double))); | ||
| 82 | + connect(this->frequencybaseSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 83 | + SLOT(frequencybaseSelected(double))); | ||
| 84 | + connect(this->recordLengthComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 85 | + SLOT(recordLengthSelected(int))); | ||
| 86 | + connect(this->formatComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 87 | + SLOT(formatSelected(int))); | ||
| 88 | + | ||
| 89 | + // Set values | ||
| 90 | + this->setSamplerate(this->settings->scope.horizontal.samplerate); | ||
| 91 | + this->setTimebase(this->settings->scope.horizontal.timebase); | ||
| 92 | + this->setFrequencybase(this->settings->scope.horizontal.frequencybase); | ||
| 93 | + this->setRecordLength(this->settings->scope.horizontal.recordLength); | ||
| 94 | + this->setFormat(this->settings->scope.horizontal.format); | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +/// \brief Cleans up everything. | ||
| 98 | +HorizontalDock::~HorizontalDock() {} | ||
| 99 | + | ||
| 100 | +/// \brief Don't close the dock, just hide it. | ||
| 101 | +/// \param event The close event that should be handled. | ||
| 102 | +void HorizontalDock::closeEvent(QCloseEvent *event) { | ||
| 103 | + this->hide(); | ||
| 104 | + | ||
| 105 | + event->accept(); | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +/// \brief Changes the frequencybase. | ||
| 109 | +/// \param frequencybase The frequencybase in hertz. | ||
| 110 | +void HorizontalDock::setFrequencybase(double frequencybase) { | ||
| 111 | + this->suppressSignals = true; | ||
| 112 | + this->frequencybaseSiSpinBox->setValue(frequencybase); | ||
| 113 | + this->suppressSignals = false; | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +/// \brief Changes the samplerate. | ||
| 117 | +/// \param samplerate The samplerate in seconds. | ||
| 118 | +void HorizontalDock::setSamplerate(double samplerate) { | ||
| 119 | + this->suppressSignals = true; | ||
| 120 | + this->samplerateSiSpinBox->setValue(samplerate); | ||
| 121 | + this->suppressSignals = false; | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +/// \brief Changes the timebase. | ||
| 125 | +/// \param timebase The timebase in seconds. | ||
| 126 | +double HorizontalDock::setTimebase(double timebase) { | ||
| 127 | + // timebaseSteps are repeated in each decade | ||
| 128 | + double decade = pow(10, floor(log10(timebase))); | ||
| 129 | + double vNorm = timebase / decade; | ||
| 130 | + for (int i = 0; i < timebaseSteps.size() - 1; ++i) { | ||
| 131 | + if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) { | ||
| 132 | + suppressSignals = true; | ||
| 133 | + timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i)); | ||
| 134 | + suppressSignals = false; | ||
| 135 | + break; | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + return timebaseSiSpinBox->value(); | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +/// \brief Changes the record length if the new value is supported. | ||
| 142 | +/// \param recordLength The record length in samples. | ||
| 143 | +void HorizontalDock::setRecordLength(unsigned int recordLength) { | ||
| 144 | + int index = this->recordLengthComboBox->findData(recordLength); | ||
| 145 | + | ||
| 146 | + if (index != -1) { | ||
| 147 | + this->suppressSignals = true; | ||
| 148 | + this->recordLengthComboBox->setCurrentIndex(index); | ||
| 149 | + this->suppressSignals = false; | ||
| 150 | + } | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +/// \brief Changes the format if the new value is supported. | ||
| 154 | +/// \param format The format for the horizontal axis. | ||
| 155 | +/// \return Index of format-value, -1 on error. | ||
| 156 | +int HorizontalDock::setFormat(Dso::GraphFormat format) { | ||
| 157 | + if (format >= Dso::GRAPHFORMAT_TY && format <= Dso::GRAPHFORMAT_XY) { | ||
| 158 | + this->suppressSignals = true; | ||
| 159 | + this->formatComboBox->setCurrentIndex(format); | ||
| 160 | + this->suppressSignals = false; | ||
| 161 | + return format; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + return -1; | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +/// \brief Updates the available record lengths in the combo box. | ||
| 168 | +/// \param recordLengths The available record lengths for the combo box. | ||
| 169 | +void HorizontalDock::availableRecordLengthsChanged( | ||
| 170 | + const QList<unsigned int> &recordLengths) { | ||
| 171 | + /// \todo Empty lists should be interpreted as scope supporting continuous | ||
| 172 | + /// record length values. | ||
| 173 | + this->recordLengthComboBox->blockSignals( | ||
| 174 | + true); // Avoid messing up the settings | ||
| 175 | + this->recordLengthComboBox->setUpdatesEnabled(false); | ||
| 176 | + | ||
| 177 | + // Update existing elements to avoid unnecessary index updates | ||
| 178 | + int index = 0; | ||
| 179 | + for (; index < recordLengths.size(); ++index) { | ||
| 180 | + unsigned int recordLengthItem = recordLengths[index]; | ||
| 181 | + if (index < this->recordLengthComboBox->count()) { | ||
| 182 | + this->recordLengthComboBox->setItemData(index, recordLengthItem); | ||
| 183 | + this->recordLengthComboBox->setItemText( | ||
| 184 | + index, recordLengthItem == UINT_MAX | ||
| 185 | + ? tr("Roll") | ||
| 186 | + : valueToString(recordLengthItem, | ||
| 187 | + UNIT_SAMPLES, 3)); | ||
| 188 | + } else { | ||
| 189 | + this->recordLengthComboBox->addItem( | ||
| 190 | + recordLengthItem == UINT_MAX | ||
| 191 | + ? tr("Roll") | ||
| 192 | + : valueToString(recordLengthItem, UNIT_SAMPLES, | ||
| 193 | + 3), | ||
| 194 | + (uint)recordLengthItem); | ||
| 195 | + } | ||
| 196 | + } | ||
| 197 | + // Remove extra elements | ||
| 198 | + for (int extraIndex = this->recordLengthComboBox->count() - 1; | ||
| 199 | + extraIndex > index; --extraIndex) { | ||
| 200 | + this->recordLengthComboBox->removeItem(extraIndex); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + this->setRecordLength(this->settings->scope.horizontal.recordLength); | ||
| 204 | + this->recordLengthComboBox->setUpdatesEnabled(true); | ||
| 205 | + this->recordLengthComboBox->blockSignals(false); | ||
| 206 | +} | ||
| 207 | + | ||
| 208 | +/// \brief Updates the minimum and maximum of the samplerate spin box. | ||
| 209 | +/// \param minimum The minimum value the spin box should accept. | ||
| 210 | +/// \param maximum The minimum value the spin box should accept. | ||
| 211 | +void HorizontalDock::samplerateLimitsChanged(double minimum, double maximum) { | ||
| 212 | + this->suppressSignals = true; | ||
| 213 | + this->samplerateSiSpinBox->setMinimum(minimum); | ||
| 214 | + this->samplerateSiSpinBox->setMaximum(maximum); | ||
| 215 | + this->suppressSignals = false; | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +/// \brief Updates the mode and steps of the samplerate spin box. | ||
| 219 | +/// \param mode The mode value the spin box should accept. | ||
| 220 | +/// \param steps The steps value the spin box should accept. | ||
| 221 | +void HorizontalDock::samplerateSet(int mode, QList<double> steps) { | ||
| 222 | + this->suppressSignals = true; | ||
| 223 | + this->samplerateSiSpinBox->setMode(mode); | ||
| 224 | + this->samplerateSiSpinBox->setSteps(steps); | ||
| 225 | + this->suppressSignals = false; | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +/// \brief Called when the frequencybase spinbox changes its value. | ||
| 229 | +/// \param frequencybase The frequencybase in hertz. | ||
| 230 | +void HorizontalDock::frequencybaseSelected(double frequencybase) { | ||
| 231 | + this->settings->scope.horizontal.frequencybase = frequencybase; | ||
| 232 | + if (!this->suppressSignals) | ||
| 233 | + emit frequencybaseChanged(frequencybase); | ||
| 234 | +} | ||
| 235 | + | ||
| 236 | +/// \brief Called when the samplerate spinbox changes its value. | ||
| 237 | +/// \param samplerate The samplerate in samples/second. | ||
| 238 | +void HorizontalDock::samplerateSelected(double samplerate) { | ||
| 239 | + this->settings->scope.horizontal.samplerate = samplerate; | ||
| 240 | + if (!this->suppressSignals) { | ||
| 241 | + this->settings->scope.horizontal.samplerateSet = true; | ||
| 242 | + emit samplerateChanged(samplerate); | ||
| 243 | + } | ||
| 244 | +} | ||
| 245 | + | ||
| 246 | +/// \brief Called when the timebase spinbox changes its value. | ||
| 247 | +/// \param timebase The timebase in seconds. | ||
| 248 | +void HorizontalDock::timebaseSelected(double timebase) { | ||
| 249 | + this->settings->scope.horizontal.timebase = timebase; | ||
| 250 | + if (!this->suppressSignals) { | ||
| 251 | + this->settings->scope.horizontal.samplerateSet = false; | ||
| 252 | + emit timebaseChanged(timebase); | ||
| 253 | + } | ||
| 254 | +} | ||
| 255 | + | ||
| 256 | +/// \brief Called when the record length combo box changes its value. | ||
| 257 | +/// \param index The index of the combo box item. | ||
| 258 | +void HorizontalDock::recordLengthSelected(int index) { | ||
| 259 | + this->settings->scope.horizontal.recordLength = | ||
| 260 | + this->recordLengthComboBox->itemData(index).toUInt(); | ||
| 261 | + if (!this->suppressSignals) | ||
| 262 | + emit recordLengthChanged(index); | ||
| 263 | +} | ||
| 264 | + | ||
| 265 | +/// \brief Called when the format combo box changes its value. | ||
| 266 | +/// \param index The index of the combo box item. | ||
| 267 | +void HorizontalDock::formatSelected(int index) { | ||
| 268 | + this->settings->scope.horizontal.format = (Dso::GraphFormat)index; | ||
| 269 | + if (!this->suppressSignals) | ||
| 270 | + emit formatChanged(this->settings->scope.horizontal.format); | ||
| 271 | +} |
openhantek/src/dockwindows.h renamed to openhantek/src/docks/HorizontalDock.h
| 1 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 2 | -// | ||
| 3 | -// OpenHantek | ||
| 4 | -/// \file dockwindows.h | ||
| 5 | -/// \brief Declares the docking window classes. | ||
| 6 | -// | ||
| 7 | -// Copyright (C) 2010 Oliver Haag | ||
| 8 | -// oliver.haag@gmail.com | ||
| 9 | -// | ||
| 10 | -// This program is free software: you can redistribute it and/or modify it | ||
| 11 | -// under the terms of the GNU General Public License as published by the Free | ||
| 12 | -// Software Foundation, either version 3 of the License, or (at your option) | ||
| 13 | -// any later version. | ||
| 14 | -// | ||
| 15 | -// This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 16 | -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 17 | -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 18 | -// more details. | ||
| 19 | -// | ||
| 20 | -// You should have received a copy of the GNU General Public License along with | ||
| 21 | -// this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | -// | ||
| 23 | -//////////////////////////////////////////////////////////////////////////////// | 1 | +// SPDX-License-Identifier: GPL-2.0+ |
| 2 | + | ||
| 3 | +#pragma once | ||
| 24 | 4 | ||
| 25 | -#ifndef DOCKWINDOWS_H | ||
| 26 | -#define DOCKWINDOWS_H | ||
| 27 | 5 | ||
| 28 | #include <QDockWidget> | 6 | #include <QDockWidget> |
| 29 | #include <QGridLayout> | 7 | #include <QGridLayout> |
| @@ -104,148 +82,3 @@ signals: | @@ -104,148 +82,3 @@ signals: | ||
| 104 | void formatChanged( | 82 | void formatChanged( |
| 105 | Dso::GraphFormat format); ///< The viewing format has been changed | 83 | Dso::GraphFormat format); ///< The viewing format has been changed |
| 106 | }; | 84 | }; |
| 107 | - | ||
| 108 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 109 | -/// \class TriggerDock dockwindows.h | ||
| 110 | -/// \brief Dock window for the trigger settings. | ||
| 111 | -/// It contains the settings for the trigger mode, source and slope. | ||
| 112 | -class TriggerDock : public QDockWidget { | ||
| 113 | - Q_OBJECT | ||
| 114 | - | ||
| 115 | -public: | ||
| 116 | - TriggerDock(DsoSettings *settings, const QStringList *specialTriggers, | ||
| 117 | - QWidget *parent, Qt::WindowFlags flags = 0); | ||
| 118 | - ~TriggerDock(); | ||
| 119 | - | ||
| 120 | - int setMode(Dso::TriggerMode mode); | ||
| 121 | - int setSource(bool special, unsigned int id); | ||
| 122 | - int setSlope(Dso::Slope slope); | ||
| 123 | - | ||
| 124 | -protected: | ||
| 125 | - void closeEvent(QCloseEvent *event); | ||
| 126 | - | ||
| 127 | - QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 128 | - QWidget *dockWidget; ///< The main widget for the dock window | ||
| 129 | - QLabel *modeLabel; ///< The label for the trigger mode combobox | ||
| 130 | - QLabel *sourceLabel; ///< The label for the trigger source combobox | ||
| 131 | - QLabel *slopeLabel; ///< The label for the trigger slope combobox | ||
| 132 | - QComboBox *modeComboBox; ///< Select the triggering mode | ||
| 133 | - QComboBox *sourceComboBox; ///< Select the source for triggering | ||
| 134 | - QComboBox *slopeComboBox; ///< Select the slope that causes triggering | ||
| 135 | - | ||
| 136 | - DsoSettings *settings; ///< The settings provided by the parent class | ||
| 137 | - | ||
| 138 | - QStringList modeStrings; ///< Strings for the trigger modes | ||
| 139 | - QStringList | ||
| 140 | - sourceStandardStrings; ///< Strings for the standard trigger sources | ||
| 141 | - QStringList sourceSpecialStrings; ///< Strings for the special trigger sources | ||
| 142 | - QStringList slopeStrings; ///< Strings for the trigger slopes | ||
| 143 | - | ||
| 144 | -protected slots: | ||
| 145 | - void modeSelected(int index); | ||
| 146 | - void slopeSelected(int index); | ||
| 147 | - void sourceSelected(int index); | ||
| 148 | - | ||
| 149 | -signals: | ||
| 150 | - void modeChanged(Dso::TriggerMode); ///< The trigger mode has been changed | ||
| 151 | - void sourceChanged(bool special, | ||
| 152 | - unsigned int id); ///< The trigger source has been changed | ||
| 153 | - void slopeChanged(Dso::Slope); ///< The trigger slope has been changed | ||
| 154 | -}; | ||
| 155 | - | ||
| 156 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 157 | -/// \class VoltageDock dockwindows.h | ||
| 158 | -/// \brief Dock window for the voltage channel settings. | ||
| 159 | -/// It contains the settings for gain and coupling for both channels and | ||
| 160 | -/// allows to enable/disable the channels. | ||
| 161 | -class VoltageDock : public QDockWidget { | ||
| 162 | - Q_OBJECT | ||
| 163 | - | ||
| 164 | -public: | ||
| 165 | - VoltageDock(DsoSettings *settings, QWidget *parent, | ||
| 166 | - Qt::WindowFlags flags = 0); | ||
| 167 | - ~VoltageDock(); | ||
| 168 | - | ||
| 169 | - int setCoupling(int channel, Dso::Coupling coupling); | ||
| 170 | - int setGain(int channel, double gain); | ||
| 171 | - int setMode(Dso::MathMode mode); | ||
| 172 | - int setUsed(int channel, bool used); | ||
| 173 | - | ||
| 174 | -protected: | ||
| 175 | - void closeEvent(QCloseEvent *event); | ||
| 176 | - | ||
| 177 | - QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 178 | - QWidget *dockWidget; ///< The main widget for the dock window | ||
| 179 | - QList<QCheckBox *> usedCheckBox; ///< Enable/disable a specific channel | ||
| 180 | - QList<QComboBox *> | ||
| 181 | - gainComboBox; ///< Select the vertical gain for the channels | ||
| 182 | - QList<QComboBox *> | ||
| 183 | - miscComboBox; ///< Select coupling for real and mode for math channels | ||
| 184 | - | ||
| 185 | - DsoSettings *settings; ///< The settings provided by the parent class | ||
| 186 | - | ||
| 187 | - QStringList couplingStrings; ///< The strings for the couplings | ||
| 188 | - QStringList modeStrings; ///< The strings for the math mode | ||
| 189 | - QList<double> gainSteps; ///< The selectable gain steps | ||
| 190 | - QStringList gainStrings; ///< String representations for the gain steps | ||
| 191 | - | ||
| 192 | -protected slots: | ||
| 193 | - void gainSelected(int index); | ||
| 194 | - void miscSelected(int index); | ||
| 195 | - void usedSwitched(bool checked); | ||
| 196 | - | ||
| 197 | -signals: | ||
| 198 | - void | ||
| 199 | - couplingChanged(unsigned int channel, | ||
| 200 | - Dso::Coupling coupling); ///< A coupling has been selected | ||
| 201 | - void gainChanged(unsigned int channel, | ||
| 202 | - double gain); ///< A gain has been selected | ||
| 203 | - void modeChanged( | ||
| 204 | - Dso::MathMode mode); ///< The mode for the math channels has been changed | ||
| 205 | - void usedChanged(unsigned int channel, | ||
| 206 | - bool used); ///< A channel has been enabled/disabled | ||
| 207 | -}; | ||
| 208 | - | ||
| 209 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 210 | -/// \class SpectrumDock dockwindows.h | ||
| 211 | -/// \brief Dock window for the spectrum view. | ||
| 212 | -/// It contains the magnitude for all channels and allows to enable/disable the | ||
| 213 | -/// channels. | ||
| 214 | -class SpectrumDock : public QDockWidget { | ||
| 215 | - Q_OBJECT | ||
| 216 | - | ||
| 217 | -public: | ||
| 218 | - SpectrumDock(DsoSettings *settings, QWidget *parent, | ||
| 219 | - Qt::WindowFlags flags = 0); | ||
| 220 | - ~SpectrumDock(); | ||
| 221 | - | ||
| 222 | - int setMagnitude(int channel, double magnitude); | ||
| 223 | - int setUsed(int channel, bool used); | ||
| 224 | - | ||
| 225 | -protected: | ||
| 226 | - void closeEvent(QCloseEvent *event); | ||
| 227 | - | ||
| 228 | - QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 229 | - QWidget *dockWidget; ///< The main widget for the dock window | ||
| 230 | - QList<QCheckBox *> usedCheckBox; ///< Enable/disable spectrum for a channel | ||
| 231 | - QList<QComboBox *> | ||
| 232 | - magnitudeComboBox; ///< Select the vertical magnitude for the spectrums | ||
| 233 | - | ||
| 234 | - DsoSettings *settings; ///< The settings provided by the parent class | ||
| 235 | - | ||
| 236 | - QList<double> magnitudeSteps; ///< The selectable magnitude steps | ||
| 237 | - QStringList | ||
| 238 | - magnitudeStrings; ///< String representations for the magnitude steps | ||
| 239 | - | ||
| 240 | -public slots: | ||
| 241 | - void magnitudeSelected(int index); | ||
| 242 | - void usedSwitched(bool checked); | ||
| 243 | - | ||
| 244 | -signals: | ||
| 245 | - void magnitudeChanged(unsigned int channel, | ||
| 246 | - double magnitude); ///< A magnitude has been selected | ||
| 247 | - void usedChanged(unsigned int channel, | ||
| 248 | - bool used); ///< A spectrum has been enabled/disabled | ||
| 249 | -}; | ||
| 250 | - | ||
| 251 | -#endif |
openhantek/src/docks/SpectrumDock.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#include <QCheckBox> | ||
| 4 | +#include <QCloseEvent> | ||
| 5 | +#include <QComboBox> | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLabel> | ||
| 8 | + | ||
| 9 | +#include <cmath> | ||
| 10 | + | ||
| 11 | +#include "dockwindows.h" | ||
| 12 | +#include "SpectrumDock.h" | ||
| 13 | + | ||
| 14 | +#include "utils/printutils.h" | ||
| 15 | +#include "utils/dsoStrings.h" | ||
| 16 | +#include "settings.h" | ||
| 17 | +#include "sispinbox.h" | ||
| 18 | + | ||
| 19 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 20 | +// class SpectrumDock | ||
| 21 | +/// \brief Initializes the spectrum view docking window. | ||
| 22 | +/// \param settings The target settings object. | ||
| 23 | +/// \param parent The parent widget. | ||
| 24 | +/// \param flags Flags for the window manager. | ||
| 25 | +SpectrumDock::SpectrumDock(DsoSettings *settings, QWidget *parent, | ||
| 26 | + Qt::WindowFlags flags) | ||
| 27 | + : QDockWidget(tr("Spectrum"), parent, flags) { | ||
| 28 | + this->settings = settings; | ||
| 29 | + | ||
| 30 | + // Initialize lists for comboboxes | ||
| 31 | + this->magnitudeSteps << 1e0 << 2e0 << 3e0 << 6e0 << 1e1 << 2e1 << 3e1 << 6e1 | ||
| 32 | + << 1e2 << 2e2 << 3e2 | ||
| 33 | + << 6e2; ///< Magnitude steps in dB/div | ||
| 34 | + for (QList<double>::iterator magnitude = this->magnitudeSteps.begin(); | ||
| 35 | + magnitude != this->magnitudeSteps.end(); ++magnitude) | ||
| 36 | + this->magnitudeStrings << valueToString(*magnitude, | ||
| 37 | + UNIT_DECIBEL, 0); | ||
| 38 | + | ||
| 39 | + // Initialize elements | ||
| 40 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 41 | + ++channel) { | ||
| 42 | + this->magnitudeComboBox.append(new QComboBox()); | ||
| 43 | + this->magnitudeComboBox[channel]->addItems(this->magnitudeStrings); | ||
| 44 | + | ||
| 45 | + this->usedCheckBox.append( | ||
| 46 | + new QCheckBox(this->settings->scope.voltage[channel].name)); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + this->dockLayout = new QGridLayout(); | ||
| 50 | + this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 51 | + this->dockLayout->setColumnStretch(1, 1); | ||
| 52 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 53 | + ++channel) { | ||
| 54 | + this->dockLayout->addWidget(this->usedCheckBox[channel], channel, 0); | ||
| 55 | + this->dockLayout->addWidget(this->magnitudeComboBox[channel], channel, 1); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + this->dockWidget = new QWidget(); | ||
| 59 | + SetupDockWidget(this, dockWidget, dockLayout); | ||
| 60 | + | ||
| 61 | + // Connect signals and slots | ||
| 62 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 63 | + ++channel) { | ||
| 64 | + connect(this->magnitudeComboBox[channel], SIGNAL(currentIndexChanged(int)), | ||
| 65 | + this, SLOT(magnitudeSelected(int))); | ||
| 66 | + connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, | ||
| 67 | + SLOT(usedSwitched(bool))); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + // Set values | ||
| 71 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 72 | + ++channel) { | ||
| 73 | + this->setMagnitude(channel, | ||
| 74 | + this->settings->scope.spectrum[channel].magnitude); | ||
| 75 | + this->setUsed(channel, this->settings->scope.spectrum[channel].used); | ||
| 76 | + } | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +/// \brief Cleans up everything. | ||
| 80 | +SpectrumDock::~SpectrumDock() {} | ||
| 81 | + | ||
| 82 | +/// \brief Don't close the dock, just hide it | ||
| 83 | +/// \param event The close event that should be handled. | ||
| 84 | +void SpectrumDock::closeEvent(QCloseEvent *event) { | ||
| 85 | + this->hide(); | ||
| 86 | + | ||
| 87 | + event->accept(); | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +/// \brief Sets the magnitude for a channel. | ||
| 91 | +/// \param channel The channel, whose magnitude should be set. | ||
| 92 | +/// \param magnitude The magnitude in dB. | ||
| 93 | +/// \return Index of magnitude-value, -1 on error. | ||
| 94 | +int SpectrumDock::setMagnitude(int channel, double magnitude) { | ||
| 95 | + if (channel < 0 || channel >= this->settings->scope.voltage.count()) | ||
| 96 | + return -1; | ||
| 97 | + | ||
| 98 | + int index = this->magnitudeSteps.indexOf(magnitude); | ||
| 99 | + if (index != -1) | ||
| 100 | + this->magnitudeComboBox[channel]->setCurrentIndex(index); | ||
| 101 | + | ||
| 102 | + return index; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +/// \brief Enables/disables a channel. | ||
| 106 | +/// \param channel The channel, that should be enabled/disabled. | ||
| 107 | +/// \param used True if the channel should be enabled, false otherwise. | ||
| 108 | +/// \return Index of channel, -1 on error. | ||
| 109 | +int SpectrumDock::setUsed(int channel, bool used) { | ||
| 110 | + if (channel >= 0 && channel < this->settings->scope.voltage.count()) { | ||
| 111 | + this->usedCheckBox[channel]->setChecked(used); | ||
| 112 | + return channel; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + return -1; | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +/// \brief Called when the source combo box changes it's value. | ||
| 119 | +/// \param index The index of the combo box item. | ||
| 120 | +void SpectrumDock::magnitudeSelected(int index) { | ||
| 121 | + int channel; | ||
| 122 | + | ||
| 123 | + // Which combobox was it? | ||
| 124 | + for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 125 | + if (this->sender() == this->magnitudeComboBox[channel]) | ||
| 126 | + break; | ||
| 127 | + | ||
| 128 | + // Send signal if it was one of the comboboxes | ||
| 129 | + if (channel < this->settings->scope.voltage.count()) { | ||
| 130 | + this->settings->scope.spectrum[channel].magnitude = | ||
| 131 | + this->magnitudeSteps.at(index); | ||
| 132 | + emit magnitudeChanged(channel, | ||
| 133 | + this->settings->scope.spectrum[channel].magnitude); | ||
| 134 | + } | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +/// \brief Called when the used checkbox is switched. | ||
| 138 | +/// \param checked The check-state of the checkbox. | ||
| 139 | +void SpectrumDock::usedSwitched(bool checked) { | ||
| 140 | + int channel; | ||
| 141 | + | ||
| 142 | + // Which checkbox was it? | ||
| 143 | + for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 144 | + if (this->sender() == this->usedCheckBox[channel]) | ||
| 145 | + break; | ||
| 146 | + | ||
| 147 | + // Send signal if it was one of the checkboxes | ||
| 148 | + if (channel < this->settings->scope.voltage.count()) { | ||
| 149 | + this->settings->scope.spectrum[channel].used = checked; | ||
| 150 | + emit usedChanged(channel, checked); | ||
| 151 | + } | ||
| 152 | +} |
openhantek/src/docks/SpectrumDock.h
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#pragma once | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QGridLayout> | ||
| 8 | + | ||
| 9 | +#include "definitions.h" | ||
| 10 | +#include "settings.h" | ||
| 11 | + | ||
| 12 | +class QLabel; | ||
| 13 | +class QCheckBox; | ||
| 14 | +class QComboBox; | ||
| 15 | + | ||
| 16 | +class SiSpinBox; | ||
| 17 | + | ||
| 18 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 19 | +/// \class SpectrumDock dockwindows.h | ||
| 20 | +/// \brief Dock window for the spectrum view. | ||
| 21 | +/// It contains the magnitude for all channels and allows to enable/disable the | ||
| 22 | +/// channels. | ||
| 23 | +class SpectrumDock : public QDockWidget { | ||
| 24 | + Q_OBJECT | ||
| 25 | + | ||
| 26 | +public: | ||
| 27 | + SpectrumDock(DsoSettings *settings, QWidget *parent, | ||
| 28 | + Qt::WindowFlags flags = 0); | ||
| 29 | + ~SpectrumDock(); | ||
| 30 | + | ||
| 31 | + int setMagnitude(int channel, double magnitude); | ||
| 32 | + int setUsed(int channel, bool used); | ||
| 33 | + | ||
| 34 | +protected: | ||
| 35 | + void closeEvent(QCloseEvent *event); | ||
| 36 | + | ||
| 37 | + QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 38 | + QWidget *dockWidget; ///< The main widget for the dock window | ||
| 39 | + QList<QCheckBox *> usedCheckBox; ///< Enable/disable spectrum for a channel | ||
| 40 | + QList<QComboBox *> | ||
| 41 | + magnitudeComboBox; ///< Select the vertical magnitude for the spectrums | ||
| 42 | + | ||
| 43 | + DsoSettings *settings; ///< The settings provided by the parent class | ||
| 44 | + | ||
| 45 | + QList<double> magnitudeSteps; ///< The selectable magnitude steps | ||
| 46 | + QStringList | ||
| 47 | + magnitudeStrings; ///< String representations for the magnitude steps | ||
| 48 | + | ||
| 49 | +public slots: | ||
| 50 | + void magnitudeSelected(int index); | ||
| 51 | + void usedSwitched(bool checked); | ||
| 52 | + | ||
| 53 | +signals: | ||
| 54 | + void magnitudeChanged(unsigned int channel, | ||
| 55 | + double magnitude); ///< A magnitude has been selected | ||
| 56 | + void usedChanged(unsigned int channel, | ||
| 57 | + bool used); ///< A spectrum has been enabled/disabled | ||
| 58 | +}; |
openhantek/src/docks/TriggerDock.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#include <QCheckBox> | ||
| 4 | +#include <QCloseEvent> | ||
| 5 | +#include <QComboBox> | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLabel> | ||
| 8 | + | ||
| 9 | +#include <cmath> | ||
| 10 | + | ||
| 11 | +#include "dockwindows.h" | ||
| 12 | +#include "TriggerDock.h" | ||
| 13 | + | ||
| 14 | +#include "utils/printutils.h" | ||
| 15 | +#include "utils/dsoStrings.h" | ||
| 16 | +#include "settings.h" | ||
| 17 | +#include "sispinbox.h" | ||
| 18 | + | ||
| 19 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 20 | +// class TriggerDock | ||
| 21 | +/// \brief Initializes the trigger settings docking window. | ||
| 22 | +/// \param settings The target settings object. | ||
| 23 | +/// \param specialTriggers The names of the special trigger sources. | ||
| 24 | +/// \param parent The parent widget. | ||
| 25 | +/// \param flags Flags for the window manager. | ||
| 26 | +TriggerDock::TriggerDock(DsoSettings *settings, | ||
| 27 | + const QStringList *specialTriggers, QWidget *parent, | ||
| 28 | + Qt::WindowFlags flags) | ||
| 29 | + : QDockWidget(tr("Trigger"), parent, flags) { | ||
| 30 | + this->settings = settings; | ||
| 31 | + | ||
| 32 | + // Initialize lists for comboboxes | ||
| 33 | + for (unsigned int channel = 0; | ||
| 34 | + channel < this->settings->scope.physicalChannels; ++channel) | ||
| 35 | + this->sourceStandardStrings << tr("CH%1").arg(channel + 1); | ||
| 36 | + this->sourceSpecialStrings << *specialTriggers; | ||
| 37 | + | ||
| 38 | + // Initialize elements | ||
| 39 | + this->modeLabel = new QLabel(tr("Mode")); | ||
| 40 | + this->modeComboBox = new QComboBox(); | ||
| 41 | + for (int mode = Dso::TRIGGERMODE_AUTO; mode < Dso::TRIGGERMODE_COUNT; ++mode) | ||
| 42 | + this->modeComboBox->addItem(Dso::triggerModeString((Dso::TriggerMode)mode)); | ||
| 43 | + | ||
| 44 | + this->slopeLabel = new QLabel(tr("Slope")); | ||
| 45 | + this->slopeComboBox = new QComboBox(); | ||
| 46 | + for (int slope = Dso::SLOPE_POSITIVE; slope < Dso::SLOPE_COUNT; ++slope) | ||
| 47 | + this->slopeComboBox->addItem(Dso::slopeString((Dso::Slope)slope)); | ||
| 48 | + | ||
| 49 | + this->sourceLabel = new QLabel(tr("Source")); | ||
| 50 | + this->sourceComboBox = new QComboBox(); | ||
| 51 | + this->sourceComboBox->addItems(this->sourceStandardStrings); | ||
| 52 | + this->sourceComboBox->addItems(this->sourceSpecialStrings); | ||
| 53 | + | ||
| 54 | + this->dockLayout = new QGridLayout(); | ||
| 55 | + this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 56 | + this->dockLayout->setColumnStretch(1, 1); | ||
| 57 | + this->dockLayout->addWidget(this->modeLabel, 0, 0); | ||
| 58 | + this->dockLayout->addWidget(this->modeComboBox, 0, 1); | ||
| 59 | + this->dockLayout->addWidget(this->sourceLabel, 1, 0); | ||
| 60 | + this->dockLayout->addWidget(this->sourceComboBox, 1, 1); | ||
| 61 | + this->dockLayout->addWidget(this->slopeLabel, 2, 0); | ||
| 62 | + this->dockLayout->addWidget(this->slopeComboBox, 2, 1); | ||
| 63 | + | ||
| 64 | + this->dockWidget = new QWidget(); | ||
| 65 | + SetupDockWidget(this, dockWidget, dockLayout); | ||
| 66 | + | ||
| 67 | + // Connect signals and slots | ||
| 68 | + connect(this->modeComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 69 | + SLOT(modeSelected(int))); | ||
| 70 | + connect(this->slopeComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 71 | + SLOT(slopeSelected(int))); | ||
| 72 | + connect(this->sourceComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 73 | + SLOT(sourceSelected(int))); | ||
| 74 | + | ||
| 75 | + // Set values | ||
| 76 | + this->setMode(this->settings->scope.trigger.mode); | ||
| 77 | + this->setSlope(this->settings->scope.trigger.slope); | ||
| 78 | + this->setSource(this->settings->scope.trigger.special, | ||
| 79 | + this->settings->scope.trigger.source); | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +/// \brief Cleans up everything. | ||
| 83 | +TriggerDock::~TriggerDock() {} | ||
| 84 | + | ||
| 85 | +/// \brief Don't close the dock, just hide it | ||
| 86 | +/// \param event The close event that should be handled. | ||
| 87 | +void TriggerDock::closeEvent(QCloseEvent *event) { | ||
| 88 | + this->hide(); | ||
| 89 | + | ||
| 90 | + event->accept(); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +/// \brief Changes the trigger mode if the new mode is supported. | ||
| 94 | +/// \param mode The trigger mode. | ||
| 95 | +/// \return Index of mode-value, -1 on error. | ||
| 96 | +int TriggerDock::setMode(Dso::TriggerMode mode) { | ||
| 97 | + if (mode >= Dso::TRIGGERMODE_AUTO && mode < Dso::TRIGGERMODE_COUNT) { | ||
| 98 | + this->modeComboBox->setCurrentIndex(mode); | ||
| 99 | + return mode; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + return -1; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +/// \brief Changes the trigger slope if the new slope is supported. | ||
| 106 | +/// \param slope The trigger slope. | ||
| 107 | +/// \return Index of slope-value, -1 on error. | ||
| 108 | +int TriggerDock::setSlope(Dso::Slope slope) { | ||
| 109 | + if (slope >= Dso::SLOPE_POSITIVE && slope <= Dso::SLOPE_NEGATIVE) { | ||
| 110 | + this->slopeComboBox->setCurrentIndex(slope); | ||
| 111 | + return slope; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + return -1; | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +/// \brief Changes the trigger source if the new source is supported. | ||
| 118 | +/// \param special true for a special channel (EXT, ...) as trigger source. | ||
| 119 | +/// \param id The number of the channel, that should be used as trigger. | ||
| 120 | +/// \return Index of source item, -1 on error. | ||
| 121 | +int TriggerDock::setSource(bool special, unsigned int id) { | ||
| 122 | + if ((!special && id >= (unsigned int)this->sourceStandardStrings.count()) || | ||
| 123 | + (special && id >= (unsigned int)this->sourceSpecialStrings.count())) | ||
| 124 | + return -1; | ||
| 125 | + | ||
| 126 | + int index = id; | ||
| 127 | + if (special) | ||
| 128 | + index += this->sourceStandardStrings.count(); | ||
| 129 | + this->sourceComboBox->setCurrentIndex(index); | ||
| 130 | + | ||
| 131 | + return index; | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +/// \brief Called when the mode combo box changes it's value. | ||
| 135 | +/// \param index The index of the combo box item. | ||
| 136 | +void TriggerDock::modeSelected(int index) { | ||
| 137 | + this->settings->scope.trigger.mode = (Dso::TriggerMode)index; | ||
| 138 | + emit modeChanged(this->settings->scope.trigger.mode); | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +/// \brief Called when the slope combo box changes it's value. | ||
| 142 | +/// \param index The index of the combo box item. | ||
| 143 | +void TriggerDock::slopeSelected(int index) { | ||
| 144 | + this->settings->scope.trigger.slope = (Dso::Slope)index; | ||
| 145 | + emit slopeChanged(this->settings->scope.trigger.slope); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +/// \brief Called when the source combo box changes it's value. | ||
| 149 | +/// \param index The index of the combo box item. | ||
| 150 | +void TriggerDock::sourceSelected(int index) { | ||
| 151 | + unsigned int id = index; | ||
| 152 | + bool special = false; | ||
| 153 | + | ||
| 154 | + if (id >= (unsigned int)this->sourceStandardStrings.count()) { | ||
| 155 | + id -= this->sourceStandardStrings.count(); | ||
| 156 | + special = true; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + this->settings->scope.trigger.source = id; | ||
| 160 | + this->settings->scope.trigger.special = special; | ||
| 161 | + emit sourceChanged(special, id); | ||
| 162 | +} |
openhantek/src/docks/TriggerDock.h
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#pragma once | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QGridLayout> | ||
| 8 | + | ||
| 9 | +#include "definitions.h" | ||
| 10 | +#include "settings.h" | ||
| 11 | + | ||
| 12 | +class QLabel; | ||
| 13 | +class QCheckBox; | ||
| 14 | +class QComboBox; | ||
| 15 | + | ||
| 16 | +class SiSpinBox; | ||
| 17 | + | ||
| 18 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 19 | +/// \class TriggerDock dockwindows.h | ||
| 20 | +/// \brief Dock window for the trigger settings. | ||
| 21 | +/// It contains the settings for the trigger mode, source and slope. | ||
| 22 | +class TriggerDock : public QDockWidget { | ||
| 23 | + Q_OBJECT | ||
| 24 | + | ||
| 25 | +public: | ||
| 26 | + TriggerDock(DsoSettings *settings, const QStringList *specialTriggers, | ||
| 27 | + QWidget *parent, Qt::WindowFlags flags = 0); | ||
| 28 | + ~TriggerDock(); | ||
| 29 | + | ||
| 30 | + int setMode(Dso::TriggerMode mode); | ||
| 31 | + int setSource(bool special, unsigned int id); | ||
| 32 | + int setSlope(Dso::Slope slope); | ||
| 33 | + | ||
| 34 | +protected: | ||
| 35 | + void closeEvent(QCloseEvent *event); | ||
| 36 | + | ||
| 37 | + QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 38 | + QWidget *dockWidget; ///< The main widget for the dock window | ||
| 39 | + QLabel *modeLabel; ///< The label for the trigger mode combobox | ||
| 40 | + QLabel *sourceLabel; ///< The label for the trigger source combobox | ||
| 41 | + QLabel *slopeLabel; ///< The label for the trigger slope combobox | ||
| 42 | + QComboBox *modeComboBox; ///< Select the triggering mode | ||
| 43 | + QComboBox *sourceComboBox; ///< Select the source for triggering | ||
| 44 | + QComboBox *slopeComboBox; ///< Select the slope that causes triggering | ||
| 45 | + | ||
| 46 | + DsoSettings *settings; ///< The settings provided by the parent class | ||
| 47 | + | ||
| 48 | + QStringList modeStrings; ///< Strings for the trigger modes | ||
| 49 | + QStringList | ||
| 50 | + sourceStandardStrings; ///< Strings for the standard trigger sources | ||
| 51 | + QStringList sourceSpecialStrings; ///< Strings for the special trigger sources | ||
| 52 | + QStringList slopeStrings; ///< Strings for the trigger slopes | ||
| 53 | + | ||
| 54 | +protected slots: | ||
| 55 | + void modeSelected(int index); | ||
| 56 | + void slopeSelected(int index); | ||
| 57 | + void sourceSelected(int index); | ||
| 58 | + | ||
| 59 | +signals: | ||
| 60 | + void modeChanged(Dso::TriggerMode); ///< The trigger mode has been changed | ||
| 61 | + void sourceChanged(bool special, | ||
| 62 | + unsigned int id); ///< The trigger source has been changed | ||
| 63 | + void slopeChanged(Dso::Slope); ///< The trigger slope has been changed | ||
| 64 | +}; |
openhantek/src/docks/VoltageDock.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#include <QCheckBox> | ||
| 4 | +#include <QCloseEvent> | ||
| 5 | +#include <QComboBox> | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLabel> | ||
| 8 | + | ||
| 9 | +#include <cmath> | ||
| 10 | + | ||
| 11 | +#include "dockwindows.h" | ||
| 12 | +#include "VoltageDock.h" | ||
| 13 | + | ||
| 14 | +#include "utils/printutils.h" | ||
| 15 | +#include "utils/dsoStrings.h" | ||
| 16 | +#include "settings.h" | ||
| 17 | +#include "sispinbox.h" | ||
| 18 | + | ||
| 19 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 20 | +// class VoltageDock | ||
| 21 | +/// \brief Initializes the vertical axis docking window. | ||
| 22 | +/// \param settings The target settings object. | ||
| 23 | +/// \param parent The parent widget. | ||
| 24 | +/// \param flags Flags for the window manager. | ||
| 25 | +VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, | ||
| 26 | + Qt::WindowFlags flags) | ||
| 27 | + : QDockWidget(tr("Voltage"), parent, flags) { | ||
| 28 | + this->settings = settings; | ||
| 29 | + | ||
| 30 | + // Initialize lists for comboboxes | ||
| 31 | + for (int coupling = Dso::COUPLING_AC; coupling < Dso::COUPLING_COUNT; | ||
| 32 | + ++coupling) | ||
| 33 | + this->couplingStrings.append(Dso::couplingString((Dso::Coupling)coupling)); | ||
| 34 | + | ||
| 35 | + for (int mode = Dso::MATHMODE_1ADD2; mode < Dso::MATHMODE_COUNT; ++mode) | ||
| 36 | + this->modeStrings.append(Dso::mathModeString((Dso::MathMode)mode)); | ||
| 37 | + | ||
| 38 | + this->gainSteps << 1e-2 << 2e-2 << 5e-2 << 1e-1 << 2e-1 << 5e-1 << 1e0 << 2e0 | ||
| 39 | + << 5e0; ///< Voltage steps in V/div | ||
| 40 | + for (QList<double>::iterator gain = this->gainSteps.begin(); | ||
| 41 | + gain != this->gainSteps.end(); ++gain) | ||
| 42 | + this->gainStrings << valueToString(*gain, UNIT_VOLTS, 0); | ||
| 43 | + | ||
| 44 | + // Initialize elements | ||
| 45 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 46 | + ++channel) { | ||
| 47 | + this->miscComboBox.append(new QComboBox()); | ||
| 48 | + if (channel < (int)this->settings->scope.physicalChannels) | ||
| 49 | + this->miscComboBox[channel]->addItems(this->couplingStrings); | ||
| 50 | + else | ||
| 51 | + this->miscComboBox[channel]->addItems(this->modeStrings); | ||
| 52 | + | ||
| 53 | + this->gainComboBox.append(new QComboBox()); | ||
| 54 | + this->gainComboBox[channel]->addItems(this->gainStrings); | ||
| 55 | + | ||
| 56 | + this->usedCheckBox.append( | ||
| 57 | + new QCheckBox(this->settings->scope.voltage[channel].name)); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + this->dockLayout = new QGridLayout(); | ||
| 61 | + this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 62 | + this->dockLayout->setColumnStretch(1, 1); | ||
| 63 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 64 | + ++channel) { | ||
| 65 | + this->dockLayout->addWidget(this->usedCheckBox[channel], channel * 2, 0); | ||
| 66 | + this->dockLayout->addWidget(this->gainComboBox[channel], channel * 2, 1); | ||
| 67 | + this->dockLayout->addWidget(this->miscComboBox[channel], channel * 2 + 1, | ||
| 68 | + 1); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + this->dockWidget = new QWidget(); | ||
| 72 | + SetupDockWidget(this, dockWidget, dockLayout); | ||
| 73 | + | ||
| 74 | + // Connect signals and slots | ||
| 75 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 76 | + ++channel) { | ||
| 77 | + connect(this->gainComboBox[channel], SIGNAL(currentIndexChanged(int)), this, | ||
| 78 | + SLOT(gainSelected(int))); | ||
| 79 | + connect(this->miscComboBox[channel], SIGNAL(currentIndexChanged(int)), this, | ||
| 80 | + SLOT(miscSelected(int))); | ||
| 81 | + connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, | ||
| 82 | + SLOT(usedSwitched(bool))); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + // Set values | ||
| 86 | + for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 87 | + ++channel) { | ||
| 88 | + if (channel < (int)this->settings->scope.physicalChannels) | ||
| 89 | + this->setCoupling( | ||
| 90 | + channel, (Dso::Coupling)this->settings->scope.voltage[channel].misc); | ||
| 91 | + else | ||
| 92 | + this->setMode((Dso::MathMode)this->settings->scope.voltage[channel].misc); | ||
| 93 | + this->setGain(channel, this->settings->scope.voltage[channel].gain); | ||
| 94 | + this->setUsed(channel, this->settings->scope.voltage[channel].used); | ||
| 95 | + } | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +/// \brief Cleans up everything. | ||
| 99 | +VoltageDock::~VoltageDock() {} | ||
| 100 | + | ||
| 101 | +/// \brief Don't close the dock, just hide it | ||
| 102 | +/// \param event The close event that should be handled. | ||
| 103 | +void VoltageDock::closeEvent(QCloseEvent *event) { | ||
| 104 | + this->hide(); | ||
| 105 | + | ||
| 106 | + event->accept(); | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +/// \brief Sets the coupling for a channel. | ||
| 110 | +/// \param channel The channel, whose coupling should be set. | ||
| 111 | +/// \param coupling The coupling-mode. | ||
| 112 | +/// \return Index of coupling-mode, -1 on error. | ||
| 113 | +int VoltageDock::setCoupling(int channel, Dso::Coupling coupling) { | ||
| 114 | + if (coupling < Dso::COUPLING_AC || coupling > Dso::COUPLING_GND) | ||
| 115 | + return -1; | ||
| 116 | + if (channel < 0 || channel >= (int)this->settings->scope.physicalChannels) | ||
| 117 | + return -1; | ||
| 118 | + | ||
| 119 | + this->miscComboBox[channel]->setCurrentIndex(coupling); | ||
| 120 | + return coupling; | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +/// \brief Sets the gain for a channel. | ||
| 124 | +/// \param channel The channel, whose gain should be set. | ||
| 125 | +/// \param gain The gain in volts. | ||
| 126 | +/// \return Index of gain-value, -1 on error. | ||
| 127 | +int VoltageDock::setGain(int channel, double gain) { | ||
| 128 | + if (channel < 0 || channel >= this->settings->scope.voltage.count()) | ||
| 129 | + return -1; | ||
| 130 | + | ||
| 131 | + int index = this->gainSteps.indexOf(gain); | ||
| 132 | + if (index != -1) | ||
| 133 | + this->gainComboBox[channel]->setCurrentIndex(index); | ||
| 134 | + | ||
| 135 | + return index; | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +/// \brief Sets the mode for the math channel. | ||
| 139 | +/// \param mode The math-mode. | ||
| 140 | +/// \return Index of math-mode, -1 on error. | ||
| 141 | +int VoltageDock::setMode(Dso::MathMode mode) { | ||
| 142 | + if (mode >= Dso::MATHMODE_1ADD2 && mode <= Dso::MATHMODE_2SUB1) { | ||
| 143 | + this->miscComboBox[this->settings->scope.physicalChannels]->setCurrentIndex( | ||
| 144 | + mode); | ||
| 145 | + return mode; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + return -1; | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +/// \brief Enables/disables a channel. | ||
| 152 | +/// \param channel The channel, that should be enabled/disabled. | ||
| 153 | +/// \param used True if the channel should be enabled, false otherwise. | ||
| 154 | +/// \return Index of channel, -1 on error. | ||
| 155 | +int VoltageDock::setUsed(int channel, bool used) { | ||
| 156 | + if (channel >= 0 && channel < this->settings->scope.voltage.count()) { | ||
| 157 | + this->usedCheckBox[channel]->setChecked(used); | ||
| 158 | + return channel; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + return -1; | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +/// \brief Called when the gain combo box changes it's value. | ||
| 165 | +/// \param index The index of the combo box item. | ||
| 166 | +void VoltageDock::gainSelected(int index) { | ||
| 167 | + int channel; | ||
| 168 | + | ||
| 169 | + // Which combobox was it? | ||
| 170 | + for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 171 | + if (this->sender() == this->gainComboBox[channel]) | ||
| 172 | + break; | ||
| 173 | + | ||
| 174 | + // Send signal if it was one of the comboboxes | ||
| 175 | + if (channel < this->settings->scope.voltage.count()) { | ||
| 176 | + this->settings->scope.voltage[channel].gain = this->gainSteps.at(index); | ||
| 177 | + | ||
| 178 | + emit gainChanged(channel, this->settings->scope.voltage[channel].gain); | ||
| 179 | + } | ||
| 180 | +} | ||
| 181 | + | ||
| 182 | +/// \brief Called when the misc combo box changes it's value. | ||
| 183 | +/// \param index The index of the combo box item. | ||
| 184 | +void VoltageDock::miscSelected(int index) { | ||
| 185 | + int channel; | ||
| 186 | + | ||
| 187 | + // Which combobox was it? | ||
| 188 | + for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 189 | + if (this->sender() == this->miscComboBox[channel]) | ||
| 190 | + break; | ||
| 191 | + | ||
| 192 | + // Send signal if it was one of the comboboxes | ||
| 193 | + if (channel < this->settings->scope.voltage.count()) { | ||
| 194 | + this->settings->scope.voltage[channel].misc = index; | ||
| 195 | + if (channel < (int)this->settings->scope.physicalChannels) | ||
| 196 | + emit couplingChanged( | ||
| 197 | + channel, (Dso::Coupling)this->settings->scope.voltage[channel].misc); | ||
| 198 | + else | ||
| 199 | + emit modeChanged( | ||
| 200 | + (Dso::MathMode)this->settings->scope.voltage[channel].misc); | ||
| 201 | + } | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +/// \brief Called when the used checkbox is switched. | ||
| 205 | +/// \param checked The check-state of the checkbox. | ||
| 206 | +void VoltageDock::usedSwitched(bool checked) { | ||
| 207 | + int channel; | ||
| 208 | + | ||
| 209 | + // Which checkbox was it? | ||
| 210 | + for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 211 | + if (this->sender() == this->usedCheckBox[channel]) | ||
| 212 | + break; | ||
| 213 | + | ||
| 214 | + // Send signal if it was one of the checkboxes | ||
| 215 | + if (channel < this->settings->scope.voltage.count()) { | ||
| 216 | + this->settings->scope.voltage[channel].used = checked; | ||
| 217 | + emit usedChanged(channel, checked); | ||
| 218 | + } | ||
| 219 | +} |
openhantek/src/docks/VoltageDock.h
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#pragma once | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QGridLayout> | ||
| 8 | + | ||
| 9 | +#include "definitions.h" | ||
| 10 | +#include "settings.h" | ||
| 11 | + | ||
| 12 | +class QLabel; | ||
| 13 | +class QCheckBox; | ||
| 14 | +class QComboBox; | ||
| 15 | + | ||
| 16 | +class SiSpinBox; | ||
| 17 | + | ||
| 18 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 19 | +/// \class VoltageDock dockwindows.h | ||
| 20 | +/// \brief Dock window for the voltage channel settings. | ||
| 21 | +/// It contains the settings for gain and coupling for both channels and | ||
| 22 | +/// allows to enable/disable the channels. | ||
| 23 | +class VoltageDock : public QDockWidget { | ||
| 24 | + Q_OBJECT | ||
| 25 | + | ||
| 26 | +public: | ||
| 27 | + VoltageDock(DsoSettings *settings, QWidget *parent, | ||
| 28 | + Qt::WindowFlags flags = 0); | ||
| 29 | + ~VoltageDock(); | ||
| 30 | + | ||
| 31 | + int setCoupling(int channel, Dso::Coupling coupling); | ||
| 32 | + int setGain(int channel, double gain); | ||
| 33 | + int setMode(Dso::MathMode mode); | ||
| 34 | + int setUsed(int channel, bool used); | ||
| 35 | + | ||
| 36 | +protected: | ||
| 37 | + void closeEvent(QCloseEvent *event); | ||
| 38 | + | ||
| 39 | + QGridLayout *dockLayout; ///< The main layout for the dock window | ||
| 40 | + QWidget *dockWidget; ///< The main widget for the dock window | ||
| 41 | + QList<QCheckBox *> usedCheckBox; ///< Enable/disable a specific channel | ||
| 42 | + QList<QComboBox *> | ||
| 43 | + gainComboBox; ///< Select the vertical gain for the channels | ||
| 44 | + QList<QComboBox *> | ||
| 45 | + miscComboBox; ///< Select coupling for real and mode for math channels | ||
| 46 | + | ||
| 47 | + DsoSettings *settings; ///< The settings provided by the parent class | ||
| 48 | + | ||
| 49 | + QStringList couplingStrings; ///< The strings for the couplings | ||
| 50 | + QStringList modeStrings; ///< The strings for the math mode | ||
| 51 | + QList<double> gainSteps; ///< The selectable gain steps | ||
| 52 | + QStringList gainStrings; ///< String representations for the gain steps | ||
| 53 | + | ||
| 54 | +protected slots: | ||
| 55 | + void gainSelected(int index); | ||
| 56 | + void miscSelected(int index); | ||
| 57 | + void usedSwitched(bool checked); | ||
| 58 | + | ||
| 59 | +signals: | ||
| 60 | + void | ||
| 61 | + couplingChanged(unsigned int channel, | ||
| 62 | + Dso::Coupling coupling); ///< A coupling has been selected | ||
| 63 | + void gainChanged(unsigned int channel, | ||
| 64 | + double gain); ///< A gain has been selected | ||
| 65 | + void modeChanged( | ||
| 66 | + Dso::MathMode mode); ///< The mode for the math channels has been changed | ||
| 67 | + void usedChanged(unsigned int channel, | ||
| 68 | + bool used); ///< A channel has been enabled/disabled | ||
| 69 | +}; |
openhantek/src/docks/dockwindows.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#include <QCheckBox> | ||
| 4 | +#include <QCloseEvent> | ||
| 5 | +#include <QComboBox> | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLabel> | ||
| 8 | + | ||
| 9 | +#include <cmath> | ||
| 10 | + | ||
| 11 | +#include "dockwindows.h" | ||
| 12 | + | ||
| 13 | +void SetupDockWidget(QDockWidget *dockWindow, QWidget *dockWidget, QLayout *layout) { | ||
| 14 | + dockWindow->setObjectName(dockWindow->windowTitle()); | ||
| 15 | + dockWindow->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); | ||
| 16 | + dockWidget->setLayout(layout); | ||
| 17 | + dockWidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, | ||
| 18 | + QSizePolicy::DefaultType)); | ||
| 19 | + dockWindow->setWidget(dockWidget); | ||
| 20 | +} |
openhantek/src/docks/dockwindows.h
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | + | ||
| 3 | +#pragma once | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +#include <QDockWidget> | ||
| 7 | +#include <QLayout> | ||
| 8 | + | ||
| 9 | +void SetupDockWidget(QDockWidget *dockWindow, QWidget *dockWidget, QLayout *layout); | ||
| 10 | + | ||
| 11 | +#include "HorizontalDock.h" | ||
| 12 | +#include "SpectrumDock.h" | ||
| 13 | +#include "TriggerDock.h" | ||
| 14 | +#include "VoltageDock.h" |
openhantek/src/dockwindows.cpp deleted
| 1 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 2 | -// | ||
| 3 | -// OpenHantek | ||
| 4 | -// dockwindows.cpp | ||
| 5 | -// | ||
| 6 | -// Copyright (C) 2010 Oliver Haag | ||
| 7 | -// oliver.haag@gmail.com | ||
| 8 | -// | ||
| 9 | -// This program is free software: you can redistribute it and/or modify it | ||
| 10 | -// under the terms of the GNU General Public License as published by the Free | ||
| 11 | -// Software Foundation, either version 3 of the License, or (at your option) | ||
| 12 | -// any later version. | ||
| 13 | -// | ||
| 14 | -// This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 15 | -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 16 | -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 17 | -// more details. | ||
| 18 | -// | ||
| 19 | -// You should have received a copy of the GNU General Public License along with | ||
| 20 | -// this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -// | ||
| 22 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 23 | - | ||
| 24 | -#include <QCheckBox> | ||
| 25 | -#include <QCloseEvent> | ||
| 26 | -#include <QComboBox> | ||
| 27 | -#include <QDockWidget> | ||
| 28 | -#include <QLabel> | ||
| 29 | - | ||
| 30 | -#include <cmath> | ||
| 31 | - | ||
| 32 | -#include "dockwindows.h" | ||
| 33 | - | ||
| 34 | -#include "utils/printutils.h" | ||
| 35 | -#include "utils/dsoStrings.h" | ||
| 36 | -#include "settings.h" | ||
| 37 | -#include "sispinbox.h" | ||
| 38 | - | ||
| 39 | -namespace { | ||
| 40 | - | ||
| 41 | -void SetupDockWidget(QDockWidget *dockWindow, QWidget *dockWidget, QLayout *layout) { | ||
| 42 | - dockWindow->setObjectName(dockWindow->windowTitle()); | ||
| 43 | - dockWindow->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); | ||
| 44 | - dockWidget->setLayout(layout); | ||
| 45 | - dockWidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, | ||
| 46 | - QSizePolicy::DefaultType)); | ||
| 47 | - dockWindow->setWidget(dockWidget); | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | -} | ||
| 51 | - | ||
| 52 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 53 | -// class HorizontalDock | ||
| 54 | -/// \brief Initializes the horizontal axis docking window. | ||
| 55 | -/// \param settings The target settings object. | ||
| 56 | -/// \param parent The parent widget. | ||
| 57 | -/// \param flags Flags for the window manager. | ||
| 58 | -HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, | ||
| 59 | - Qt::WindowFlags flags) | ||
| 60 | - : QDockWidget(tr("Horizontal"), parent, flags) { | ||
| 61 | - this->settings = settings; | ||
| 62 | - | ||
| 63 | - // Initialize elements | ||
| 64 | - this->samplerateLabel = new QLabel(tr("Samplerate")); | ||
| 65 | - this->samplerateSiSpinBox = new SiSpinBox(UNIT_SAMPLES); | ||
| 66 | - this->samplerateSiSpinBox->setMinimum(1); | ||
| 67 | - this->samplerateSiSpinBox->setMaximum(1e8); | ||
| 68 | - this->samplerateSiSpinBox->setUnitPostfix("/s"); | ||
| 69 | - | ||
| 70 | - timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0; | ||
| 71 | - | ||
| 72 | - this->timebaseLabel = new QLabel(tr("Timebase")); | ||
| 73 | - this->timebaseSiSpinBox = new SiSpinBox(UNIT_SECONDS); | ||
| 74 | - this->timebaseSiSpinBox->setSteps(timebaseSteps); | ||
| 75 | - this->timebaseSiSpinBox->setMinimum(1e-9); | ||
| 76 | - this->timebaseSiSpinBox->setMaximum(3.6e3); | ||
| 77 | - | ||
| 78 | - this->frequencybaseLabel = new QLabel(tr("Frequencybase")); | ||
| 79 | - this->frequencybaseSiSpinBox = new SiSpinBox(UNIT_HERTZ); | ||
| 80 | - this->frequencybaseSiSpinBox->setMinimum(1.0); | ||
| 81 | - this->frequencybaseSiSpinBox->setMaximum(100e6); | ||
| 82 | - | ||
| 83 | - this->recordLengthLabel = new QLabel(tr("Record length")); | ||
| 84 | - this->recordLengthComboBox = new QComboBox(); | ||
| 85 | - | ||
| 86 | - this->formatLabel = new QLabel(tr("Format")); | ||
| 87 | - this->formatComboBox = new QComboBox(); | ||
| 88 | - for (int format = Dso::GRAPHFORMAT_TY; format < Dso::GRAPHFORMAT_COUNT; | ||
| 89 | - ++format) | ||
| 90 | - this->formatComboBox->addItem( | ||
| 91 | - Dso::graphFormatString((Dso::GraphFormat)format)); | ||
| 92 | - | ||
| 93 | - this->dockLayout = new QGridLayout(); | ||
| 94 | - this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 95 | - this->dockLayout->setColumnStretch(1, 1); | ||
| 96 | - this->dockLayout->addWidget(this->samplerateLabel, 0, 0); | ||
| 97 | - this->dockLayout->addWidget(this->samplerateSiSpinBox, 0, 1); | ||
| 98 | - this->dockLayout->addWidget(this->timebaseLabel, 1, 0); | ||
| 99 | - this->dockLayout->addWidget(this->timebaseSiSpinBox, 1, 1); | ||
| 100 | - this->dockLayout->addWidget(this->frequencybaseLabel, 2, 0); | ||
| 101 | - this->dockLayout->addWidget(this->frequencybaseSiSpinBox, 2, 1); | ||
| 102 | - this->dockLayout->addWidget(this->recordLengthLabel, 3, 0); | ||
| 103 | - this->dockLayout->addWidget(this->recordLengthComboBox, 3, 1); | ||
| 104 | - this->dockLayout->addWidget(this->formatLabel, 4, 0); | ||
| 105 | - this->dockLayout->addWidget(this->formatComboBox, 4, 1); | ||
| 106 | - | ||
| 107 | - this->dockWidget = new QWidget(); | ||
| 108 | - SetupDockWidget(this, dockWidget, dockLayout); | ||
| 109 | - | ||
| 110 | - // Connect signals and slots | ||
| 111 | - connect(this->samplerateSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 112 | - SLOT(samplerateSelected(double))); | ||
| 113 | - connect(this->timebaseSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 114 | - SLOT(timebaseSelected(double))); | ||
| 115 | - connect(this->frequencybaseSiSpinBox, SIGNAL(valueChanged(double)), this, | ||
| 116 | - SLOT(frequencybaseSelected(double))); | ||
| 117 | - connect(this->recordLengthComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 118 | - SLOT(recordLengthSelected(int))); | ||
| 119 | - connect(this->formatComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 120 | - SLOT(formatSelected(int))); | ||
| 121 | - | ||
| 122 | - // Set values | ||
| 123 | - this->setSamplerate(this->settings->scope.horizontal.samplerate); | ||
| 124 | - this->setTimebase(this->settings->scope.horizontal.timebase); | ||
| 125 | - this->setFrequencybase(this->settings->scope.horizontal.frequencybase); | ||
| 126 | - this->setRecordLength(this->settings->scope.horizontal.recordLength); | ||
| 127 | - this->setFormat(this->settings->scope.horizontal.format); | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | -/// \brief Cleans up everything. | ||
| 131 | -HorizontalDock::~HorizontalDock() {} | ||
| 132 | - | ||
| 133 | -/// \brief Don't close the dock, just hide it. | ||
| 134 | -/// \param event The close event that should be handled. | ||
| 135 | -void HorizontalDock::closeEvent(QCloseEvent *event) { | ||
| 136 | - this->hide(); | ||
| 137 | - | ||
| 138 | - event->accept(); | ||
| 139 | -} | ||
| 140 | - | ||
| 141 | -/// \brief Changes the frequencybase. | ||
| 142 | -/// \param frequencybase The frequencybase in hertz. | ||
| 143 | -void HorizontalDock::setFrequencybase(double frequencybase) { | ||
| 144 | - this->suppressSignals = true; | ||
| 145 | - this->frequencybaseSiSpinBox->setValue(frequencybase); | ||
| 146 | - this->suppressSignals = false; | ||
| 147 | -} | ||
| 148 | - | ||
| 149 | -/// \brief Changes the samplerate. | ||
| 150 | -/// \param samplerate The samplerate in seconds. | ||
| 151 | -void HorizontalDock::setSamplerate(double samplerate) { | ||
| 152 | - this->suppressSignals = true; | ||
| 153 | - this->samplerateSiSpinBox->setValue(samplerate); | ||
| 154 | - this->suppressSignals = false; | ||
| 155 | -} | ||
| 156 | - | ||
| 157 | -/// \brief Changes the timebase. | ||
| 158 | -/// \param timebase The timebase in seconds. | ||
| 159 | -double HorizontalDock::setTimebase(double timebase) { | ||
| 160 | - // timebaseSteps are repeated in each decade | ||
| 161 | - double decade = pow(10, floor(log10(timebase))); | ||
| 162 | - double vNorm = timebase / decade; | ||
| 163 | - for (int i = 0; i < timebaseSteps.size() - 1; ++i) { | ||
| 164 | - if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) { | ||
| 165 | - suppressSignals = true; | ||
| 166 | - timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i)); | ||
| 167 | - suppressSignals = false; | ||
| 168 | - break; | ||
| 169 | - } | ||
| 170 | - } | ||
| 171 | - return timebaseSiSpinBox->value(); | ||
| 172 | -} | ||
| 173 | - | ||
| 174 | -/// \brief Changes the record length if the new value is supported. | ||
| 175 | -/// \param recordLength The record length in samples. | ||
| 176 | -void HorizontalDock::setRecordLength(unsigned int recordLength) { | ||
| 177 | - int index = this->recordLengthComboBox->findData(recordLength); | ||
| 178 | - | ||
| 179 | - if (index != -1) { | ||
| 180 | - this->suppressSignals = true; | ||
| 181 | - this->recordLengthComboBox->setCurrentIndex(index); | ||
| 182 | - this->suppressSignals = false; | ||
| 183 | - } | ||
| 184 | -} | ||
| 185 | - | ||
| 186 | -/// \brief Changes the format if the new value is supported. | ||
| 187 | -/// \param format The format for the horizontal axis. | ||
| 188 | -/// \return Index of format-value, -1 on error. | ||
| 189 | -int HorizontalDock::setFormat(Dso::GraphFormat format) { | ||
| 190 | - if (format >= Dso::GRAPHFORMAT_TY && format <= Dso::GRAPHFORMAT_XY) { | ||
| 191 | - this->suppressSignals = true; | ||
| 192 | - this->formatComboBox->setCurrentIndex(format); | ||
| 193 | - this->suppressSignals = false; | ||
| 194 | - return format; | ||
| 195 | - } | ||
| 196 | - | ||
| 197 | - return -1; | ||
| 198 | -} | ||
| 199 | - | ||
| 200 | -/// \brief Updates the available record lengths in the combo box. | ||
| 201 | -/// \param recordLengths The available record lengths for the combo box. | ||
| 202 | -void HorizontalDock::availableRecordLengthsChanged( | ||
| 203 | - const QList<unsigned int> &recordLengths) { | ||
| 204 | - /// \todo Empty lists should be interpreted as scope supporting continuous | ||
| 205 | - /// record length values. | ||
| 206 | - this->recordLengthComboBox->blockSignals( | ||
| 207 | - true); // Avoid messing up the settings | ||
| 208 | - this->recordLengthComboBox->setUpdatesEnabled(false); | ||
| 209 | - | ||
| 210 | - // Update existing elements to avoid unnecessary index updates | ||
| 211 | - int index = 0; | ||
| 212 | - for (; index < recordLengths.size(); ++index) { | ||
| 213 | - unsigned int recordLengthItem = recordLengths[index]; | ||
| 214 | - if (index < this->recordLengthComboBox->count()) { | ||
| 215 | - this->recordLengthComboBox->setItemData(index, recordLengthItem); | ||
| 216 | - this->recordLengthComboBox->setItemText( | ||
| 217 | - index, recordLengthItem == UINT_MAX | ||
| 218 | - ? tr("Roll") | ||
| 219 | - : valueToString(recordLengthItem, | ||
| 220 | - UNIT_SAMPLES, 3)); | ||
| 221 | - } else { | ||
| 222 | - this->recordLengthComboBox->addItem( | ||
| 223 | - recordLengthItem == UINT_MAX | ||
| 224 | - ? tr("Roll") | ||
| 225 | - : valueToString(recordLengthItem, UNIT_SAMPLES, | ||
| 226 | - 3), | ||
| 227 | - (uint)recordLengthItem); | ||
| 228 | - } | ||
| 229 | - } | ||
| 230 | - // Remove extra elements | ||
| 231 | - for (int extraIndex = this->recordLengthComboBox->count() - 1; | ||
| 232 | - extraIndex > index; --extraIndex) { | ||
| 233 | - this->recordLengthComboBox->removeItem(extraIndex); | ||
| 234 | - } | ||
| 235 | - | ||
| 236 | - this->setRecordLength(this->settings->scope.horizontal.recordLength); | ||
| 237 | - this->recordLengthComboBox->setUpdatesEnabled(true); | ||
| 238 | - this->recordLengthComboBox->blockSignals(false); | ||
| 239 | -} | ||
| 240 | - | ||
| 241 | -/// \brief Updates the minimum and maximum of the samplerate spin box. | ||
| 242 | -/// \param minimum The minimum value the spin box should accept. | ||
| 243 | -/// \param maximum The minimum value the spin box should accept. | ||
| 244 | -void HorizontalDock::samplerateLimitsChanged(double minimum, double maximum) { | ||
| 245 | - this->suppressSignals = true; | ||
| 246 | - this->samplerateSiSpinBox->setMinimum(minimum); | ||
| 247 | - this->samplerateSiSpinBox->setMaximum(maximum); | ||
| 248 | - this->suppressSignals = false; | ||
| 249 | -} | ||
| 250 | - | ||
| 251 | -/// \brief Updates the mode and steps of the samplerate spin box. | ||
| 252 | -/// \param mode The mode value the spin box should accept. | ||
| 253 | -/// \param steps The steps value the spin box should accept. | ||
| 254 | -void HorizontalDock::samplerateSet(int mode, QList<double> steps) { | ||
| 255 | - this->suppressSignals = true; | ||
| 256 | - this->samplerateSiSpinBox->setMode(mode); | ||
| 257 | - this->samplerateSiSpinBox->setSteps(steps); | ||
| 258 | - this->suppressSignals = false; | ||
| 259 | -} | ||
| 260 | - | ||
| 261 | -/// \brief Called when the frequencybase spinbox changes its value. | ||
| 262 | -/// \param frequencybase The frequencybase in hertz. | ||
| 263 | -void HorizontalDock::frequencybaseSelected(double frequencybase) { | ||
| 264 | - this->settings->scope.horizontal.frequencybase = frequencybase; | ||
| 265 | - if (!this->suppressSignals) | ||
| 266 | - emit frequencybaseChanged(frequencybase); | ||
| 267 | -} | ||
| 268 | - | ||
| 269 | -/// \brief Called when the samplerate spinbox changes its value. | ||
| 270 | -/// \param samplerate The samplerate in samples/second. | ||
| 271 | -void HorizontalDock::samplerateSelected(double samplerate) { | ||
| 272 | - this->settings->scope.horizontal.samplerate = samplerate; | ||
| 273 | - if (!this->suppressSignals) { | ||
| 274 | - this->settings->scope.horizontal.samplerateSet = true; | ||
| 275 | - emit samplerateChanged(samplerate); | ||
| 276 | - } | ||
| 277 | -} | ||
| 278 | - | ||
| 279 | -/// \brief Called when the timebase spinbox changes its value. | ||
| 280 | -/// \param timebase The timebase in seconds. | ||
| 281 | -void HorizontalDock::timebaseSelected(double timebase) { | ||
| 282 | - this->settings->scope.horizontal.timebase = timebase; | ||
| 283 | - if (!this->suppressSignals) { | ||
| 284 | - this->settings->scope.horizontal.samplerateSet = false; | ||
| 285 | - emit timebaseChanged(timebase); | ||
| 286 | - } | ||
| 287 | -} | ||
| 288 | - | ||
| 289 | -/// \brief Called when the record length combo box changes its value. | ||
| 290 | -/// \param index The index of the combo box item. | ||
| 291 | -void HorizontalDock::recordLengthSelected(int index) { | ||
| 292 | - this->settings->scope.horizontal.recordLength = | ||
| 293 | - this->recordLengthComboBox->itemData(index).toUInt(); | ||
| 294 | - if (!this->suppressSignals) | ||
| 295 | - emit recordLengthChanged(index); | ||
| 296 | -} | ||
| 297 | - | ||
| 298 | -/// \brief Called when the format combo box changes its value. | ||
| 299 | -/// \param index The index of the combo box item. | ||
| 300 | -void HorizontalDock::formatSelected(int index) { | ||
| 301 | - this->settings->scope.horizontal.format = (Dso::GraphFormat)index; | ||
| 302 | - if (!this->suppressSignals) | ||
| 303 | - emit formatChanged(this->settings->scope.horizontal.format); | ||
| 304 | -} | ||
| 305 | - | ||
| 306 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 307 | -// class TriggerDock | ||
| 308 | -/// \brief Initializes the trigger settings docking window. | ||
| 309 | -/// \param settings The target settings object. | ||
| 310 | -/// \param specialTriggers The names of the special trigger sources. | ||
| 311 | -/// \param parent The parent widget. | ||
| 312 | -/// \param flags Flags for the window manager. | ||
| 313 | -TriggerDock::TriggerDock(DsoSettings *settings, | ||
| 314 | - const QStringList *specialTriggers, QWidget *parent, | ||
| 315 | - Qt::WindowFlags flags) | ||
| 316 | - : QDockWidget(tr("Trigger"), parent, flags) { | ||
| 317 | - this->settings = settings; | ||
| 318 | - | ||
| 319 | - // Initialize lists for comboboxes | ||
| 320 | - for (unsigned int channel = 0; | ||
| 321 | - channel < this->settings->scope.physicalChannels; ++channel) | ||
| 322 | - this->sourceStandardStrings << tr("CH%1").arg(channel + 1); | ||
| 323 | - this->sourceSpecialStrings << *specialTriggers; | ||
| 324 | - | ||
| 325 | - // Initialize elements | ||
| 326 | - this->modeLabel = new QLabel(tr("Mode")); | ||
| 327 | - this->modeComboBox = new QComboBox(); | ||
| 328 | - for (int mode = Dso::TRIGGERMODE_AUTO; mode < Dso::TRIGGERMODE_COUNT; ++mode) | ||
| 329 | - this->modeComboBox->addItem(Dso::triggerModeString((Dso::TriggerMode)mode)); | ||
| 330 | - | ||
| 331 | - this->slopeLabel = new QLabel(tr("Slope")); | ||
| 332 | - this->slopeComboBox = new QComboBox(); | ||
| 333 | - for (int slope = Dso::SLOPE_POSITIVE; slope < Dso::SLOPE_COUNT; ++slope) | ||
| 334 | - this->slopeComboBox->addItem(Dso::slopeString((Dso::Slope)slope)); | ||
| 335 | - | ||
| 336 | - this->sourceLabel = new QLabel(tr("Source")); | ||
| 337 | - this->sourceComboBox = new QComboBox(); | ||
| 338 | - this->sourceComboBox->addItems(this->sourceStandardStrings); | ||
| 339 | - this->sourceComboBox->addItems(this->sourceSpecialStrings); | ||
| 340 | - | ||
| 341 | - this->dockLayout = new QGridLayout(); | ||
| 342 | - this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 343 | - this->dockLayout->setColumnStretch(1, 1); | ||
| 344 | - this->dockLayout->addWidget(this->modeLabel, 0, 0); | ||
| 345 | - this->dockLayout->addWidget(this->modeComboBox, 0, 1); | ||
| 346 | - this->dockLayout->addWidget(this->sourceLabel, 1, 0); | ||
| 347 | - this->dockLayout->addWidget(this->sourceComboBox, 1, 1); | ||
| 348 | - this->dockLayout->addWidget(this->slopeLabel, 2, 0); | ||
| 349 | - this->dockLayout->addWidget(this->slopeComboBox, 2, 1); | ||
| 350 | - | ||
| 351 | - this->dockWidget = new QWidget(); | ||
| 352 | - SetupDockWidget(this, dockWidget, dockLayout); | ||
| 353 | - | ||
| 354 | - // Connect signals and slots | ||
| 355 | - connect(this->modeComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 356 | - SLOT(modeSelected(int))); | ||
| 357 | - connect(this->slopeComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 358 | - SLOT(slopeSelected(int))); | ||
| 359 | - connect(this->sourceComboBox, SIGNAL(currentIndexChanged(int)), this, | ||
| 360 | - SLOT(sourceSelected(int))); | ||
| 361 | - | ||
| 362 | - // Set values | ||
| 363 | - this->setMode(this->settings->scope.trigger.mode); | ||
| 364 | - this->setSlope(this->settings->scope.trigger.slope); | ||
| 365 | - this->setSource(this->settings->scope.trigger.special, | ||
| 366 | - this->settings->scope.trigger.source); | ||
| 367 | -} | ||
| 368 | - | ||
| 369 | -/// \brief Cleans up everything. | ||
| 370 | -TriggerDock::~TriggerDock() {} | ||
| 371 | - | ||
| 372 | -/// \brief Don't close the dock, just hide it | ||
| 373 | -/// \param event The close event that should be handled. | ||
| 374 | -void TriggerDock::closeEvent(QCloseEvent *event) { | ||
| 375 | - this->hide(); | ||
| 376 | - | ||
| 377 | - event->accept(); | ||
| 378 | -} | ||
| 379 | - | ||
| 380 | -/// \brief Changes the trigger mode if the new mode is supported. | ||
| 381 | -/// \param mode The trigger mode. | ||
| 382 | -/// \return Index of mode-value, -1 on error. | ||
| 383 | -int TriggerDock::setMode(Dso::TriggerMode mode) { | ||
| 384 | - if (mode >= Dso::TRIGGERMODE_AUTO && mode < Dso::TRIGGERMODE_COUNT) { | ||
| 385 | - this->modeComboBox->setCurrentIndex(mode); | ||
| 386 | - return mode; | ||
| 387 | - } | ||
| 388 | - | ||
| 389 | - return -1; | ||
| 390 | -} | ||
| 391 | - | ||
| 392 | -/// \brief Changes the trigger slope if the new slope is supported. | ||
| 393 | -/// \param slope The trigger slope. | ||
| 394 | -/// \return Index of slope-value, -1 on error. | ||
| 395 | -int TriggerDock::setSlope(Dso::Slope slope) { | ||
| 396 | - if (slope >= Dso::SLOPE_POSITIVE && slope <= Dso::SLOPE_NEGATIVE) { | ||
| 397 | - this->slopeComboBox->setCurrentIndex(slope); | ||
| 398 | - return slope; | ||
| 399 | - } | ||
| 400 | - | ||
| 401 | - return -1; | ||
| 402 | -} | ||
| 403 | - | ||
| 404 | -/// \brief Changes the trigger source if the new source is supported. | ||
| 405 | -/// \param special true for a special channel (EXT, ...) as trigger source. | ||
| 406 | -/// \param id The number of the channel, that should be used as trigger. | ||
| 407 | -/// \return Index of source item, -1 on error. | ||
| 408 | -int TriggerDock::setSource(bool special, unsigned int id) { | ||
| 409 | - if ((!special && id >= (unsigned int)this->sourceStandardStrings.count()) || | ||
| 410 | - (special && id >= (unsigned int)this->sourceSpecialStrings.count())) | ||
| 411 | - return -1; | ||
| 412 | - | ||
| 413 | - int index = id; | ||
| 414 | - if (special) | ||
| 415 | - index += this->sourceStandardStrings.count(); | ||
| 416 | - this->sourceComboBox->setCurrentIndex(index); | ||
| 417 | - | ||
| 418 | - return index; | ||
| 419 | -} | ||
| 420 | - | ||
| 421 | -/// \brief Called when the mode combo box changes it's value. | ||
| 422 | -/// \param index The index of the combo box item. | ||
| 423 | -void TriggerDock::modeSelected(int index) { | ||
| 424 | - this->settings->scope.trigger.mode = (Dso::TriggerMode)index; | ||
| 425 | - emit modeChanged(this->settings->scope.trigger.mode); | ||
| 426 | -} | ||
| 427 | - | ||
| 428 | -/// \brief Called when the slope combo box changes it's value. | ||
| 429 | -/// \param index The index of the combo box item. | ||
| 430 | -void TriggerDock::slopeSelected(int index) { | ||
| 431 | - this->settings->scope.trigger.slope = (Dso::Slope)index; | ||
| 432 | - emit slopeChanged(this->settings->scope.trigger.slope); | ||
| 433 | -} | ||
| 434 | - | ||
| 435 | -/// \brief Called when the source combo box changes it's value. | ||
| 436 | -/// \param index The index of the combo box item. | ||
| 437 | -void TriggerDock::sourceSelected(int index) { | ||
| 438 | - unsigned int id = index; | ||
| 439 | - bool special = false; | ||
| 440 | - | ||
| 441 | - if (id >= (unsigned int)this->sourceStandardStrings.count()) { | ||
| 442 | - id -= this->sourceStandardStrings.count(); | ||
| 443 | - special = true; | ||
| 444 | - } | ||
| 445 | - | ||
| 446 | - this->settings->scope.trigger.source = id; | ||
| 447 | - this->settings->scope.trigger.special = special; | ||
| 448 | - emit sourceChanged(special, id); | ||
| 449 | -} | ||
| 450 | - | ||
| 451 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 452 | -// class SpectrumDock | ||
| 453 | -/// \brief Initializes the spectrum view docking window. | ||
| 454 | -/// \param settings The target settings object. | ||
| 455 | -/// \param parent The parent widget. | ||
| 456 | -/// \param flags Flags for the window manager. | ||
| 457 | -SpectrumDock::SpectrumDock(DsoSettings *settings, QWidget *parent, | ||
| 458 | - Qt::WindowFlags flags) | ||
| 459 | - : QDockWidget(tr("Spectrum"), parent, flags) { | ||
| 460 | - this->settings = settings; | ||
| 461 | - | ||
| 462 | - // Initialize lists for comboboxes | ||
| 463 | - this->magnitudeSteps << 1e0 << 2e0 << 3e0 << 6e0 << 1e1 << 2e1 << 3e1 << 6e1 | ||
| 464 | - << 1e2 << 2e2 << 3e2 | ||
| 465 | - << 6e2; ///< Magnitude steps in dB/div | ||
| 466 | - for (QList<double>::iterator magnitude = this->magnitudeSteps.begin(); | ||
| 467 | - magnitude != this->magnitudeSteps.end(); ++magnitude) | ||
| 468 | - this->magnitudeStrings << valueToString(*magnitude, | ||
| 469 | - UNIT_DECIBEL, 0); | ||
| 470 | - | ||
| 471 | - // Initialize elements | ||
| 472 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 473 | - ++channel) { | ||
| 474 | - this->magnitudeComboBox.append(new QComboBox()); | ||
| 475 | - this->magnitudeComboBox[channel]->addItems(this->magnitudeStrings); | ||
| 476 | - | ||
| 477 | - this->usedCheckBox.append( | ||
| 478 | - new QCheckBox(this->settings->scope.voltage[channel].name)); | ||
| 479 | - } | ||
| 480 | - | ||
| 481 | - this->dockLayout = new QGridLayout(); | ||
| 482 | - this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 483 | - this->dockLayout->setColumnStretch(1, 1); | ||
| 484 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 485 | - ++channel) { | ||
| 486 | - this->dockLayout->addWidget(this->usedCheckBox[channel], channel, 0); | ||
| 487 | - this->dockLayout->addWidget(this->magnitudeComboBox[channel], channel, 1); | ||
| 488 | - } | ||
| 489 | - | ||
| 490 | - this->dockWidget = new QWidget(); | ||
| 491 | - SetupDockWidget(this, dockWidget, dockLayout); | ||
| 492 | - | ||
| 493 | - // Connect signals and slots | ||
| 494 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 495 | - ++channel) { | ||
| 496 | - connect(this->magnitudeComboBox[channel], SIGNAL(currentIndexChanged(int)), | ||
| 497 | - this, SLOT(magnitudeSelected(int))); | ||
| 498 | - connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, | ||
| 499 | - SLOT(usedSwitched(bool))); | ||
| 500 | - } | ||
| 501 | - | ||
| 502 | - // Set values | ||
| 503 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 504 | - ++channel) { | ||
| 505 | - this->setMagnitude(channel, | ||
| 506 | - this->settings->scope.spectrum[channel].magnitude); | ||
| 507 | - this->setUsed(channel, this->settings->scope.spectrum[channel].used); | ||
| 508 | - } | ||
| 509 | -} | ||
| 510 | - | ||
| 511 | -/// \brief Cleans up everything. | ||
| 512 | -SpectrumDock::~SpectrumDock() {} | ||
| 513 | - | ||
| 514 | -/// \brief Don't close the dock, just hide it | ||
| 515 | -/// \param event The close event that should be handled. | ||
| 516 | -void SpectrumDock::closeEvent(QCloseEvent *event) { | ||
| 517 | - this->hide(); | ||
| 518 | - | ||
| 519 | - event->accept(); | ||
| 520 | -} | ||
| 521 | - | ||
| 522 | -/// \brief Sets the magnitude for a channel. | ||
| 523 | -/// \param channel The channel, whose magnitude should be set. | ||
| 524 | -/// \param magnitude The magnitude in dB. | ||
| 525 | -/// \return Index of magnitude-value, -1 on error. | ||
| 526 | -int SpectrumDock::setMagnitude(int channel, double magnitude) { | ||
| 527 | - if (channel < 0 || channel >= this->settings->scope.voltage.count()) | ||
| 528 | - return -1; | ||
| 529 | - | ||
| 530 | - int index = this->magnitudeSteps.indexOf(magnitude); | ||
| 531 | - if (index != -1) | ||
| 532 | - this->magnitudeComboBox[channel]->setCurrentIndex(index); | ||
| 533 | - | ||
| 534 | - return index; | ||
| 535 | -} | ||
| 536 | - | ||
| 537 | -/// \brief Enables/disables a channel. | ||
| 538 | -/// \param channel The channel, that should be enabled/disabled. | ||
| 539 | -/// \param used True if the channel should be enabled, false otherwise. | ||
| 540 | -/// \return Index of channel, -1 on error. | ||
| 541 | -int SpectrumDock::setUsed(int channel, bool used) { | ||
| 542 | - if (channel >= 0 && channel < this->settings->scope.voltage.count()) { | ||
| 543 | - this->usedCheckBox[channel]->setChecked(used); | ||
| 544 | - return channel; | ||
| 545 | - } | ||
| 546 | - | ||
| 547 | - return -1; | ||
| 548 | -} | ||
| 549 | - | ||
| 550 | -/// \brief Called when the source combo box changes it's value. | ||
| 551 | -/// \param index The index of the combo box item. | ||
| 552 | -void SpectrumDock::magnitudeSelected(int index) { | ||
| 553 | - int channel; | ||
| 554 | - | ||
| 555 | - // Which combobox was it? | ||
| 556 | - for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 557 | - if (this->sender() == this->magnitudeComboBox[channel]) | ||
| 558 | - break; | ||
| 559 | - | ||
| 560 | - // Send signal if it was one of the comboboxes | ||
| 561 | - if (channel < this->settings->scope.voltage.count()) { | ||
| 562 | - this->settings->scope.spectrum[channel].magnitude = | ||
| 563 | - this->magnitudeSteps.at(index); | ||
| 564 | - emit magnitudeChanged(channel, | ||
| 565 | - this->settings->scope.spectrum[channel].magnitude); | ||
| 566 | - } | ||
| 567 | -} | ||
| 568 | - | ||
| 569 | -/// \brief Called when the used checkbox is switched. | ||
| 570 | -/// \param checked The check-state of the checkbox. | ||
| 571 | -void SpectrumDock::usedSwitched(bool checked) { | ||
| 572 | - int channel; | ||
| 573 | - | ||
| 574 | - // Which checkbox was it? | ||
| 575 | - for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 576 | - if (this->sender() == this->usedCheckBox[channel]) | ||
| 577 | - break; | ||
| 578 | - | ||
| 579 | - // Send signal if it was one of the checkboxes | ||
| 580 | - if (channel < this->settings->scope.voltage.count()) { | ||
| 581 | - this->settings->scope.spectrum[channel].used = checked; | ||
| 582 | - emit usedChanged(channel, checked); | ||
| 583 | - } | ||
| 584 | -} | ||
| 585 | - | ||
| 586 | -//////////////////////////////////////////////////////////////////////////////// | ||
| 587 | -// class VoltageDock | ||
| 588 | -/// \brief Initializes the vertical axis docking window. | ||
| 589 | -/// \param settings The target settings object. | ||
| 590 | -/// \param parent The parent widget. | ||
| 591 | -/// \param flags Flags for the window manager. | ||
| 592 | -VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, | ||
| 593 | - Qt::WindowFlags flags) | ||
| 594 | - : QDockWidget(tr("Voltage"), parent, flags) { | ||
| 595 | - this->settings = settings; | ||
| 596 | - | ||
| 597 | - // Initialize lists for comboboxes | ||
| 598 | - for (int coupling = Dso::COUPLING_AC; coupling < Dso::COUPLING_COUNT; | ||
| 599 | - ++coupling) | ||
| 600 | - this->couplingStrings.append(Dso::couplingString((Dso::Coupling)coupling)); | ||
| 601 | - | ||
| 602 | - for (int mode = Dso::MATHMODE_1ADD2; mode < Dso::MATHMODE_COUNT; ++mode) | ||
| 603 | - this->modeStrings.append(Dso::mathModeString((Dso::MathMode)mode)); | ||
| 604 | - | ||
| 605 | - this->gainSteps << 1e-2 << 2e-2 << 5e-2 << 1e-1 << 2e-1 << 5e-1 << 1e0 << 2e0 | ||
| 606 | - << 5e0; ///< Voltage steps in V/div | ||
| 607 | - for (QList<double>::iterator gain = this->gainSteps.begin(); | ||
| 608 | - gain != this->gainSteps.end(); ++gain) | ||
| 609 | - this->gainStrings << valueToString(*gain, UNIT_VOLTS, 0); | ||
| 610 | - | ||
| 611 | - // Initialize elements | ||
| 612 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 613 | - ++channel) { | ||
| 614 | - this->miscComboBox.append(new QComboBox()); | ||
| 615 | - if (channel < (int)this->settings->scope.physicalChannels) | ||
| 616 | - this->miscComboBox[channel]->addItems(this->couplingStrings); | ||
| 617 | - else | ||
| 618 | - this->miscComboBox[channel]->addItems(this->modeStrings); | ||
| 619 | - | ||
| 620 | - this->gainComboBox.append(new QComboBox()); | ||
| 621 | - this->gainComboBox[channel]->addItems(this->gainStrings); | ||
| 622 | - | ||
| 623 | - this->usedCheckBox.append( | ||
| 624 | - new QCheckBox(this->settings->scope.voltage[channel].name)); | ||
| 625 | - } | ||
| 626 | - | ||
| 627 | - this->dockLayout = new QGridLayout(); | ||
| 628 | - this->dockLayout->setColumnMinimumWidth(0, 64); | ||
| 629 | - this->dockLayout->setColumnStretch(1, 1); | ||
| 630 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 631 | - ++channel) { | ||
| 632 | - this->dockLayout->addWidget(this->usedCheckBox[channel], channel * 2, 0); | ||
| 633 | - this->dockLayout->addWidget(this->gainComboBox[channel], channel * 2, 1); | ||
| 634 | - this->dockLayout->addWidget(this->miscComboBox[channel], channel * 2 + 1, | ||
| 635 | - 1); | ||
| 636 | - } | ||
| 637 | - | ||
| 638 | - this->dockWidget = new QWidget(); | ||
| 639 | - SetupDockWidget(this, dockWidget, dockLayout); | ||
| 640 | - | ||
| 641 | - // Connect signals and slots | ||
| 642 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 643 | - ++channel) { | ||
| 644 | - connect(this->gainComboBox[channel], SIGNAL(currentIndexChanged(int)), this, | ||
| 645 | - SLOT(gainSelected(int))); | ||
| 646 | - connect(this->miscComboBox[channel], SIGNAL(currentIndexChanged(int)), this, | ||
| 647 | - SLOT(miscSelected(int))); | ||
| 648 | - connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, | ||
| 649 | - SLOT(usedSwitched(bool))); | ||
| 650 | - } | ||
| 651 | - | ||
| 652 | - // Set values | ||
| 653 | - for (int channel = 0; channel < this->settings->scope.voltage.count(); | ||
| 654 | - ++channel) { | ||
| 655 | - if (channel < (int)this->settings->scope.physicalChannels) | ||
| 656 | - this->setCoupling( | ||
| 657 | - channel, (Dso::Coupling)this->settings->scope.voltage[channel].misc); | ||
| 658 | - else | ||
| 659 | - this->setMode((Dso::MathMode)this->settings->scope.voltage[channel].misc); | ||
| 660 | - this->setGain(channel, this->settings->scope.voltage[channel].gain); | ||
| 661 | - this->setUsed(channel, this->settings->scope.voltage[channel].used); | ||
| 662 | - } | ||
| 663 | -} | ||
| 664 | - | ||
| 665 | -/// \brief Cleans up everything. | ||
| 666 | -VoltageDock::~VoltageDock() {} | ||
| 667 | - | ||
| 668 | -/// \brief Don't close the dock, just hide it | ||
| 669 | -/// \param event The close event that should be handled. | ||
| 670 | -void VoltageDock::closeEvent(QCloseEvent *event) { | ||
| 671 | - this->hide(); | ||
| 672 | - | ||
| 673 | - event->accept(); | ||
| 674 | -} | ||
| 675 | - | ||
| 676 | -/// \brief Sets the coupling for a channel. | ||
| 677 | -/// \param channel The channel, whose coupling should be set. | ||
| 678 | -/// \param coupling The coupling-mode. | ||
| 679 | -/// \return Index of coupling-mode, -1 on error. | ||
| 680 | -int VoltageDock::setCoupling(int channel, Dso::Coupling coupling) { | ||
| 681 | - if (coupling < Dso::COUPLING_AC || coupling > Dso::COUPLING_GND) | ||
| 682 | - return -1; | ||
| 683 | - if (channel < 0 || channel >= (int)this->settings->scope.physicalChannels) | ||
| 684 | - return -1; | ||
| 685 | - | ||
| 686 | - this->miscComboBox[channel]->setCurrentIndex(coupling); | ||
| 687 | - return coupling; | ||
| 688 | -} | ||
| 689 | - | ||
| 690 | -/// \brief Sets the gain for a channel. | ||
| 691 | -/// \param channel The channel, whose gain should be set. | ||
| 692 | -/// \param gain The gain in volts. | ||
| 693 | -/// \return Index of gain-value, -1 on error. | ||
| 694 | -int VoltageDock::setGain(int channel, double gain) { | ||
| 695 | - if (channel < 0 || channel >= this->settings->scope.voltage.count()) | ||
| 696 | - return -1; | ||
| 697 | - | ||
| 698 | - int index = this->gainSteps.indexOf(gain); | ||
| 699 | - if (index != -1) | ||
| 700 | - this->gainComboBox[channel]->setCurrentIndex(index); | ||
| 701 | - | ||
| 702 | - return index; | ||
| 703 | -} | ||
| 704 | - | ||
| 705 | -/// \brief Sets the mode for the math channel. | ||
| 706 | -/// \param mode The math-mode. | ||
| 707 | -/// \return Index of math-mode, -1 on error. | ||
| 708 | -int VoltageDock::setMode(Dso::MathMode mode) { | ||
| 709 | - if (mode >= Dso::MATHMODE_1ADD2 && mode <= Dso::MATHMODE_2SUB1) { | ||
| 710 | - this->miscComboBox[this->settings->scope.physicalChannels]->setCurrentIndex( | ||
| 711 | - mode); | ||
| 712 | - return mode; | ||
| 713 | - } | ||
| 714 | - | ||
| 715 | - return -1; | ||
| 716 | -} | ||
| 717 | - | ||
| 718 | -/// \brief Enables/disables a channel. | ||
| 719 | -/// \param channel The channel, that should be enabled/disabled. | ||
| 720 | -/// \param used True if the channel should be enabled, false otherwise. | ||
| 721 | -/// \return Index of channel, -1 on error. | ||
| 722 | -int VoltageDock::setUsed(int channel, bool used) { | ||
| 723 | - if (channel >= 0 && channel < this->settings->scope.voltage.count()) { | ||
| 724 | - this->usedCheckBox[channel]->setChecked(used); | ||
| 725 | - return channel; | ||
| 726 | - } | ||
| 727 | - | ||
| 728 | - return -1; | ||
| 729 | -} | ||
| 730 | - | ||
| 731 | -/// \brief Called when the gain combo box changes it's value. | ||
| 732 | -/// \param index The index of the combo box item. | ||
| 733 | -void VoltageDock::gainSelected(int index) { | ||
| 734 | - int channel; | ||
| 735 | - | ||
| 736 | - // Which combobox was it? | ||
| 737 | - for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 738 | - if (this->sender() == this->gainComboBox[channel]) | ||
| 739 | - break; | ||
| 740 | - | ||
| 741 | - // Send signal if it was one of the comboboxes | ||
| 742 | - if (channel < this->settings->scope.voltage.count()) { | ||
| 743 | - this->settings->scope.voltage[channel].gain = this->gainSteps.at(index); | ||
| 744 | - | ||
| 745 | - emit gainChanged(channel, this->settings->scope.voltage[channel].gain); | ||
| 746 | - } | ||
| 747 | -} | ||
| 748 | - | ||
| 749 | -/// \brief Called when the misc combo box changes it's value. | ||
| 750 | -/// \param index The index of the combo box item. | ||
| 751 | -void VoltageDock::miscSelected(int index) { | ||
| 752 | - int channel; | ||
| 753 | - | ||
| 754 | - // Which combobox was it? | ||
| 755 | - for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 756 | - if (this->sender() == this->miscComboBox[channel]) | ||
| 757 | - break; | ||
| 758 | - | ||
| 759 | - // Send signal if it was one of the comboboxes | ||
| 760 | - if (channel < this->settings->scope.voltage.count()) { | ||
| 761 | - this->settings->scope.voltage[channel].misc = index; | ||
| 762 | - if (channel < (int)this->settings->scope.physicalChannels) | ||
| 763 | - emit couplingChanged( | ||
| 764 | - channel, (Dso::Coupling)this->settings->scope.voltage[channel].misc); | ||
| 765 | - else | ||
| 766 | - emit modeChanged( | ||
| 767 | - (Dso::MathMode)this->settings->scope.voltage[channel].misc); | ||
| 768 | - } | ||
| 769 | -} | ||
| 770 | - | ||
| 771 | -/// \brief Called when the used checkbox is switched. | ||
| 772 | -/// \param checked The check-state of the checkbox. | ||
| 773 | -void VoltageDock::usedSwitched(bool checked) { | ||
| 774 | - int channel; | ||
| 775 | - | ||
| 776 | - // Which checkbox was it? | ||
| 777 | - for (channel = 0; channel < this->settings->scope.voltage.count(); ++channel) | ||
| 778 | - if (this->sender() == this->usedCheckBox[channel]) | ||
| 779 | - break; | ||
| 780 | - | ||
| 781 | - // Send signal if it was one of the checkboxes | ||
| 782 | - if (channel < this->settings->scope.voltage.count()) { | ||
| 783 | - this->settings->scope.voltage[channel].used = checked; | ||
| 784 | - emit usedChanged(channel, checked); | ||
| 785 | - } | ||
| 786 | -} |