qpropertyeditor_items.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,138 行 · 第 1/5 页

CPP
2,138
字号
QWidget *DoubleProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    lineEdit->setValidator(new QDoubleValidator(lineEdit));    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void DoubleProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        double v = lineEdit->text().toDouble();        if (v != m_value)            lineEdit->setText(QString::number(m_value));    }}void DoubleProperty::updateValue(QWidget *editor){    if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit*>(editor)) {        const double newValue = lineEdit->text().toDouble();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------// QDoublePropertySpinBox also emits editingFinished when the spinbox is usedclass QDoublePropertySpinBox: public QDoubleSpinBox{public:    QDoublePropertySpinBox(QWidget *parent = 0)        : QDoubleSpinBox(parent) { }    void stepBy(int steps)    {        QDoubleSpinBox::stepBy(steps);        emit editingFinished();    }};SpinBoxDoubleProperty::SpinBoxDoubleProperty(double value, const QString &name)    : AbstractProperty<double>(value, name), m_low(-HUGE_VAL), m_hi(HUGE_VAL){}void SpinBoxDoubleProperty::setRange(double low, double hi){    m_low = low;    m_hi = hi;}QString SpinBoxDoubleProperty::specialValue() const{    return m_specialValue;}void SpinBoxDoubleProperty::setSpecialValue(const QString &specialValue){    m_specialValue = specialValue;}void SpinBoxDoubleProperty::setValue(const QVariant &value){    m_value = value.toDouble();}QString SpinBoxDoubleProperty::toString() const{    return QString::number(m_value);}QWidget *SpinBoxDoubleProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QDoubleSpinBox *spinBox = new QDoublePropertySpinBox(parent);    spinBox->setFrame(0);    spinBox->setSpecialValueText(m_specialValue);    spinBox->setDecimals(6);    spinBox->setRange(m_low, m_hi);    spinBox->setValue(m_value);    spinBox->selectAll();    QObject::connect(spinBox, SIGNAL(editingFinished()), target, receiver);    return spinBox;}void SpinBoxDoubleProperty::updateEditorContents(QWidget *editor){    if (QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(editor)) {        spinBox->setValue(m_value);    }}void SpinBoxDoubleProperty::updateValue(QWidget *editor){    if (const QDoubleSpinBox *spinBox = qobject_cast<const QDoubleSpinBox*>(editor)) {        const double newValue = spinBox->value();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------CharProperty::CharProperty(QChar value, const QString &name)    : AbstractProperty<QChar>(value, name){}void CharProperty::setValue(const QVariant &value){    m_value = value.toChar();}QString CharProperty::toString() const{    return QString(m_value);}QWidget *CharProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    lineEdit->setInputMask(QLatin1String("X; "));    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void CharProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        if (lineEdit->text() != QString(m_value)) {            lineEdit->setText(QString(m_value));            lineEdit->setCursorPosition(0);        }    }}void CharProperty::updateValue(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        lineEdit->setCursorPosition(0);        QChar newValue = QLatin1Char(' ');        if (lineEdit->text().size() > 0)            newValue = lineEdit->text().at(0);        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------LongLongProperty::LongLongProperty(qlonglong value, const QString &name)    : AbstractProperty<qlonglong>(value, name){}void LongLongProperty::setValue(const QVariant &value){    m_value = value.toLongLong();}QString LongLongProperty::toString() const{    return QString::number(m_value);}QWidget *LongLongProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    lineEdit->setValidator(new QLongLongValidator(lineEdit));    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void LongLongProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        const qlonglong v = lineEdit->text().toLongLong();        if (v != m_value)            lineEdit->setText(QString::number(m_value));    }}void LongLongProperty::updateValue(QWidget *editor){    if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit*>(editor)) {        const qlonglong newValue = lineEdit->text().toLongLong();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------SeparatorProperty::SeparatorProperty(const QString &value, const QString &name)    : StringProperty(value, name){}QWidget *SeparatorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    Q_UNUSED(parent);    Q_UNUSED(target);    Q_UNUSED(receiver);    return 0;}bool SeparatorProperty::hasEditor() const{ return false; }void SeparatorProperty::updateEditorContents(QWidget *editor){ Q_UNUSED(editor); }void SeparatorProperty::updateValue(QWidget *editor){ Q_UNUSED(editor); }// -------------------------------------------------------------------------UrlProperty::UrlProperty(const QUrl &value, const QString &name)    : AbstractPropertyGroup(name),      m_value(value){}QVariant UrlProperty::value() const{    return m_value;}void UrlProperty::setValue(const QVariant &value){    m_value = value.toUrl();}QString UrlProperty::toString() const{    return m_value.toString();}QWidget *UrlProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void UrlProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        if (QUrl(lineEdit->text()) != m_value)            lineEdit->setText(m_value.toString());    }}void UrlProperty::updateValue(QWidget *editor){    if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit*>(editor)) {        const QUrl newValue = QUrl(lineEdit->text());        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------StringListProperty::StringListProperty(const QStringList &value, const QString &name)    : AbstractProperty<QStringList>(value, name){}void StringListProperty::setValue(const QVariant &value){    m_value = qvariant_cast<QStringList>(value);}QString StringListProperty::toString() const{    return m_value.join(QLatin1String(", "));}QWidget *StringListProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    StringListEditorButton *btn = new StringListEditorButton(m_value, parent);    QObject::connect(btn, SIGNAL(changed()), target, receiver);    return btn;}void StringListProperty::updateEditorContents(QWidget *editor){    if (StringListEditorButton *btn = qobject_cast<StringListEditorButton*>(editor)) {        btn->setStringList(m_value);    }}void StringListProperty::updateValue(QWidget *editor){    if (const StringListEditorButton *btn = qobject_cast<const StringListEditorButton*>(editor)) {        const QStringList newValue = btn->stringList();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------UIntProperty::UIntProperty(uint value, const QString &name)    : AbstractProperty<uint>(value, name){}void UIntProperty::setValue(const QVariant &value){    m_value = value.toUInt();}QString UIntProperty::toString() const{    return QString::number(m_value);}QWidget *UIntProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    lineEdit->setValidator(new QULongLongValidator(0, UINT_MAX, lineEdit));    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void UIntProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        const uint v = lineEdit->text().toUInt();        if (v != m_value)            lineEdit->setText(QString::number(m_value));    }}void UIntProperty::updateValue(QWidget *editor){    if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit*>(editor)) {        const uint newValue = lineEdit->text().toUInt();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}// -------------------------------------------------------------------------ULongLongProperty::ULongLongProperty(qulonglong value, const QString &name)    : AbstractProperty<qulonglong>(value, name){}void ULongLongProperty::setValue(const QVariant &value){    m_value = value.toULongLong();}QString ULongLongProperty::toString() const{    return QString::number(m_value);}QWidget *ULongLongProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{    QLineEdit *lineEdit = new QLineEdit(parent);    lineEdit->setFrame(0);    lineEdit->setValidator(new QULongLongValidator(lineEdit));    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);    return lineEdit;}void ULongLongProperty::updateEditorContents(QWidget *editor){    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {        const qulonglong v = lineEdit->text().toULongLong();        if (v != m_value)            lineEdit->setText(QString::number(m_value));    }}void ULongLongProperty::updateValue(QWidget *editor){    if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit*>(editor)) {        const qulonglong newValue = lineEdit->text().toULongLong();        if (newValue != m_value) {            m_value = newValue;            setChanged(true);        }    }}#include "qpropertyeditor_items.moc"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?