1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

mixercurve, dblspindelegate names

This commit is contained in:
Mike LaBranche 2012-07-09 09:07:22 -07:00
parent 898bd7dbf1
commit 923345762b
2 changed files with 159 additions and 0 deletions

View File

@ -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<QDoubleSpinBox*>(editor);
spinBox->setValue(value);
}
void DoubleSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(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();
}

View File

@ -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 <QDoubleSpinBox>
#include <QItemDelegate>
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