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
00025 #include <kexidb/indexschema.h>
00026 #include <kexidb/tableschema.h>
00027 #include "kexitableviewdata.h"
00028
00029
00030
00031 KexiCellEditorFactoryItem::KexiCellEditorFactoryItem()
00032 {
00033 }
00034
00035 KexiCellEditorFactoryItem::~KexiCellEditorFactoryItem()
00036 {
00037 }
00038
00039
00040
00042 class KexiCellEditorFactoryPrivate
00043 {
00044 public:
00045 KexiCellEditorFactoryPrivate()
00046 : items(101)
00047 , items_by_type(101, false)
00048 {
00049 items.setAutoDelete( true );
00050 items_by_type.setAutoDelete( false );
00051 }
00052 ~KexiCellEditorFactoryPrivate() {}
00053
00054 QString key(uint type, const QString& subType) const
00055 {
00056 QString key = QString::number(type);
00057 if (!subType.isEmpty())
00058 key += (QString(" ") + subType);
00059 return key;
00060 }
00061
00062 void registerItem( KexiCellEditorFactoryItem& item, uint type, const QString& subType )
00063 {
00064 if (!items[ &item ])
00065 items.insert( &item, &item );
00066
00067 items_by_type.insert( key(type, subType), &item );
00068 }
00069
00070 KexiCellEditorFactoryItem *findItem(uint type, const QString& subType)
00071 {
00072 KexiCellEditorFactoryItem *item = items_by_type[ key(type, subType) ];
00073 if (item)
00074 return item;
00075 item = items_by_type[ key(type, QString::null) ];
00076 if (item)
00077 return item;
00078 return items_by_type[ key( KexiDB::Field::InvalidType, QString::null ) ];
00079 }
00080
00081 QPtrDict<KexiCellEditorFactoryItem> items;
00082
00083 QDict<KexiCellEditorFactoryItem> items_by_type;
00084 };
00085
00086 KexiCellEditorFactoryPrivate static_KexiCellEditorFactory;
00087
00088
00089
00090
00091 KexiCellEditorFactory::KexiCellEditorFactory()
00092 {
00093 }
00094
00095 KexiCellEditorFactory::~KexiCellEditorFactory()
00096 {
00097 }
00098
00099 void KexiCellEditorFactory::registerItem( KexiCellEditorFactoryItem& item, uint type, const QString& subType )
00100 {
00101 static_KexiCellEditorFactory.registerItem( item, type, subType );
00102 }
00103
00104 KexiTableEdit* KexiCellEditorFactory::createEditor(KexiTableViewColumn &column, QScrollView* parent)
00105 {
00106 KexiTableViewData *rel_data = column.relatedData();
00107 KexiCellEditorFactoryItem *item = 0;
00108 if (rel_data) {
00109
00110 item = KexiCellEditorFactory::item( KexiDB::Field::Enum );
00111 }
00112 else {
00113 item = KexiCellEditorFactory::item( column.field()->type(), column.field()->subType() );
00114 }
00115
00116 #if 0 //js: TODO LATER
00117
00118
00119 KexiDB::TableSchema *table = f.table();
00120 if (table) {
00121
00122 KexiDB::IndexSchema::ListIterator it = table->indicesIterator();
00123 for (;it.current();++it) {
00124 KexiDB::IndexSchema *idx = it.current();
00125 if (idx->fields()->findRef(&f)!=-1) {
00126
00127 KexiDB::Relationship *rel = idx->detailsRelationships()->first();
00128 if (rel) {
00129
00130 }
00131 }
00132 }
00133 }
00134 #endif
00135
00136 return item->createEditor(column, parent);
00137 }
00138
00139 KexiCellEditorFactoryItem* KexiCellEditorFactory::item( uint type, const QString& subType )
00140 {
00141 return static_KexiCellEditorFactory.findItem(type, subType);
00142 }
00143
|