Esempio n. 1
0
void KexiMacroError::designbtnClicked()
{
	if(! d->mainwin->project()) {
		kdWarning() << QString("KexiMacroError::designbtnClicked(): No project open.") << endl;
		return;
	}

	// We need to determinate the KexiPart::Item which should be opened.
	KSharedPtr<KoMacro::Macro> macro = d->context->macro();
	const QString name = macro->name();
	KexiPart::Item* item = d->mainwin->project()->itemForMimeType("kexi/macro", name);
	if(! item) {
		kdWarning() << QString("KexiMacroError::designbtnClicked(): No such macro \"%1\"").arg(name) << endl;
		return;
	}

	// Try to open the KexiPart::Item now.
	bool openingCancelled;
	if(! d->mainwin->openObject(item, Kexi::DesignViewMode, openingCancelled)) {
		if(! openingCancelled) {
			kdWarning() << QString("KexiMacroError::designbtnClicked(): Open macro \"%1\" in designview failed.").arg(name) << endl;
			return;
		}
	}

	close();
}
Esempio n. 2
0
void MacroTests::testMacro()
{
	kdDebug()<<"===================== testMacro() ======================" << endl;

	QDomElement const domelement = d->doomdocument->documentElement();
	
	KSharedPtr<KoMacro::Macro> macro1 = KoMacro::Manager::self()->createMacro("testMacro");
	KSharedPtr<KoMacro::Macro> macro2 = KoMacro::Manager::self()->createMacro("testMacro");
	//Is our XML parseable ?
	KOMACROTEST_ASSERT(macro1->parseXML(domelement),true);
	KOMACROTEST_ASSERT(macro2->parseXML(domelement),true);

	//check that it is not null
	KOMACROTEST_XASSERT(sizetype(macro1.data()), sizetype(0));
	KOMACROTEST_XASSERT(sizetype(macro2.data()), sizetype(0));

	//check macro1 == macro2
	KOMACROTEST_ASSERT(macro1->name(), macro2->name() );

	//create list of KsharedPtr from the childs of the macro	
	QValueList< KSharedPtr<KoMacro::MacroItem> >& items1 = macro1->items();
	QValueList< KSharedPtr<KoMacro::MacroItem> >& items2 = macro2->items();
	
	//check that there is one
	KOMACROTEST_XASSERT( items1.count(), sizetype(0) );	
	KOMACROTEST_XASSERT( items2.count(), sizetype(0) );	

	//check macro1 == macro2	
	KOMACROTEST_ASSERT( items1.count(), items2.count() );
	
	//check the name
	KOMACROTEST_ASSERT( QString(macro1->name()), QString("testMacro") );
	
	{
		const QString tmp1 = QString("test");
		macro1->setName(tmp1);

		//check the name changed
		KOMACROTEST_XASSERT( QString(macro1->name()), QString("testMacro") );	
		//check the name
		KOMACROTEST_ASSERT( QString(macro1->name()), QString("test") );
	}
	
	//fetch the first one
	KSharedPtr<KoMacro::Action> actionptr = items1[0]->action();
	//check that it is not null
	KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
	//check that it has the right name
	KOMACROTEST_ASSERT( QString(actionptr->name()), QString("testaction") );
	//check that it has the right text
	KOMACROTEST_ASSERT( actionptr->text(), QString("Test") );

	//try to clear items
	macro1->clearItems();
	//get items
	items1 = macro1->items();
	//check that they are deleted
	KOMACROTEST_ASSERT( items1.count(), sizetype(0) );
}