kexi
kexicelleditorfactory.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexicelleditorfactory.h"
00021
00022 #include <qptrdict.h>
00023 #include <qintdict.h>
00024 #include <kstaticdeleter.h>
00025
00026 #include <kexidb/indexschema.h>
00027 #include <kexidb/tableschema.h>
00028 #include "kexitableviewdata.h"
00029 #include "kexidatetableedit.h"
00030 #include "kexitimetableedit.h"
00031 #include "kexidatetimetableedit.h"
00032 #include "kexitableedit.h"
00033 #include "kexiinputtableedit.h"
00034 #include "kexicomboboxtableedit.h"
00035 #include "kexiblobtableedit.h"
00036 #include "kexibooltableedit.h"
00037
00038
00039
00040 KexiCellEditorFactoryItem::KexiCellEditorFactoryItem()
00041 {
00042 }
00043
00044 KexiCellEditorFactoryItem::~KexiCellEditorFactoryItem()
00045 {
00046 }
00047
00048
00049
00051 class KexiCellEditorFactoryPrivate
00052 {
00053 public:
00054 KexiCellEditorFactoryPrivate()
00055 : items(101)
00056 , items_by_type(101, false)
00057 {
00058 items.setAutoDelete( true );
00059 items_by_type.setAutoDelete( false );
00060 }
00061 ~KexiCellEditorFactoryPrivate() {}
00062
00063 QString key(uint type, const QString& subType) const
00064 {
00065 QString key = QString::number(type);
00066 if (!subType.isEmpty())
00067 key += (QString(" ") + subType);
00068 return key;
00069 }
00070
00071 void registerItem( KexiCellEditorFactoryItem& item, uint type, const QString& subType = QString::null )
00072 {
00073 if (!items[ &item ])
00074 items.insert( &item, &item );
00075
00076 items_by_type.insert( key(type, subType), &item );
00077 }
00078
00079 KexiCellEditorFactoryItem *findItem(uint type, const QString& subType)
00080 {
00081 KexiCellEditorFactoryItem *item = items_by_type[ key(type, subType) ];
00082 if (item)
00083 return item;
00084 item = items_by_type[ key(type, QString::null) ];
00085 if (item)
00086 return item;
00087 return items_by_type[ key( KexiDB::Field::InvalidType, QString::null ) ];
00088 }
00089
00090 QPtrDict<KexiCellEditorFactoryItem> items;
00091
00092 QDict<KexiCellEditorFactoryItem> items_by_type;
00093 };
00094
00095 static KStaticDeleter<KexiCellEditorFactoryPrivate> KexiCellEditorFactory_deleter;
00096 static KexiCellEditorFactoryPrivate *KexiCellEditorFactory_static = 0;
00097
00098
00099
00100 KexiCellEditorFactory::KexiCellEditorFactory()
00101 {
00102 }
00103
00104 KexiCellEditorFactory::~KexiCellEditorFactory()
00105 {
00106 }
00107
00108
00109
00110 void KexiCellEditorFactory::init()
00111 {
00112 if (KexiCellEditorFactory_static)
00113 return;
00114 KexiCellEditorFactory_deleter.setObject(KexiCellEditorFactory_static, new KexiCellEditorFactoryPrivate());
00115
00116 KexiCellEditorFactory_static->registerItem( *new KexiBlobEditorFactoryItem(), KexiDB::Field::BLOB );
00117 KexiCellEditorFactory_static->registerItem( *new KexiDateEditorFactoryItem(), KexiDB::Field::Date );
00118 KexiCellEditorFactory_static->registerItem( *new KexiTimeEditorFactoryItem(), KexiDB::Field::Time );
00119 KexiCellEditorFactory_static->registerItem( *new KexiDateTimeEditorFactoryItem(), KexiDB::Field::DateTime );
00120 KexiCellEditorFactory_static->registerItem( *new KexiComboBoxEditorFactoryItem(), KexiDB::Field::Enum );
00121 KexiCellEditorFactory_static->registerItem( *new KexiBoolEditorFactoryItem(), KexiDB::Field::Boolean );
00122 KexiCellEditorFactory_static->registerItem( *new KexiKIconTableEditorFactoryItem(), KexiDB::Field::Text, "KIcon" );
00123
00124 KexiCellEditorFactory_static->registerItem( *new KexiInputEditorFactoryItem(), KexiDB::Field::InvalidType );
00125 }
00126
00127 void KexiCellEditorFactory::registerItem( KexiCellEditorFactoryItem& item, uint type, const QString& subType )
00128 {
00129 init();
00130 KexiCellEditorFactory_static->registerItem( item, type, subType );
00131 }
00132
00133 KexiTableEdit* KexiCellEditorFactory::createEditor(KexiTableViewColumn &column, QWidget* parent)
00134 {
00135 init();
00136 KexiDB::Field *realField;
00137 if (column.visibleLookupColumnInfo) {
00138 realField = column.visibleLookupColumnInfo->field;
00139 }
00140 else {
00141 realField = column.field();
00142 }
00143
00144 KexiCellEditorFactoryItem *item = 0;
00145 if (column.relatedData()
00146 || (column.field() && column.field()->table() && column.field()->table()->lookupFieldSchema( *column.field() )))
00147 {
00148
00149 item = KexiCellEditorFactory::item( KexiDB::Field::Enum );
00150 }
00151 else {
00152 item = KexiCellEditorFactory::item( realField->type(), realField->subType() );
00153 }
00154
00155 #if 0 //js: TODO LATER
00156
00157
00158 KexiDB::TableSchema *table = f.table();
00159 if (table) {
00160
00161 KexiDB::IndexSchema::ListIterator it = table->indicesIterator();
00162 for (;it.current();++it) {
00163 KexiDB::IndexSchema *idx = it.current();
00164 if (idx->fields()->findRef(&f)!=-1) {
00165
00166 KexiDB::Relationship *rel = idx->detailsRelationships()->first();
00167 if (rel) {
00168
00169 }
00170 }
00171 }
00172 }
00173 #endif
00174
00175 return item->createEditor(column, parent);
00176 }
00177
00178 KexiCellEditorFactoryItem* KexiCellEditorFactory::item( uint type, const QString& subType )
00179 {
00180 init();
00181 return KexiCellEditorFactory_static->findItem(type, subType);
00182 }
00183
|