objectnamevariable.h
1/***************************************************************************
2 * This file is part of the KDE project
3 * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
4 * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
5 * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this program; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 ***************************************************************************/
20
21#ifndef KEXIMACRO_OBJECTNAMEVARIABLE_H
22#define KEXIMACRO_OBJECTNAMEVARIABLE_H
23
24#include "../lib/variable.h"
25
26#include "kexivariable.h"
27
28#include <core/kexi.h>
29#include <core/kexiproject.h>
30#include <core/kexipartmanager.h>
31#include <core/kexipartinfo.h>
32
33#include <tdelocale.h>
34
35namespace KexiMacro {
36
41 template<class ACTIONIMPL>
42 class ObjectNameVariable : public KexiVariable<ACTIONIMPL>
43 {
44 public:
45 ObjectNameVariable(ACTIONIMPL* actionimpl, const TQString& objectname = TQString(), const TQString& name = TQString())
46 : KexiVariable<ACTIONIMPL>(actionimpl, "name", i18n("Name"))
47 {
48 if(! actionimpl->mainWin()->project())
49 return;
50
51 TQStringList namelist;
52 KexiPart::Info* info = Kexi::partManager().infoForMimeType( TQString("kexi/%1").arg(objectname) );
53 if(info) {
54 KexiPart::ItemDict* items = actionimpl->mainWin()->project()->items(info);
55 if(items)
56 for(KexiPart::ItemDictIterator item_it = *items; item_it.current(); ++item_it)
57 namelist << item_it.current()->name();
58 }
59
60 if(namelist.count() <= 0)
61 namelist << "";
62
63 for(TQStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it)
64 this->appendChild( TDESharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) );
65
66 this->setVariant( (name.isNull() || ! namelist.contains(name)) ? namelist[0] : name );
67
68 kdDebug()<<"##################### KexiActions::ObjectNameVariable() objectname="<<objectname<<" name="<<name<<" value="<<this->variant()<<" children="<<namelist<<endl;
69 }
70
71 virtual ~ObjectNameVariable() {}
72 };
73
74}
75
76#endif
Template class to offer common functionality needed by all KoMacro::Variable implementations Kexi pro...
The ViewVariable class provide a list of KexiPart::PartItem's supported by a KexiPart::Part as KoMacr...
Information about a Kexi Part (plugin).
Info * infoForMimeType(const TQString &mimeType)
A variable value used to provide abstract access to variables.
Definition variable.h:39
TQString name() const
Definition variable.cpp:137
void appendChild(TDESharedPtr< Variable > variable)
Append a Variable to the list of children this Variable has.
Definition variable.cpp:221
void setVariant(const TQVariant &variant, bool detecttype=true)
Set the TQVariant.
Definition variable.cpp:165
const TQVariant variant() const
Definition variable.cpp:157
KEXICORE_EXPORT KexiPart::Manager & partManager()
shared part manager
Definition kexi.cpp:97