summaryrefslogtreecommitdiffstats
path: root/parts/snippet/snippetitem.cpp
blob: 69010a5d01ffb74964b0f3bb175cd69e2fde3f14 (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
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 <tqstring.h>


#include "snippetitem.h"

SnippetItem::SnippetItem(TQListView * tqparent, TQString name, TQString text )
			: TQListViewItem( tqparent, name )
{
  strName = name;
  strText = text;
  iParent = -1;
}

SnippetItem::SnippetItem(TQListViewItem * tqparent, TQString name, TQString text)
			: TQListViewItem( tqparent, name )
{
  strName = name;
  strText = text;
  iParent = ((SnippetGroup *)tqparent)->getId();
}

SnippetItem::~SnippetItem()
{
}


/*!
    \fn SnippetItem::getName()
 */
TQString SnippetItem::getName()
{
  return strName;
}


/*!
    \fn SnippetItem::getText
 */
TQString SnippetItem::getText()
{
  return strText;
}


/*!
    \fn SnippetItem::setText(TQString text)
 */
void SnippetItem::setText(TQString text)
{
  strText = text;
}


/*!
    \fn SnippetItem::setName(TQString name)
 */
void SnippetItem::setName(TQString name)
{
  strName = name;
}

void SnippetItem::resetParent()
{
  SnippetGroup * group = dynamic_cast<SnippetGroup*>(tqparent());
  if (group)
    iParent = group->getId();
}

SnippetItem * SnippetItem::findItemByName(TQString name, TQPtrList<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, TQPtrList<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(TQListView * tqparent, TQString name, int id, TQString lang)
 : SnippetItem(tqparent, 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;
}