kmail
snippetitem.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "snippetitem.h"
00015
00016 #include <kaction.h>
00017
00018 #include <qstring.h>
00019
00020 SnippetItem::SnippetItem(QListView * parent, QString name, QString text )
00021 : QListViewItem( parent, name ), action(0)
00022 {
00023 strName = name;
00024 strText = text;
00025 iParent = -1;
00026 }
00027
00028 SnippetItem::SnippetItem(QListViewItem * parent, QString name, QString text)
00029 : QListViewItem( parent, name ), action(0)
00030 {
00031 strName = name;
00032 strText = text;
00033 iParent = ((SnippetGroup *)parent)->getId();
00034 }
00035
00036 SnippetItem::~SnippetItem()
00037 {
00038 if ( action ) {
00039 action->unplugAll();
00040 delete action;
00041 }
00042 }
00043
00044
00048 QString SnippetItem::getName()
00049 {
00050 return strName;
00051 }
00052
00053
00057 QString SnippetItem::getText()
00058 {
00059 return strText;
00060 }
00061
00062
00066 void SnippetItem::setText(QString text)
00067 {
00068 strText = text;
00069 }
00070
00071
00075 void SnippetItem::setName(QString name)
00076 {
00077 strName = name;
00078 }
00079
00080 void SnippetItem::resetParent()
00081 {
00082 SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
00083 if (group)
00084 iParent = group->getId();
00085 }
00086
00087
00088 KAction* SnippetItem::getAction()
00089 {
00090 return action;
00091 }
00092
00093 void SnippetItem::setAction(KAction * anAction)
00094 {
00095 action = anAction;
00096 }
00097
00098 void SnippetItem::slotExecute()
00099 {
00100 emit execute( this );
00101 }
00102
00103
00104 SnippetItem * SnippetItem::findItemByName(QString name, QPtrList<SnippetItem> &list)
00105 {
00106 for ( SnippetItem * item = list.first(); item; item = list.next() ) {
00107 if (item->getName() == name)
00108 return item;
00109 }
00110 return NULL;
00111 }
00112
00113 SnippetGroup * SnippetItem::findGroupById(int id, QPtrList<SnippetItem> &list)
00114 {
00115 for ( SnippetItem * item = list.first(); item; item = list.next() ) {
00116 SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
00117 if (group && group->getId() == id)
00118 return group;
00119 }
00120 return NULL;
00121 }
00122
00123
00124
00125
00126
00127
00128 int SnippetGroup::iMaxId = 1;
00129
00130 SnippetGroup::SnippetGroup(QListView * parent, QString name, int id)
00131 : SnippetItem(parent, name, "GROUP")
00132 {
00133 if (id > 0) {
00134 iId = id;
00135 if (id >= iMaxId)
00136 iMaxId = id+1;
00137 } else {
00138 iId = iMaxId;
00139 iMaxId++;
00140 }
00141 }
00142
00143 SnippetGroup::~SnippetGroup()
00144 {
00145 }
00146
00147 void SnippetGroup::setId(int id)
00148 {
00149 iId = id;
00150 if (iId >= iMaxId)
00151 iMaxId = iId+1;
00152 }
00153
00154 #include "snippetitem.moc"
|