Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QItemEditorFactory Class Reference

The QItemEditorFactory class provides widgets for editing item data in views and delegates. More...

#include <qitemeditorfactory.h>

Inheritance diagram for QItemEditorFactory:
QDefaultItemEditorFactory

Public Functions

virtual QWidgetcreateEditor (QVariant::Type type, QWidget *parent) const
 Creates an editor widget with the given parent for the specified type of data, and returns it as a QWidget. More...
 
 QItemEditorFactory ()
 Constructs a new item editor factory. More...
 
void registerEditor (QVariant::Type type, QItemEditorCreatorBase *creator)
 Registers an item editor creator specified by creator for the given type of data. More...
 
virtual QByteArray valuePropertyName (QVariant::Type type) const
 Returns the property name used to access data for the given type of data. More...
 
virtual ~QItemEditorFactory ()
 Destroys the item editor factory. More...
 

Static Public Functions

static const QItemEditorFactorydefaultFactory ()
 Returns the default item editor factory. More...
 
static void setDefaultFactory (QItemEditorFactory *factory)
 Sets the default item editor factory to the given factory. More...
 

Properties

QHash< QVariant::Type, QItemEditorCreatorBase * > creatorMap
 

Detailed Description

The QItemEditorFactory class provides widgets for editing item data in views and delegates.

Since
4.2

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 QVariant).

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.

Type Editor Widget
bool QComboBox
double QDoubleSpinBox
int QSpinBox
unsigned int
QDate QDateEdit
QDateTime QDateTimeEdit
QPixmap QLabel
QString QLineEdit
QTime QTimeEdit

Additional editors can be registered with the registerEditor() function.

See also
QItemDelegate, {Model/View Programming}, {Color Editor Factory Example}

Definition at line 100 of file qitemeditorfactory.h.

Constructors and Destructors

◆ QItemEditorFactory()

QItemEditorFactory::QItemEditorFactory ( )
inline

Constructs a new item editor factory.

Definition at line 103 of file qitemeditorfactory.h.

103 {}

◆ ~QItemEditorFactory()

QItemEditorFactory::~QItemEditorFactory ( )
virtual

Destroys the item editor factory.

Definition at line 165 of file qitemeditorfactory.cpp.

166 {
167  //we make sure we delete all the QItemEditorCreatorBase
168  //this has to be done only once, hence the QSet
170  qDeleteAll(set);
171 }
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QHash< QVariant::Type, QItemEditorCreatorBase * > creatorMap

Functions

◆ createEditor()

QWidget * QItemEditorFactory::createEditor ( QVariant::Type  type,
QWidget parent 
) const
virtual

Creates an editor widget with the given parent for the specified type of data, and returns it as a QWidget.

See also
registerEditor()

Reimplemented in QDefaultItemEditorFactory.

Definition at line 139 of file qitemeditorfactory.cpp.

Referenced by QItemDelegate::createEditor(), and createEditor().

140 {
142  if (!creator) {
143  const QItemEditorFactory *dfactory = defaultFactory();
144  return dfactory == this ? 0 : dfactory->createEditor(type, parent);
145  }
146  return creator->createWidget(parent);
147 }
int type
Definition: qmetatype.cpp:239
The QItemEditorFactory class provides widgets for editing item data in views and delegates.
The QItemEditorCreatorBase class provides an abstract base class that must be subclassed when impleme...
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
virtual QWidget * createWidget(QWidget *parent) const =0
Returns an editor widget with the given parent.
static const QItemEditorFactory * defaultFactory()
Returns the default item editor factory.
virtual QWidget * createEditor(QVariant::Type type, QWidget *parent) const
Creates an editor widget with the given parent for the specified type of data, and returns it as a QW...
QHash< QVariant::Type, QItemEditorCreatorBase * > creatorMap

◆ defaultFactory()

const QItemEditorFactory * QItemEditorFactory::defaultFactory ( )
static

Returns the default item editor factory.

See also
setDefaultFactory()

Definition at line 306 of file qitemeditorfactory.cpp.

Referenced by QItemDelegate::createEditor(), QItemDelegatePrivate::editorFactory(), and QStyledItemDelegatePrivate::editorFactory().

307 {
308  static const QDefaultItemEditorFactory factory;
309  if (q_default_factory)
310  return q_default_factory;
311  return &factory;
312 }
static QItemEditorFactory * q_default_factory

◆ registerEditor()

void QItemEditorFactory::registerEditor ( QVariant::Type  type,
QItemEditorCreatorBase creator 
)

Registers an item editor creator specified by creator for the given type of data.

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.

See also
createEditor()

Definition at line 181 of file qitemeditorfactory.cpp.

182 {
184  if (it != creatorMap.end()) {
185  QItemEditorCreatorBase *oldCreator = it.value();
186  Q_ASSERT(oldCreator);
187  creatorMap.erase(it);
188  if (!creatorMap.values().contains(oldCreator))
189  delete oldCreator; // if it is no more in use we can delete it
190  }
191 
192  creatorMap[type] = creator;
193 }
int type
Definition: qmetatype.cpp:239
The QItemEditorCreatorBase class provides an abstract base class that must be subclassed when impleme...
#define it(className, varName)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
QHash< QVariant::Type, QItemEditorCreatorBase * > creatorMap

◆ setDefaultFactory()

void QItemEditorFactory::setDefaultFactory ( QItemEditorFactory factory)
static

Sets the default item editor factory to the given factory.

Both new and existing delegates will use the new factory.

See also
defaultFactory()

Definition at line 320 of file qitemeditorfactory.cpp.

321 {
322  static const QDefaultFactoryCleaner cleaner;
323  delete q_default_factory;
324  q_default_factory = factory;
325 }
static QItemEditorFactory * q_default_factory

◆ valuePropertyName()

QByteArray QItemEditorFactory::valuePropertyName ( QVariant::Type  type) const
virtual

Returns the property name used to access data for the given type of data.

Reimplemented in QDefaultItemEditorFactory.

Definition at line 152 of file qitemeditorfactory.cpp.

Referenced by valuePropertyName().

153 {
155  if (!creator) {
156  const QItemEditorFactory *dfactory = defaultFactory();
157  return dfactory == this ? QByteArray() : dfactory->valuePropertyName(type);
158  }
159  return creator->valuePropertyName();
160 }
int type
Definition: qmetatype.cpp:239
The QItemEditorFactory class provides widgets for editing item data in views and delegates.
The QItemEditorCreatorBase class provides an abstract base class that must be subclassed when impleme...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual QByteArray valuePropertyName(QVariant::Type type) const
Returns the property name used to access data for the given type of data.
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
virtual QByteArray valuePropertyName() const =0
Returns the name of the property used to get and set values in the creator&#39;s editor widgets...
static const QItemEditorFactory * defaultFactory()
Returns the default item editor factory.
QHash< QVariant::Type, QItemEditorCreatorBase * > creatorMap

Properties

◆ creatorMap

QHash<QVariant::Type, QItemEditorCreatorBase *> QItemEditorFactory::creatorMap
private

Definition at line 115 of file qitemeditorfactory.h.


The documentation for this class was generated from the following files: