summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexipartitem.h
blob: c0b88d017d36ee701b351581666e3ddcbeabc466 (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
/* This file is part of the KDE project
   Copyright (C) 2002, 2003 Lucijan Busch <[email protected]>
   Copyright (C) 2005 Jaroslaw Staniek <[email protected]>

   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.
*/

#ifndef KEXIPROJECTPARTITEM_H
#define KEXIPROJECTPARTITEM_H

#include <tqobject.h>
#include <tqintdict.h>
#include <tqptrlist.h>

namespace KexiDB
{
	class Connection;
}

namespace KexiPart
{

class Info;

/*!
 @short Information about a single object that can be instantiated using Kexi Part

 KexiPart::Item stores:
	- identifier ident (low-level name, for example: table name)
	- mime type name, eg. "kexi/table"
	- caption (visible, i18n'd hight level name, eg. table or query title)
*/
class KEXICORE_EXPORT Item
{
	public:

		Item();
		~Item();

		int identifier() const { return m_id; }
		void setIdentifier(int id) { m_id = id; }

		TQCString mimeType() const { return m_mime; }
		void setMimeType(const TQCString &mime) { m_mime = mime; }

		TQString name() const { return m_name; }
		void setName(const TQString &name) { m_name = name; }

		TQString caption() const { return m_caption; }
		void setCaption(const TQString &c) { m_caption = c; }

		TQString description() const { return m_desc; }
		void setDescription(const TQString &d) { m_desc = d; }

		/*! \return "neverSaved" flag for this item what mean 
		 that is used when new item is created in-memory-only,
		 so we need to indicate for KexiProject about that state. 
		 By default this flag is false. 
		 Used by KexiMainWindowImpl::newObject(). */
		bool neverSaved() const { return m_neverSaved; }

		/*! \sa neverSaved().
		 Used by KexiMainWindowImpl::newObject(). */
		void setNeverSaved(bool set) { m_neverSaved = set; }

		bool isNull() const { return m_id==0; }

		//! \return caption if not empty, else returns name.
		inline TQString captionOrName() const { return m_caption.isEmpty() ? m_name : m_caption; }

	private:
		TQCString m_mime;
		TQString m_name;
		TQString m_caption;
		TQString m_desc;
		int m_id;
		bool m_neverSaved : 1;
};

typedef TQIntDict<KexiPart::Item> ItemDict;
typedef TQIntDictIterator<KexiPart::Item> ItemDictIterator;
typedef TQPtrListIterator<KexiPart::Item> ItemListIterator;

/*! 
 @short Part item list with reimplemented compareItems() method.

 Such a list is returend by KexiProject::getSortedItems(KexiPart::ItemList& list, KexiPart::Info *i);
 so you can call sort() on the list to sort it by item name. 
*/
class KEXICORE_EXPORT ItemList : public TQPtrList<KexiPart::Item> {
	public:
		ItemList() {}
	protected:
		virtual int compareItems( TQPtrCollection::Item item1, TQPtrCollection::Item item2 ) {
			return TQString::compare(
				static_cast<KexiPart::Item*>(item1)->name(), 
				static_cast<KexiPart::Item*>(item2)->name());
		}
};

}

#endif