summaryrefslogtreecommitdiffstats
path: root/parts/snippet/snippetitem.h
blob: ac6fb416018a1dfc4bdb4a3138d57d6a766c9f99 (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
/*
 *  File : snippetitem.h
 *
 *  Author: Robert Gruber <rgruber@users.sourceforge.net>
 *
 *  Copyright: See COPYING file that comes with this distribution
 */

#ifndef SNIPPETITEM_H
#define SNIPPETITEM_H

#include <klistview.h>
#include <klocale.h>

class QString;

class SnippetGroup;

/**
This class represents one CodeSnippet-Item in the listview.
It also holds the needed data for one snippet.
@author Robert Gruber
*/
class SnippetItem : public QListViewItem {
friend class SnippetGroup;
public:
    SnippetItem(QListViewItem * parent, QString name, QString text);

    ~SnippetItem();
    QString getName();
    QString getText();
    int getParent() { return iParent; }
    void resetParent();
    void setText(QString text);
    void setName(QString name);
    static SnippetItem * findItemByName(QString name, QPtrList<SnippetItem> &list);
    static SnippetGroup * findGroupById(int id, QPtrList<SnippetItem> &list);
    
private:
  SnippetItem(QListView * parent, QString name, QString text);
  QString strName;
  QString strText;
  int iParent;
};

/**
This class represents one group in the listview.
It is derived from SnippetItem in order to allow storing 
it in the main QPtrList<SnippetItem>.
@author Robert Gruber
*/
class SnippetGroup : public SnippetItem {
public:
    SnippetGroup(QListView * parent, QString name, int id, QString lang=i18n("All"));
    ~SnippetGroup();

    int getId() { return iId; }
    static int getMaxId() { return iMaxId; }
    QString getLanguage() { return strLanguage; }
    
    void setId(int id);
    void setLanguage(QString lang) { strLanguage = lang; }

private:
    static int iMaxId;
    int iId;
    QString strLanguage;
};

#endif