Q3EditorFactory Class Reference

#include <q3editorfactory.h>

Inheritance diagram for Q3EditorFactory:

Inheritance graph
[legend]
Collaboration diagram for Q3EditorFactory:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3EditorFactory class is used to create editor widgets for QVariant data types.

Each editor factory provides the createEditor() function which given a QVariant will create and return a QWidget that can edit that QVariant. For example if you have a QVariant::String type, a QLineEdit would be the default editor returned, whereas a QVariant::Int's default editor would be a QSpinBox.

If you want to create different editors for fields with the same data type, subclass Q3EditorFactory and reimplement the createEditor() function.

Definition at line 36 of file q3editorfactory.h.

Public Member Functions

 Q3EditorFactory (QObject *parent=0)
 ~Q3EditorFactory ()
virtual QWidgetcreateEditor (QWidget *parent, const QVariant &v)

Static Public Member Functions

static Q3EditorFactorydefaultFactory ()
static void installDefaultFactory (Q3EditorFactory *factory)


Constructor & Destructor Documentation

Q3EditorFactory::Q3EditorFactory ( QObject parent = 0  ) 

Constructs an editor factory with parent parent.

Definition at line 57 of file q3editorfactory.cpp.

Referenced by defaultFactory().

00058     : QObject(parent)
00059 {
00060 
00061 }

Q3EditorFactory::~Q3EditorFactory (  ) 

Destroys the object and frees any allocated resources.

Definition at line 67 of file q3editorfactory.cpp.

00068 {
00069 
00070 }


Member Function Documentation

QWidget * Q3EditorFactory::createEditor ( QWidget parent,
const QVariant v 
) [virtual]

Creates and returns the appropriate editor for the QVariant v. If the QVariant is invalid, 0 is returned. The parent is passed to the appropriate editor's constructor.

Definition at line 113 of file q3editorfactory.cpp.

References QVariant::Bitmap, QVariant::Bool, QVariant::Brush, QVariant::ByteArray, QVariant::Color, QVariant::Cursor, QVariant::Date, QVariant::DateTime, QVariant::Double, QVariant::Font, QVariant::Int, QVariant::Invalid, QVariant::Map, QVariant::Palette, QObject::parent(), QVariant::Pixmap, QVariant::Point, QObject::QWidget, QVariant::Rect, QVariant::Region, QDateTimeEdit::setDisplayFormat(), QObject::setObjectName(), QVariant::Size, QVariant::SizePolicy, QVariant::String, QVariant::StringList, QVariant::Time, QVariant::type(), QVariant::UInt, and w.

Referenced by Q3SqlEditorFactory::createEditor().

00114 {
00115     QWidget * w = 0;
00116     switch(v.type()){
00117         case QVariant::Invalid:
00118             w = 0;
00119             break;
00120         case QVariant::Bool:
00121             w = new QComboBox(parent, "qt_editor_bool");
00122             ((QComboBox *) w)->insertItem("False");
00123             ((QComboBox *) w)->insertItem("True");
00124             break;
00125         case QVariant::UInt:
00126             w = new QSpinBox(0, 999999, 1, parent, "qt_editor_spinbox");
00127             break;
00128         case QVariant::Int:
00129             w = new QSpinBox(-999999, 999999, 1, parent, "qt_editor_int");
00130             break;
00131         case QVariant::String:
00132         case QVariant::Double:
00133             w = new QLineEdit(parent, "qt_editor_double");
00134             ((QLineEdit*)w)->setFrame(false);
00135             break;
00136         case QVariant::Date: {
00137             QDateTimeEdit *edit = new QDateTimeEdit(parent);
00138             edit->setDisplayFormat("yyyy/MM/dd");
00139             edit->setObjectName("qt_editor_date");
00140             w = edit; }
00141             break;
00142         case QVariant::Time: {
00143             QDateTimeEdit *edit = new QDateTimeEdit(parent);
00144             edit->setDisplayFormat("hh:mm");
00145             edit->setObjectName("qt_editor_time");
00146             w = edit; }
00147             break;
00148         case QVariant::DateTime:
00149             w = new QDateTimeEdit(parent);
00150             w->setObjectName("qt_editor_datetime");
00151             break;
00152 #ifndef QT_NO_LABEL
00153         case QVariant::Pixmap:
00154             w = new QLabel(parent, "qt_editor_pixmap");
00155             break;
00156 #endif
00157         case QVariant::Palette:
00158         case QVariant::Color:
00159         case QVariant::Font:
00160         case QVariant::Brush:
00161         case QVariant::Bitmap:
00162         case QVariant::Cursor:
00163         case QVariant::Map:
00164         case QVariant::StringList:
00165         case QVariant::Rect:
00166         case QVariant::Size:
00167         case QVariant::IconSet:
00168         case QVariant::Point:
00169         case QVariant::PointArray:
00170         case QVariant::Region:
00171         case QVariant::SizePolicy:
00172         case QVariant::ByteArray:
00173         default:
00174             w = new QWidget(parent, "qt_editor_default");
00175             break;
00176     }
00177     return w;
00178 }

Here is the call graph for this function:

Q3EditorFactory * Q3EditorFactory::defaultFactory (  )  [static]

Returns an instance of a default editor factory.

Definition at line 79 of file q3editorfactory.cpp.

References defaultfactory, Q3EditorFactory(), and q_cleanup_editor_factory.

00080 {
00081     if(defaultfactory == 0){
00082         defaultfactory = new Q3EditorFactory();
00083         q_cleanup_editor_factory.add(&defaultfactory);
00084     }
00085 
00086     return defaultfactory;
00087 }

Here is the call graph for this function:

void Q3EditorFactory::installDefaultFactory ( Q3EditorFactory factory  )  [static]

Replaces the default editor factory with factory. {Q3EditorFactory takes ownership of factory, and destroys it when it is no longer needed.}

Definition at line 95 of file q3editorfactory.cpp.

References defaultfactory, and q_cleanup_editor_factory.

00096 {
00097     if(factory == 0 || factory == defaultfactory) return;
00098 
00099     if(defaultfactory != 0){
00100         q_cleanup_editor_factory.remove(&defaultfactory);
00101         delete defaultfactory;
00102     }
00103     defaultfactory = factory;
00104     q_cleanup_editor_factory.add(&defaultfactory);
00105 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:54:12 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1