summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/macros/kexipart/keximacroproperty.cpp
blob: 2fdafd28339106938467d0633f2803b823390f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/* This file is part of the KDE project
   Copyright (C) 2006 Sebastian Sauer <mail@dipe.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "keximacroproperty.h"

#include <qlayout.h>
#include <qlineedit.h>
#include <qlistbox.h>
#include <qpainter.h>

#include <kcombobox.h>
#include <kpushbutton.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kdebug.h>

#include "../lib/variable.h"
#include "../lib/macroitem.h"

#define KEXIMACRO_PROPERTYEDITORTYPE 5682

/*************************************************************
 * KexiMacroProperty
 */

/**
* @internal d-pointer class to be more flexible on future extension of the
* functionality without to much risk to break the binary compatibility.
*/
class KexiMacroProperty::Private
{
	public:
		/** The @a KoMacro::MacroItem the custom property uses
		internal. Together with the name we are able to identify
		the used variable at runtime. */
		KSharedPtr<KoMacro::MacroItem> macroitem;
		/** The name the variable @a KoMacro::Variable is known
		as in the @a KoMacro::MacroItem defined above. */
		QString name;
};

KexiMacroProperty::KexiMacroProperty(KoProperty::Property* parent, KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name)
	: KoProperty::CustomProperty(parent)
	, d( new Private() )
{
	d->macroitem = macroitem;
	d->name = name;
	init();
}

KexiMacroProperty::~KexiMacroProperty()
{
	delete d;
}

void KexiMacroProperty::init()
{
	Q_ASSERT( d->macroitem != 0 );
	//kdDebug() << "--------- KexiMacroProperty::set() macroitem=" << d->macroitem->name() << " name=" << d->name << endl;

	KSharedPtr<KoMacro::Action> action = d->macroitem->action();
	KSharedPtr<KoMacro::Variable> actionvariable = action->variable(d->name);
	if(! actionvariable.data()) {
		kdDebug() << "KexiMacroProperty::createProperty() Skipped cause there exists no such action=" << d->name << endl;
		return;
	}

	KSharedPtr<KoMacro::Variable> variable = d->macroitem->variable(d->name, true/*checkaction*/);
	if(! variable.data()) {
		kdDebug() << "KexiMacroProperty::createProperty() Skipped cause there exists no such variable=" << d->name << endl;
		return;
	}

	//TESTCASE!!!!!!!!!!!!!!!!!!!!!!
	//if(! variable->isEnabled()) qFatal( QString("############## VARIABLE=%1").arg(variable->name()).latin1() );

	Q_ASSERT(! d->name.isNull());
	m_property->setName( d->name.latin1() );
	m_property->setCaption( actionvariable->text() );
	m_property->setDescription( action->comment() );
	m_property->setValue( variable->variant(), true );
	m_property->setType( KEXIMACRO_PROPERTYEDITORTYPE ); // use our own propertytype
}

KoProperty::Property* KexiMacroProperty::parentProperty() const
{
	return m_property;
}

void KexiMacroProperty::setValue(const QVariant &value, bool rememberOldValue)
{
	Q_UNUSED(rememberOldValue);
	kdDebug()<<"KexiMacroProperty::setValue name="<<d->name<<" value="<<value<<" rememberOldValue="<<rememberOldValue<<endl;
	if(! d->macroitem->setVariant(d->name, value)) { // takes care of the type-conversation
		kdDebug()<<"KexiMacroProperty::setValue Update failed !!!"<<endl;
		return;
	}

	// m_property->setValue() does check if the value changed by using
	// this-value() and cause we already set it above, m_property->setValue()
	// will be aborted. Well, we don't touch the properties value and handle
	// it all via our CustomProperty class anyway. So, just ignore the property.
	//m_property->setValue(this->value(), rememberOldValue, false/*useCustomProperty*/);

	emit valueChanged();
}

QVariant KexiMacroProperty::value() const
{
	KSharedPtr<KoMacro::Variable> variable = d->macroitem->variable(d->name, true);
	Q_ASSERT( variable.data() != 0 );
	return variable.data() ? variable->variant() : QVariant();
}

bool KexiMacroProperty::handleValue() const
{
	return true; // we handle getting and setting of values and don't need KoProperty::Property for it.
}

KSharedPtr<KoMacro::MacroItem> KexiMacroProperty::macroItem() const
{
	return d->macroitem;
}

QString KexiMacroProperty::name() const
{
	return d->name;
}

KSharedPtr<KoMacro::Variable> KexiMacroProperty::variable() const
{
	return d->macroitem->variable(d->name, true/*checkaction*/);
}

KoProperty::Property* KexiMacroProperty::createProperty(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name)
{
	KoProperty::Property* property = new KoProperty::Property();
	KexiMacroProperty* customproperty = new KexiMacroProperty(property, macroitem, name);
	if(! customproperty->variable().data()) {
		kdWarning() << "KexiMacroProperty::createProperty() No such variable" << endl;
		delete customproperty; customproperty = 0;
		delete property; property = 0;
		return 0;
	}
	property->setCustomProperty(customproperty);
	return property;
}

/*************************************************************
 * KexiMacroPropertyFactory
 */

KexiMacroPropertyFactory::KexiMacroPropertyFactory(QObject* parent)
	: KoProperty::CustomPropertyFactory(parent)
{
}

KexiMacroPropertyFactory::~KexiMacroPropertyFactory()
{
}

KoProperty::CustomProperty* KexiMacroPropertyFactory::createCustomProperty(KoProperty::Property* parent)
{
	kdDebug()<<"KexiMacroPropertyFactory::createCustomProperty parent="<<parent->name()<<endl;

	KoProperty::CustomProperty* customproperty = parent->customProperty();
	KexiMacroProperty* parentcustomproperty = dynamic_cast<KexiMacroProperty*>(customproperty);
	if(! parentcustomproperty) {
		kdWarning() << "KexiMacroPropertyFactory::createCustomProperty() parent=" << parent->name() << " has an invalid customproperty." << endl;
		return 0;
	}

	KSharedPtr<KoMacro::MacroItem> macroitem = parentcustomproperty->macroItem();
	Q_ASSERT( macroitem.data() != 0 );
	const QString name = parentcustomproperty->name();
	Q_ASSERT(! name.isEmpty());

	KexiMacroProperty* macroproperty = new KexiMacroProperty(parent, macroitem, name);
	if(! macroproperty->variable().data()) {
		delete macroproperty; macroproperty = 0;
		return 0;
	}

	return macroproperty;
}

KoProperty::Widget* KexiMacroPropertyFactory::createCustomWidget(KoProperty::Property* property)
{
	kdDebug()<<"KexiMacroPropertyFactory::createCustomWidget property="<<property->name()<<endl;
	return new KexiMacroPropertyWidget(property);
}

void KexiMacroPropertyFactory::initFactory()
{
	CustomPropertyFactory* factory = KoProperty::FactoryManager::self()->factoryForEditorType(KEXIMACRO_PROPERTYEDITORTYPE);
	if(! factory) {
		factory = new KexiMacroPropertyFactory( KoProperty::FactoryManager::self() );
		KoProperty::FactoryManager::self()->registerFactoryForEditor(KEXIMACRO_PROPERTYEDITORTYPE, factory);
	}
}

/*************************************************************
 * KexiMacroPropertyWidget
 */

/**
* @internal implementation of a QListBoxItem to display the items of the
* combobox used within @a KexiMacroPropertyWidget to handle variables
* within a @a ListBox instance.
*/
class ListBoxItem : public QListBoxText
{
	public:
		ListBoxItem(QListBox* listbox)
			: QListBoxText(listbox), m_enabled(true) {}
		ListBoxItem(QListBox* listbox, const QString& text, QListBoxItem* after)
			: QListBoxText(listbox, text, after), m_enabled(true) {}
		virtual ~ListBoxItem() {}
		void setEnabled(bool enabled) { m_enabled = enabled; }
		virtual int width(const QListBox* lb) const {
			Q_ASSERT( dynamic_cast<KComboBox*>( lb->parent() ) );
			return static_cast<KComboBox*>( lb->parent() )->lineEdit()->width() + 2;
		}
		virtual int height(const QListBox* lb) const {
			Q_ASSERT( dynamic_cast<KComboBox*>( lb->parent() ) );
			return m_enabled ? static_cast<KComboBox*>( lb->parent() )->height() + 2 : 0;
		}
	private:
		bool m_enabled;
};

/**
* @internal implementation of a @a ListBoxItem to provide an editable
* @a KoProperty::Widget as QListBoxItem in a @a ListBox instance.
*/
class EditListBoxItem : public ListBoxItem
{
	public:

		EditListBoxItem(QListBox* listbox, KexiMacroProperty* macroproperty)
			: ListBoxItem(listbox)
			, m_macroproperty(macroproperty)
			, m_prop(0)
			, m_widget(0)
		{
			init();
		}

		virtual ~EditListBoxItem() {
			delete m_widget;
			delete m_prop;
		}

		virtual QString text() const {
			KSharedPtr<KoMacro::Variable> variable = m_macroproperty->variable();
			Q_ASSERT( variable.data() );
			//kdDebug()<<"EditListBoxItem::text() text="<<variable->toString()<<endl;
			Q_ASSERT( variable->toString() != QString::null );
			return variable->toString();
		}

		KoProperty::Widget* widget() const { return m_widget; }
		KSharedPtr<KoMacro::MacroItem> macroItem() const { return m_macroproperty->macroItem(); }
		KSharedPtr<KoMacro::Variable> variable() const { return m_macroproperty->variable(); }
		KSharedPtr<KoMacro::Action> action() const { return m_macroproperty->macroItem()->action(); }

	protected:
		virtual void paint(QPainter* p) {
			if(! m_widget) return;
			Q_ASSERT( dynamic_cast<KComboBox*>( listBox()->parent() ) );
			const int w = width(listBox());
			const int h = height(listBox());
			m_widget->setFixedSize(w - 2, h - 2);
			p->drawPixmap(0, 0, QPixmap::grabWidget(m_widget), 1, 1, w - 1, h - 1);
		}

	private:
		void init() {
			KSharedPtr<KoMacro::MacroItem> macroitem = m_macroproperty->macroItem();
			Q_ASSERT( macroitem.data() );
			KSharedPtr<KoMacro::Action> action = m_macroproperty->macroItem()->action();
			if(! action.data()) {
				kdWarning() << "EditListBoxItem::EditListBoxItem() Skipped cause there exists no action for macroproperty=" << m_macroproperty->name() << endl;
				return;
			}
			KoProperty::Property* parentproperty = m_macroproperty->parentProperty();
			if(! parentproperty) {
				kdWarning() << "EditListBoxItem::EditListBoxItem() No parentproperty defined" << endl;
				return;
			}
			KSharedPtr<KoMacro::Variable> variable = m_macroproperty->variable();
			if(! variable.data()) {
				kdWarning() << "EditListBoxItem::EditListBoxItem() No variable defined for property=" << parentproperty->name() << endl;
				return;
			}

			QVariant variant = variable->variant();

			KSharedPtr<KoMacro::Variable> actionvariable = action->variable(m_macroproperty->name());
			if(actionvariable.data()) {
				QVariant actionvariant = actionvariable->variant();
				Q_ASSERT( ! actionvariant.isNull() );
				Q_ASSERT( variant.canCast(actionvariant.type()) );
				variant.cast( actionvariant.type() ); //preserve type.
			}

			int type = KoProperty::Auto;
			switch(variant.type()) {
				case QVariant::UInt:
				case QVariant::Int: {
					type = KoProperty::Integer;
				} break;
				case QVariant::CString:
				case QVariant::String: {
					type = KoProperty::String;
				} break;
				default: {
					kdWarning() << "EditListBoxItem::EditListBoxItem() name=" << variable->name() << " type=" << QVariant::typeToName(variant.type()) << endl;
				} break;
			}

			QString name = variable->name();
			Q_ASSERT(! name.isNull());
			//if(name.isNull()) name = "aaaaaaaaaaaaaaaaa";//TESTCASE
			m_prop = new KoProperty::Property(
				name.latin1(), // name
				variant, // value
				variable->text(), // caption
				QString::null, // description
				type, // type
				0 //parentproperty // parent
			);

			m_widget = KoProperty::FactoryManager::self()->createWidgetForProperty(m_prop);
			Q_ASSERT( m_widget != 0 );
			//m_widget->reparent(listBox()->viewport(), 0, QPoint(0,0));
			m_widget->reparent(listBox(), 0, QPoint(1,1));
			//layout->addWidget(m_widget, 1);
			m_widget->setMinimumHeight(5);
			m_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
		}

	private:
		KexiMacroProperty* m_macroproperty;
		KoProperty::Property* m_prop;
		KoProperty::Widget* m_widget;
};

/**
* @internal implementation of a @a QListBox for the combobox used within
* @a KexiMacroPropertyWidget to handle different variable-states.
*/
class ListBox : public QListBox
{
	public:
		ListBox(KComboBox* parent, KexiMacroProperty* macroproperty)
			: QListBox(parent)
			, m_macroproperty(macroproperty)
			, m_edititem(0)
		{
			viewport()->setBackgroundMode(PaletteBackground);
			setVariableHeight(true);
			update();
		}

		virtual ~ListBox() {}

		void update() {
			m_items.clear();
			delete m_edititem;
			m_edititem = 0;
			clear();

			m_edititem = new EditListBoxItem(this, m_macroproperty);
			Q_ASSERT( m_edititem->widget() != 0 );

			const QString name = m_macroproperty->name();
			KoMacro::Variable::List children;
			{
				KoMacro::Variable::List actionchildren;

				KSharedPtr<KoMacro::Variable> itemvar = m_macroproperty->macroItem()->variable(name,false);
				//kdDebug() << "KexiMacroProperty::ListBox::update() itemvar="<<(itemvar.data() ? "name:"+itemvar->name()+" value:"+itemvar->toString() : "NULL")<<endl;
				if(itemvar.data())
					actionchildren = itemvar->children();

				KSharedPtr<KoMacro::Action> action = m_edititem->action();
				KSharedPtr<KoMacro::Variable> actionvar = action.data() ? action->variable(name) : KSharedPtr<KoMacro::Variable>();
				//kdDebug() << "KexiMacroProperty::ListBox::update() actionvar="<<(actionvar.data() ? "name:"+actionvar->name()+" value:"+actionvar->toString() : "NULL")<<endl;
				if(actionvar.data())
					actionchildren += actionvar->children();

				KoMacro::Variable::List::ConstIterator it(actionchildren.constBegin()), end(actionchildren.constEnd());
				for(; it != end; ++it) {
					if(name == (*it)->name()) {
						KoMacro::Variable::List list = (*it)->children();
						KoMacro::Variable::List::ConstIterator listit(list.constBegin()), listend(list.constEnd());
						for(; listit != listend; ++listit)
							children.append( *listit );
					}
				}

				if(children.count() <= 0)
					children = actionchildren;
			}

			/*
			kdDebug() << "KexiMacroProperty::ListBox::update() name="<<name<<" childcount="<<children.count()<<endl;
			KoMacro::Variable::List::ConstIterator listit(children.constBegin()), listend(children.constEnd());
			for(; listit != listend; ++listit) {
				kdDebug()<<"    child name="<<(*listit)->name()<<" value="<<(*listit)->toString()<<" childcount="<<(*listit)->children().count()<<endl;
			}
			*/

			if(children.count() > 0) {
				KoMacro::Variable::List::Iterator childit(children.begin()), childend(children.end());
				for(; childit != childend; ++childit) {
					const QString n = (*childit)->name();
					//if(! n.startsWith("@")) continue;
					const QVariant v = (*childit)->variant();

					//kdDebug() << "  child name=" << n << " value=" << v << endl;
					switch( v.type() ) {
						/* case QVariant::Map: {
							const QMap<QString,QVariant> map = v.toMap();
							for(QMap<QString,QVariant>::ConstIterator it = map.constBegin(); it != map.constEnd(); ++it)
								m_items.append(it.key());
						} break; */
						case QVariant::List: {
							const QValueList<QVariant> list = v.toList();
							for(QValueList<QVariant>::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) {
								const QString s = (*it).toString().stripWhiteSpace();
								if(! s.isEmpty())
									m_items.append(s);
							}
						} break;
						case QVariant::StringList: {
							const QStringList list = v.toStringList();
							for(QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it)
								if(! (*it).isEmpty())
									m_items.append(*it);
						} break;
						default: {
							const QString s = v.toString().stripWhiteSpace();
							if(! s.isEmpty())
								m_items.append(s);
						} break;
					}
				}
			}

			QListBoxItem* item = m_edititem;
			const uint count = m_items.count();
			for(uint i = 0; i < count; i++)
				item = new ListBoxItem(this, m_items[i], item);
		}

		EditListBoxItem* editItem() const { return m_edititem; }
		QStringList items() const { return m_items; }

		virtual void hide () {
			QListBox::hide();
			for(uint i = 0; i < count(); i++)
				static_cast<ListBoxItem*>( item(i) )->setEnabled(false);
		}
		virtual void show() {
			update();
			adjustSize();
			QListBox::show();
		}

	private:
		KexiMacroProperty* m_macroproperty;
		EditListBoxItem* m_edititem;
		QStringList m_items;
};

/**
* @internal d-pointer class to be more flexible on future extension of the
* functionality without to much risk to break the binary compatibility.
*/
class KexiMacroPropertyWidget::Private
{
	public:
		KexiMacroProperty* macroproperty;
		KComboBox* combobox;
		ListBox* listbox;
};

KexiMacroPropertyWidget::KexiMacroPropertyWidget(KoProperty::Property* property, QWidget* parent)
	: KoProperty::Widget(property, parent)
	, d( new Private() )
{
	kdDebug() << "KexiMacroPropertyWidget::KexiMacroPropertyWidget() Ctor" << endl;

	QHBoxLayout* layout = new QHBoxLayout(this, 0, 0);

	d->macroproperty = dynamic_cast<KexiMacroProperty*>( property->customProperty() );
	if(! d->macroproperty) {
		kdWarning() << "KexiMacroPropertyWidget::KexiMacroPropertyWidget() Missing macroproperty for property=" << property->name() << endl;
		return;
	}

	d->combobox = new KComboBox(this);
	layout->addWidget(d->combobox);
	d->listbox = new ListBox(d->combobox, d->macroproperty);
	d->combobox->setEditable(true);
	d->combobox->setListBox(d->listbox);
	d->combobox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	d->combobox->setMinimumHeight(5);
	d->combobox->setInsertionPolicy(QComboBox::NoInsertion);
	d->combobox->setMinimumSize(10, 0); // to allow the combo to be resized to a small size
	d->combobox->setAutoCompletion(false);
	d->combobox->setContextMenuEnabled(false);

	QVariant value = d->macroproperty->value();
	int index = d->listbox->items().findIndex( value.toString() );
	if(index >= 0) {
		d->combobox->setCurrentItem(index + 1);
		d->listbox->setCurrentItem(index + 1);
	}
	else {
		Q_ASSERT( d->listbox->editItem()->widget() != 0 );
		d->listbox->editItem()->widget()->setValue( d->macroproperty->value(), true );
		//d->combobox->setCurrentItem(0);
	}
	kdDebug() << ">>> KexiMacroPropertyWidget::KexiMacroPropertyWidget() CurrentItem=" << d->combobox->currentItem() << endl;

	d->combobox->setFocusProxy( d->listbox->editItem()->widget() );
	setFocusWidget( d->combobox->lineEdit() );

	connect(d->combobox, SIGNAL(textChanged(const QString&)), 
	        this, SLOT(slotComboBoxChanged()));
	connect(d->combobox, SIGNAL(activated(int)),
	        this, SLOT(slotComboBoxActivated()));
	connect(d->listbox->editItem()->widget(), SIGNAL(valueChanged(Widget*)),
	        this, SLOT(slotWidgetValueChanged()));
	connect(d->macroproperty, SIGNAL(valueChanged()),
	        this, SLOT(slotPropertyValueChanged()));
}

KexiMacroPropertyWidget::~KexiMacroPropertyWidget()
{
	kdDebug() << "KexiMacroPropertyWidget::~KexiMacroPropertyWidget() Dtor" << endl;
	delete d;
}

QVariant KexiMacroPropertyWidget::value() const
{
	kdDebug()<<"KexiMacroPropertyWidget::value() value="<<d->macroproperty->value()<<endl;
	return d->macroproperty->value();
	/* QVariant value = d->combobox->currentText();
	value.cast( d->macroproperty->value().type() );
	return value; */
}

void KexiMacroPropertyWidget::setValue(const QVariant& value, bool emitChange)
{
	kdDebug()<<"KexiMacroPropertyWidget::setValue() value="<<value<<" emitChange="<<emitChange<<endl;
	
	if(! emitChange)
		d->combobox->blockSignals(true);

	const QString s = value.toString();
	d->combobox->setCurrentText( s.isNull() ? "" : s );

	if(emitChange)
		emit valueChanged(this);
	else
		d->combobox->blockSignals(false);
}

void KexiMacroPropertyWidget::setReadOnlyInternal(bool readOnly)
{
	Q_UNUSED(readOnly);
	//kdDebug()<<"KexiMacroPropertyWidget::setReadOnlyInternal() readOnly="<<readOnly<<endl;
}

void KexiMacroPropertyWidget::slotComboBoxChanged()
{
	kdDebug()<<"KexiMacroPropertyWidget::slotComboBoxChanged()"<<endl;
	const QVariant v = d->combobox->currentText();
	d->macroproperty->setValue(v, true);
	//emit valueChanged(this);
}

void KexiMacroPropertyWidget::slotComboBoxActivated()
{
	Q_ASSERT( d->listbox->editItem()->widget() );
	const int index = d->combobox->currentItem();
	QString text = (index == 0)
		? d->listbox->editItem()->widget()->value().toString()
		: d->combobox->text(index);
	kdDebug()<<"KexiMacroPropertyWidget::slotComboBoxActivated() index="<<index<<" text="<<text<<endl;
	d->combobox->setCurrentText(text);
	slotWidgetValueChanged();
}

void KexiMacroPropertyWidget::slotWidgetValueChanged()
{
	d->macroproperty->emitPropertyChanged();
}

void KexiMacroPropertyWidget::slotPropertyValueChanged()
{
	Q_ASSERT( d->listbox->editItem()->widget() );
	const QVariant v = d->macroproperty->value();
	kdDebug()<<"KexiMacroPropertyWidget::slotPropertyValueChanged() value="<<v<<endl;
	d->listbox->editItem()->widget()->setValue(v, true);
}

#include "keximacroproperty.moc"