⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qitemeditorfactory.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qplatformdefs.h>#include "qitemeditorfactory.h"#ifndef QT_NO_ITEMVIEWS#include <qcombobox.h>#include <qdatetimeedit.h>#include <qlabel.h>#include <qlineedit.h>#include <qspinbox.h>#include <limits.h>#include <float.h>#include <qcoreapplication.h>#include <qdebug.h>#ifndef QT_NO_LINEEDITclass QExpandingLineEdit : public QLineEdit{    Q_OBJECTpublic:    QExpandingLineEdit(QWidget *parent);    QExpandingLineEdit(const QString &contents, QWidget *parent);public Q_SLOTS:    void resizeToContents();private:    int originalWidth;};#endif // QT_NO_LINEEDIT#ifndef QT_NO_COMBOBOXclass QBooleanComboBox : public QComboBox{    Q_OBJECT    Q_PROPERTY(bool value READ value WRITE setValue USER true)public:    QBooleanComboBox(QWidget *parent);    void setValue(bool);    bool value() const;};#endif // QT_NO_COMBOBOX/*!    \class QItemEditorFactory    \brief The QItemEditorFactory class provides widgets for editing item data    in views and delegates.    \since 4.2    \ingroup model-view    When editing data in an item view, editors are created and    displayed by a delegate. QItemDelegate, which is the delegate by    default installed on Qt's item views, uses a QItemEditorFactory to    create editors for it. A default unique instance provided by    QItemEditorFactory is used by all item delegates.  If you set a    new default factory with setDefaultFactory(), the new factory will    be used by existing and new delegates.    A factory keeps a collection of QItemEditorCreatorBase    instances, which are specialized editors that produce editors    for one particular QVariant data type (All Qt models store    their data in \l{QVariant}s).    \section1 Standard Editing Widgets    The standard factory implementation provides editors for a variety of data    types. These are created whenever a delegate needs to provide an editor for    data supplied by a model. The following table shows the relationship between    types and the standard editors provided.    \table    \header \o Type \o Editor Widget    \row    \o bool \o QComboBox    \row    \o double \o QDoubleSpinBox    \row    \o int \o{1,2} QSpinBox    \row    \o unsigned int    \row    \o QDate \o QDateEdit    \row    \o QDateTime \o QDateTimeEdit    \row    \o QPixmap \o QLabel    \row    \o QString \o QLineEdit    \row    \o QTime \o QTimeEdit    \endtable    Additional editors can be registered with the registerEditor() function.     \sa QItemDelegate, {Model/View Programming}, {Color Editor Factory Example}*//*!    \fn QItemEditorFactory::QItemEditorFactory()    Constructs a new item editor factory.*//*!    Creates an editor widget with the given \a parent for the specified \a type of data,    and returns it as a QWidget.    \sa registerEditor()*/QWidget *QItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const{    QItemEditorCreatorBase *creator = creatorMap.value(type, 0);    if (!creator) {        const QItemEditorFactory *dfactory = defaultFactory();        return dfactory == this ? 0 : dfactory->createEditor(type, parent);    }    return creator->createWidget(parent);}/*!    Returns the property name used to access data for the given \a type of data.*/QByteArray QItemEditorFactory::valuePropertyName(QVariant::Type type) const{    QItemEditorCreatorBase *creator = creatorMap.value(type, 0);    if (!creator) {        const QItemEditorFactory *dfactory = defaultFactory();        return dfactory == this ? QByteArray() : dfactory->valuePropertyName(type);    }    return creator->valuePropertyName();}/*!    Destroys the item editor factory.*/QItemEditorFactory::~QItemEditorFactory(){}/*!    Registers an item editor creator specified by \a creator for the given \a type of data.    \bold{Note:} The factory takes ownership of the item editor creator and will destroy    it if a new creator for the same type is registered later.    \sa createEditor()*/void QItemEditorFactory::registerEditor(QVariant::Type type, QItemEditorCreatorBase *creator){   delete creatorMap.value(type, 0);   creatorMap[type] = creator;}class QDefaultItemEditorFactory : public QItemEditorFactory{public:    inline QDefaultItemEditorFactory() {}    QWidget *createEditor(QVariant::Type type, QWidget *parent) const;    QByteArray valuePropertyName(QVariant::Type) const;};QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const{    switch (type) {#ifndef QT_NO_COMBOBOX    case QVariant::Bool: {        QBooleanComboBox *cb = new QBooleanComboBox(parent);        cb->setFrame(false);        return cb; }#endif#ifndef QT_NO_SPINBOX    case QVariant::UInt: {        QSpinBox *sb = new QSpinBox(parent);        sb->setFrame(false);        sb->setMaximum(INT_MAX);        return sb; }    case QVariant::Int: {        QSpinBox *sb = new QSpinBox(parent);        sb->setFrame(false);        sb->setMinimum(INT_MIN);        sb->setMaximum(INT_MAX);        return sb; }#endif#ifndef QT_NO_DATETIMEEDIT    case QVariant::Date: {        QDateTimeEdit *ed = new QDateEdit(parent);        ed->setFrame(false);        return ed; }    case QVariant::Time: {        QDateTimeEdit *ed = new QTimeEdit(parent);        ed->setFrame(false);        return ed; }    case QVariant::DateTime: {        QDateTimeEdit *ed = new QDateTimeEdit(parent);        ed->setFrame(false);        return ed; }#endif    case QVariant::Pixmap:        return new QLabel(parent);#ifndef QT_NO_SPINBOX    case QVariant::Double: {        QDoubleSpinBox *sb = new QDoubleSpinBox(parent);        sb->setFrame(false);        sb->setMinimum(-DBL_MAX);        sb->setMaximum(DBL_MAX);        return sb; }#endif#ifndef QT_NO_LINEEDIT    case QVariant::String:    default: {        // the default editor is a lineedit        QLineEdit *le = new QExpandingLineEdit(parent);        le->setFrame(false);        return le; }#else    default:        break;#endif    }    return 0;}QByteArray QDefaultItemEditorFactory::valuePropertyName(QVariant::Type type) const{    switch (type) {#ifndef QT_NO_COMBOBOX    case QVariant::Bool:        return "currentIndex";#endif#ifndef QT_NO_SPINBOX    case QVariant::UInt:    case QVariant::Int:    case QVariant::Double:        return "value";#endif#ifndef QT_NO_DATETIMEEDIT    case QVariant::Date:        return "date";    case QVariant::Time:        return "time";    case QVariant::DateTime:        return "dateTime";#endif    case QVariant::String:    default:        // the default editor is a lineedit

⌨️ 快捷键说明

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