summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/queries/kexiquerypart.h
blob: f404e6e682f75ed85272648d114227edeaf5d60b (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
/* This file is part of the KDE project
   Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
   Copyright (C) 2004,2006 Jaroslaw Staniek <js@iidea.pl>

   This program 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 program 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 program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KEXIQUERYPART_H
#define KEXIQUERYPART_H

#include <tqmap.h>

#include <kexidialogbase.h>
#include <kexipart.h>
#include <kexipartitem.h>
//#include <kexipartdatasource.h>

#include <kexidb/queryschema.h>
#include <kexidb/connection.h>

class KexiMainWin;
namespace KexiDB
{
	class QuerySchema;
	class Connection;
}

class KexiProject;

//! @short Kexi Query Designer Plugin.
class KexiQueryPart : public KexiPart::Part
{
	Q_OBJECT
  TQ_OBJECT

	public:
		KexiQueryPart(TQObject *parent, const char *name, const TQStringList &);
		virtual ~KexiQueryPart();

		virtual bool remove(KexiMainWindow *win, KexiPart::Item &item);

		//! @short Temporary data kept in memory while switching between Query Dialog's views
		class TempData : public KexiDialogTempData, 
		                 public KexiDB::Connection::TableSchemaChangeListenerInterface
		{
			public:
				TempData(KexiDialogBase* parent, KexiDB::Connection *conn);
				virtual ~TempData();
				virtual tristate closeListener();
				void clearQuery();
				void unregisterForTablesSchemaChanges();
				void registerTableSchemaChanges(KexiDB::QuerySchema *q);

				/*! Assigns query \a query for this data.
				 Existing query (available using query()) is deleted but only 
				 if it is not owned by parent dialog (i.e. != KexiDialogBase::schemaData()).
				 \a query can be 0. 
				 If \a query is equal to existing query, nothing is performed.
				*/
				void setQuery(KexiDB::QuerySchema *query);

				//! \return query associated with this data
				KexiDB::QuerySchema *query() const { return m_query; }

				//! Takes query associated with this data (without deleting) and returns it.
				//! After this call query() == 0
				KexiDB::QuerySchema *takeQuery();

				//! Connection used for retrieving definition of the query
				KexiDB::Connection *conn;

				/*! true, if \a query member has changed in previous view. 
				 Used on view switching. We're checking this flag to see if we should 
				 rebuild internal structure for DesignViewMode of regenerated sql text 
				 in TextViewMode after switch from other view. */
				bool queryChangedInPreviousView : 1;

			protected:
				KexiDB::QuerySchema *m_query;
		};

		virtual TQString i18nMessage(const TQCString& englishMessage, 
			KexiDialogBase* dlg) const;

		/*! Renames stored data pointed by \a item to \a newName. 
		 Reimplemented to mark the query obsolete by using KexiDB::Connection::setQuerySchemaObsolete(). */
		virtual tristate rename(KexiMainWindow * win, KexiPart::Item & item, const TQString& newName);

	protected:
		virtual KexiDialogTempData* createTempData(KexiDialogBase* dialog);

		virtual KexiViewBase* createView(TQWidget *parent, KexiDialogBase* dialog, 
			KexiPart::Item &item, int viewMode = Kexi::DataViewMode, TQMap<TQString,TQString>* staticObjectArgs = 0);

//		virtual void initPartActions( KActionCollection *col );
//		virtual void initInstanceActions( int mode, KActionCollection *col );

		virtual void initPartActions();
		virtual void initInstanceActions();

		virtual KexiDB::SchemaData* loadSchemaData(KexiDialogBase *dlg, 
			const KexiDB::SchemaData& sdata, int viewMode);
};

#endif