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
120
121
122
123
124
125
126
127
|
/*
* File : snippetitem.cpp
*
* Author: Robert Gruber <rgruber@users.sourceforge.net>
*
* Copyright: See COPYING file that comes with this distribution
*/
#include <qstring.h>
#include "snippetitem.h"
SnippetItem::SnippetItem(QListView * parent, QString name, QString text )
: QListViewItem( parent, name )
{
strName = name;
strText = text;
iParent = -1;
}
SnippetItem::SnippetItem(QListViewItem * parent, QString name, QString text)
: QListViewItem( parent, name )
{
strName = name;
strText = text;
iParent = ((SnippetGroup *)parent)->getId();
}
SnippetItem::~SnippetItem()
{
}
/*!
\fn SnippetItem::getName()
*/
QString SnippetItem::getName()
{
return strName;
}
/*!
\fn SnippetItem::getText
*/
QString SnippetItem::getText()
{
return strText;
}
/*!
\fn SnippetItem::setText(QString text)
*/
void SnippetItem::setText(QString text)
{
strText = text;
}
/*!
\fn SnippetItem::setName(QString name)
*/
void SnippetItem::setName(QString name)
{
strName = name;
}
void SnippetItem::resetParent()
{
SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
if (group)
iParent = group->getId();
}
SnippetItem * SnippetItem::findItemByName(QString name, QPtrList<SnippetItem> &list)
{
for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
if (item->getName() == name)
return item;
}
return NULL;
}
SnippetGroup * SnippetItem::findGroupById(int id, QPtrList<SnippetItem> &list)
{
for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
if (group && group->getId() == id)
return group;
}
return NULL;
}
/* * * * * * * * * * * * * * * * * * * *
Deklaration for class SnippetGroup
* * * * * * * * * * * * * * * * * * * */
int SnippetGroup::iMaxId = 1;
SnippetGroup::SnippetGroup(QListView * parent, QString name, int id, QString lang)
: SnippetItem(parent, name, "GROUP")
{
if (id > 0) {
iId = id;
if (id >= iMaxId)
iMaxId = id+1;
} else {
iId = iMaxId;
iMaxId++;
}
strLanguage = lang;
}
SnippetGroup::~SnippetGroup()
{
}
void SnippetGroup::setId(int id)
{
iId = id;
if (iId >= iMaxId)
iMaxId = iId+1;
}
|