From 923345762b0eff2cd970a3ea9c39e9b7692c00a5 Mon Sep 17 00:00:00 2001 From: Mike LaBranche Date: Mon, 9 Jul 2012 09:07:22 -0700 Subject: [PATCH] mixercurve, dblspindelegate names --- .../src/plugins/config/dblspindelegate.cpp | 86 +++++++++++++++++++ .../src/plugins/config/dblspindelegate.h | 73 ++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 ground/openpilotgcs/src/plugins/config/dblspindelegate.cpp create mode 100644 ground/openpilotgcs/src/plugins/config/dblspindelegate.h diff --git a/ground/openpilotgcs/src/plugins/config/dblspindelegate.cpp b/ground/openpilotgcs/src/plugins/config/dblspindelegate.cpp new file mode 100644 index 000000000..21af3f1d2 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/config/dblspindelegate.cpp @@ -0,0 +1,86 @@ +/** + ****************************************************************************** + * + * @file doublespindelegate.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup ConfigPlugin Config Plugin + * @{ + * @brief A double spinbox delegate + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "dblspindelegate.h" + +/** + Helper delegate for the custom mixer editor table. + */ +DoubleSpinDelegate::DoubleSpinDelegate(QObject *parent) + : QItemDelegate(parent) + { + m_min = 0.0; + m_max = 1.0; + m_decimals = 2; + m_step = 0.01; + } + +QWidget *DoubleSpinDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &/* option */, + const QModelIndex &/* index */) const +{ + QDoubleSpinBox *editor = new QDoubleSpinBox(parent); + editor->setMinimum(m_min); + editor->setMaximum(m_max); + editor->setDecimals(m_decimals); + editor->setSingleStep(m_step); + + connect(editor,SIGNAL(valueChanged(double)), this, SLOT(valueChanged())); + + return editor; +} + +void DoubleSpinDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + double value = index.model()->data(index, Qt::EditRole).toDouble(); + + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->setValue(value); +} + +void DoubleSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + double value = spinBox->value(); + + model->setData(index, value, Qt::EditRole); +} + +void DoubleSpinDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + +void DoubleSpinDelegate::valueChanged() +{ + emit ValueChanged(); +} + diff --git a/ground/openpilotgcs/src/plugins/config/dblspindelegate.h b/ground/openpilotgcs/src/plugins/config/dblspindelegate.h new file mode 100644 index 000000000..482a07649 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/config/dblspindelegate.h @@ -0,0 +1,73 @@ +/** + ****************************************************************************** + * + * @file doublespindelegate.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup ConfigPlugin Config Plugin + * @{ + * @brief A double spinbox delegate + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef DOUBLESPINDELEGATE_H +#define DOUBLESPINDELEGATE_H + +#include +#include + +namespace Ui { +class DoubleSpinDelegate; +} + +class DoubleSpinDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + DoubleSpinDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &index) const; + + void setMin(double min) { m_min = min; } + void setMax(double max) { m_max = max; } + void setRange(double min, double max) { m_min = min; m_max = max; } + void setStep(double step) { m_step = step; } + void setDecimals(int decimals) { m_decimals = decimals; } + +private: + double m_min; + double m_max; + double m_step; + int m_decimals; + +signals: + void ValueChanged(); + +private slots: + void valueChanged(); +}; + +#endif // DOUBLESPINDELEGATE_H