/**********************************************************************
** Copyright (C) 2005-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of TQt Designer.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** Licensees holding valid TQt Commercial licenses may use this file in
** accordance with the TQt Commercial License Agreement provided with
** the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#ifndef METADATABASE_H
#define METADATABASE_H

#include <tqvariant.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqmap.h>
#include <tqptrlist.h>
#include <tqsizepolicy.h>
#include <tqsize.h>
#include <tqwidgetlist.h>
#include <tqcursor.h>

#include "pixmapchooser.h"
#include "../interfaces/languageinterface.h"

class TQObject;
class TQPixmap;
struct LanguageInterface;

class MetaDataBase
{
public:
    struct Connection
    {
	TQObject *sender, *receiver;
	TQCString signal, slot;
	bool operator==( const Connection &c ) const {
	    return sender == c.sender && receiver == c.receiver &&
		   signal == c.signal && slot == c.slot ;
	}
    };

    struct Function
    {
	TQString returnType;
	TQCString function;
	TQString specifier;
	TQString access;
	TQString type;
	TQString language;
	bool operator==( const Function &f ) const {
	    return ( returnType == f.returnType &&
		     function == f.function &&
		     specifier == f.specifier &&
		     access == f.access &&
		     type == f.type &&
		     language == f.language
		     );
	}
    };

    struct Property
    {
	TQCString property;
	TQString type;
	bool operator==( const Property &p ) const {
	    return property == p.property &&
		 type == p.type;
	}
    };

    struct CustomWidget
    {
	CustomWidget();
	CustomWidget( const CustomWidget &w );
	~CustomWidget() { delete pixmap; } // inlined to work around 2.7.2.3 bug
	bool operator==( const CustomWidget &w ) const;
	CustomWidget &operator=( const CustomWidget &w );

	bool hasSignal( const TQCString &signal ) const;
	bool hasSlot( const TQCString &slot ) const;
	bool hasProperty( const TQCString &prop ) const;

	enum IncludePolicy { Global, Local };
	TQString className;
	TQString includeFile;
	IncludePolicy includePolicy;
	TQSize tqsizeHint;
	TQSizePolicy sizePolicy;
	TQPixmap *pixmap;
	TQValueList<TQCString> lstSignals;
	TQValueList<Function> lstSlots;
	TQValueList<Property> lstProperties;
	int id;
	bool isContainer;
    };

    struct Include
    {
	Include() : header(), location(), implDecl( "in implementation" ) {}
	TQString header;
	TQString location;
	bool operator==( const Include &i ) const {
	    return header == i.header && location == i.location;
	}
	TQString implDecl;
    };

    struct Variable
    {
	TQString varName;
	TQString varAccess;
	bool operator==( const Variable &v ) const {
	    return varName == v.varName &&
		   varAccess == v.varAccess;
	}
    };

    struct MetaInfo
    {
	MetaInfo() : classNameChanged( FALSE ) { }
	TQString className;
	bool classNameChanged;
	TQString comment;
	TQString author;
    };

    MetaDataBase();
    static void clearDataBase();

    static void addEntry( TQT_BASE_OBJECT_NAME *o );
    static void removeEntry( TQT_BASE_OBJECT_NAME *o );
    static void setPropertyChanged( TQT_BASE_OBJECT_NAME *o, const TQString &property, bool changed );
    static bool isPropertyChanged( TQT_BASE_OBJECT_NAME *o, const TQString &property );
    static void setPropertyComment( TQT_BASE_OBJECT_NAME *o, const TQString &property, const TQString &comment );
    static TQString propertyComment( TQT_BASE_OBJECT_NAME *o, const TQString &property );
    static TQStringList changedProperties( TQT_BASE_OBJECT_NAME *o );

    static void setFakeProperty( TQT_BASE_OBJECT_NAME *o, const TQString &property, const TQVariant& value );
    static TQVariant fakeProperty( TQT_BASE_OBJECT_NAME * o, const TQString &property );
    static TQMap<TQString,TQVariant>* fakeProperties( TQT_BASE_OBJECT_NAME* o );

    static void setSpacing( TQT_BASE_OBJECT_NAME *o, int spacing );
    static int spacing( TQT_BASE_OBJECT_NAME *o );
    static void setMargin( TQT_BASE_OBJECT_NAME *o, int margin );
    static int margin( TQT_BASE_OBJECT_NAME *o );

    static void setResizeMode( TQT_BASE_OBJECT_NAME *o, const TQString &mode );
    static TQString resizeMode( TQT_BASE_OBJECT_NAME *o );

    static void addConnection( TQT_BASE_OBJECT_NAME *o, TQT_BASE_OBJECT_NAME *sender, const TQCString &signal,
			       TQT_BASE_OBJECT_NAME *receiver, const TQCString &slot, bool addCode = TRUE );
    static void removeConnection( TQT_BASE_OBJECT_NAME *o, TQObject *sender, const TQCString &signal,
				  TQObject *receiver, const TQCString &slot );
    static bool hasConnection( TQT_BASE_OBJECT_NAME *o, TQT_BASE_OBJECT_NAME *sender, const TQCString &signal,
			       TQT_BASE_OBJECT_NAME *receiver, const TQCString &slot );
    static void setupConnections( TQT_BASE_OBJECT_NAME *o, const TQValueList<LanguageInterface::Connection> &conns );
    static TQValueList<Connection> connections( TQT_BASE_OBJECT_NAME *o );
    static TQValueList<Connection> connections( TQT_BASE_OBJECT_NAME *o, TQT_BASE_OBJECT_NAME *sender, TQT_BASE_OBJECT_NAME *receiver );
    static TQValueList<Connection> connections( TQT_BASE_OBJECT_NAME *o, TQT_BASE_OBJECT_NAME *object );
    static void doConnections( TQT_BASE_OBJECT_NAME *o );

    static void addFunction( TQT_BASE_OBJECT_NAME *o, const TQCString &function, const TQString &specifier,
			     const TQString &access, const TQString &type, const TQString &language,
			     const TQString &returnType );
    static void removeFunction( TQT_BASE_OBJECT_NAME *o, const TQCString &function, const TQString &specifier,
				const TQString &access, const TQString &type, const TQString &language,
				const TQString &returnType );
    static void removeFunction( TQT_BASE_OBJECT_NAME *o, const TQString &function );
    static TQValueList<Function> functionList( TQT_BASE_OBJECT_NAME *o, bool onlyFunctions = FALSE );
    static TQValueList<Function> slotList( TQT_BASE_OBJECT_NAME *o );
    static bool isSlotUsed( TQT_BASE_OBJECT_NAME *o, const TQCString &slot );
    static bool hasFunction( TQT_BASE_OBJECT_NAME *o, const TQCString &function, bool onlyCustom = FALSE );
    static bool hasSlot( TQT_BASE_OBJECT_NAME *o, const TQCString &slot, bool onlyCustom = FALSE );
    static void changeFunction( TQT_BASE_OBJECT_NAME *o, const TQString &function, const TQString &newName,
				const TQString &returnType );
    static void changeFunctionAttributes( TQT_BASE_OBJECT_NAME *o, const TQString &oldName, const TQString &newName,
				      const TQString &specifier, const TQString &access,
				      const TQString &type, const TQString &language,
				      const TQString &returnType );
    static TQString languageOfFunction( TQT_BASE_OBJECT_NAME *o, const TQCString &function );
    static void setFunctionList( TQT_BASE_OBJECT_NAME *o, const TQValueList<Function> &functionList );


    static bool addCustomWidget( CustomWidget *w );
    static void removeCustomWidget( CustomWidget *w );
    static TQPtrList<CustomWidget> *customWidgets();
    static CustomWidget *customWidget( int id );
    static bool isWidgetNameUsed( CustomWidget *w );
    static bool hasCustomWidget( const TQString &className );

    static void setTabOrder( TQWidget *w, const TQWidgetList &order );
    static TQWidgetList tabOrder( TQWidget *w );

    static void setIncludes( TQT_BASE_OBJECT_NAME *o, const TQValueList<Include> &incs );
    static TQValueList<Include> includes( TQT_BASE_OBJECT_NAME *o );

    static void setForwards( TQT_BASE_OBJECT_NAME *o, const TQStringList &fwds );
    static TQStringList forwards( TQT_BASE_OBJECT_NAME *o );

    static void setVariables( TQT_BASE_OBJECT_NAME *o, const TQValueList<Variable> &vars );
    static void addVariable( TQT_BASE_OBJECT_NAME *o, const TQString &name, const TQString &access );
    static void removeVariable( TQT_BASE_OBJECT_NAME *o, const TQString &name );
    static TQValueList<Variable> variables( TQT_BASE_OBJECT_NAME *o );
    static bool hasVariable( TQT_BASE_OBJECT_NAME *o, const TQString &name );
    static TQString extractVariableName( const TQString &name );

    static void setSignalList( TQT_BASE_OBJECT_NAME *o, const TQStringList &sigs );
    static TQStringList signalList( TQT_BASE_OBJECT_NAME *o );

    static void setMetaInfo( TQT_BASE_OBJECT_NAME *o, MetaInfo mi );
    static MetaInfo metaInfo( TQT_BASE_OBJECT_NAME *o );

    static void setCursor( TQWidget *w, const TQCursor &c );
    static TQCursor cursor( TQWidget *w );

    static void setPixmapArgument( TQT_BASE_OBJECT_NAME *o, int pixmap, const TQString &arg );
    static TQString pixmapArgument( TQT_BASE_OBJECT_NAME *o, int pixmap );
    static void clearPixmapArguments( TQT_BASE_OBJECT_NAME *o );

    static void setPixmapKey( TQT_BASE_OBJECT_NAME *o, int pixmap, const TQString &arg );
    static TQString pixmapKey( TQT_BASE_OBJECT_NAME *o, int pixmap );
    static void clearPixmapKeys( TQT_BASE_OBJECT_NAME *o );

    static void setColumnFields( TQT_BASE_OBJECT_NAME *o, const TQMap<TQString, TQString> &columnFields );
    static TQMap<TQString, TQString> columnFields( TQT_BASE_OBJECT_NAME *o );

    static void setEditor( const TQStringList &langs );
    static bool hasEditor( const TQString &lang );

    static void setupInterfaceManagers( const TQString &plugDir );
    static TQStringList languages();

    static LanguageInterface *languageInterface( const TQString &lang );

    static TQString normalizeFunction( const TQString &f );

    static void clear( TQT_BASE_OBJECT_NAME *o );

    static void setBreakPoints( TQT_BASE_OBJECT_NAME *o, const TQValueList<uint> &l );
    static void setBreakPointCondition( TQT_BASE_OBJECT_NAME *o, int line, const TQString &condition );
    static TQValueList<uint> breakPoints( TQT_BASE_OBJECT_NAME *o );
    static TQString breakPointCondition( TQT_BASE_OBJECT_NAME *o, int line );

    static void setExportMacro( TQT_BASE_OBJECT_NAME *o, const TQString &macro );
    static TQString exportMacro( TQT_BASE_OBJECT_NAME *o );

    static bool hasObject( TQT_BASE_OBJECT_NAME *o );

};

#endif
