summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-22 00:24:52 (UTC)
committer zecke <zecke>2004-02-22 00:24:52 (UTC)
commit7e25ffee3337376d60c9c382bda4664672fec5de (patch) (unidiff)
treed3c1d35066b1afe6480ad389ea3d97c5e7fde475
parent91faf16c7336e54a6472fc9821903782918be539 (diff)
downloadopie-7e25ffee3337376d60c9c382bda4664672fec5de.zip
opie-7e25ffee3337376d60c9c382bda4664672fec5de.tar.gz
opie-7e25ffee3337376d60c9c382bda4664672fec5de.tar.bz2
check if there is a listview item at all.
c cast -> static_cast
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/templatedialogimpl.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/pim/todo/templatedialogimpl.cpp b/core/pim/todo/templatedialogimpl.cpp
index c2306ac..63d8107 100644
--- a/core/pim/todo/templatedialogimpl.cpp
+++ b/core/pim/todo/templatedialogimpl.cpp
@@ -16,103 +16,112 @@ namespace {
16 TemplateListItem( QListView*, 16 TemplateListItem( QListView*,
17 const QString& name, 17 const QString& name,
18 const OTodo& ); 18 const OTodo& );
19 ~TemplateListItem(); 19 ~TemplateListItem();
20 20
21 OTodo event()const; 21 OTodo event()const;
22 QString text()const; 22 QString text()const;
23 void setText(const QString& str ); 23 void setText(const QString& str );
24 void setEvent( const OTodo& ); 24 void setEvent( const OTodo& );
25 private: 25 private:
26 QString m_name; 26 QString m_name;
27 OTodo m_ev; 27 OTodo m_ev;
28 }; 28 };
29 29
30 /* implementation */ 30 /* implementation */
31 TemplateListItem::TemplateListItem( QListView* view, 31 TemplateListItem::TemplateListItem( QListView* view,
32 const QString& text, 32 const QString& text,
33 const OTodo& ev ) 33 const OTodo& ev )
34 : QListViewItem( view ), m_name( text ), m_ev( ev ) 34 : QListViewItem( view ), m_name( text ), m_ev( ev )
35 { 35 {
36 QListViewItem::setText(0, m_name ); 36 QListViewItem::setText(0, m_name );
37 } 37 }
38 TemplateListItem::~TemplateListItem() {} 38 TemplateListItem::~TemplateListItem() {}
39 OTodo TemplateListItem::event() const { 39 OTodo TemplateListItem::event() const {
40 return m_ev; 40 return m_ev;
41 } 41 }
42 QString TemplateListItem::text()const { 42 QString TemplateListItem::text()const {
43 return m_name; 43 return m_name;
44 } 44 }
45 void TemplateListItem::setText( const QString& str ) { 45 void TemplateListItem::setText( const QString& str ) {
46 QListViewItem::setText(0, str ); 46 QListViewItem::setText(0, str );
47 m_name = str; 47 m_name = str;
48 } 48 }
49 void TemplateListItem::setEvent( const OTodo& ev) { 49 void TemplateListItem::setEvent( const OTodo& ev) {
50 m_ev = ev; 50 m_ev = ev;
51 } 51 }
52} 52}
53 53
54TemplateDialogImpl::TemplateDialogImpl( MainWindow* win, 54TemplateDialogImpl::TemplateDialogImpl( MainWindow* win,
55 TemplateManager* man ) 55 TemplateManager* man )
56 : TemplateDialog( win ), m_win( win), m_man( man ) 56 : TemplateDialog( win ), m_win( win), m_man( man )
57{ 57{
58 /* fill the listview */ 58 /* fill the listview */
59 /* not the fastest way.... */ 59 /* not the fastest way.... */
60 QStringList list = man->templates(); 60 QStringList list = man->templates();
61 for (QStringList::Iterator it = list.begin(); 61 for (QStringList::Iterator it = list.begin();
62 it != list.end(); ++it ) { 62 it != list.end(); ++it ) {
63 new TemplateListItem( listView(), (*it), man->templateEvent( (*it) ) ); 63 new TemplateListItem( listView(), (*it), man->templateEvent( (*it) ) );
64 } 64 }
65 listView()->addColumn( QWidget::tr("Name") ); 65 listView()->addColumn( QWidget::tr("Name") );
66 66
67 connect( listView(), SIGNAL(clicked(QListViewItem*) ), 67 connect( listView(), SIGNAL(clicked(QListViewItem*) ),
68 this, SLOT(slotClicked(QListViewItem*) ) ); 68 this, SLOT(slotClicked(QListViewItem*) ) );
69} 69}
70TemplateDialogImpl::~TemplateDialogImpl() { 70TemplateDialogImpl::~TemplateDialogImpl() {
71 71
72} 72}
73void TemplateDialogImpl::slotAdd() { 73void TemplateDialogImpl::slotAdd() {
74 QString str = QWidget::tr("New Template %1").arg( listView()->childCount() ); 74 QString str = QWidget::tr("New Template %1").arg( listView()->childCount() );
75 OTodo ev; 75 OTodo ev;
76 m_man->addEvent(str, ev); 76 m_man->addEvent(str, ev);
77 new TemplateListItem( listView(), str, ev ); 77 new TemplateListItem( listView(), str, ev );
78} 78}
79void TemplateDialogImpl::slotRemove() { 79void TemplateDialogImpl::slotRemove() {
80 TemplateListItem* item = (TemplateListItem*) listView()->currentItem(); 80 if (!listView()->currentItem() )
81 return;
82
83 TemplateListItem* item = static_cast<TemplateListItem*>( listView()->currentItem() );
81 listView()->takeItem( item ); 84 listView()->takeItem( item );
82 85
83 m_man->removeEvent( item->text() ); 86 m_man->removeEvent( item->text() );
84 87
85 delete item; 88 delete item;
86} 89}
87void TemplateDialogImpl::slotEdit() { 90void TemplateDialogImpl::slotEdit() {
88 TemplateListItem* item = (TemplateListItem*)listView()->currentItem(); 91 if ( !listView()->currentItem() )
92 return;
93
94 TemplateListItem* item = static_cast<TemplateListItem*>( listView()->currentItem() );
89 OTodo ev = m_win->currentEditor()->edit( m_win, item->event() ); 95 OTodo ev = m_win->currentEditor()->edit( m_win, item->event() );
90 if ( m_win->currentEditor()->accepted() ) { 96 if ( m_win->currentEditor()->accepted() ) {
91 item->setEvent( ev ); 97 item->setEvent( ev );
92 m_man->removeEvent( item->text() ); 98 m_man->removeEvent( item->text() );
93 m_man->addEvent( item->text(), ev ); 99 m_man->addEvent( item->text(), ev );
94 } 100 }
95} 101}
96/* 102/*
97 * we need to update 103 * we need to update
98 * the text 104 * the text
99 */ 105 */
100 106
101void TemplateDialogImpl::slotReturn() { 107void TemplateDialogImpl::slotReturn() {
102 TemplateListItem* tbl = (TemplateListItem*)listView()->currentItem(); 108 if ( !listView()->currentItem() )
109 return;
110
111 TemplateListItem* tbl = static_cast<TemplateListItem*>( listView()->currentItem() );
103 112
104 if (tbl->text() != edit()->text() ) { 113 if (tbl->text() != edit()->text() ) {
105 m_man->removeEvent( tbl->text() ); 114 m_man->removeEvent( tbl->text() );
106 tbl->setText( edit()->text() ); 115 tbl->setText( edit()->text() );
107 m_man->addEvent( tbl->text(), tbl->event() ); 116 m_man->addEvent( tbl->text(), tbl->event() );
108 } 117 }
109} 118}
110/* update the lineedit when changing */ 119/* update the lineedit when changing */
111void TemplateDialogImpl::slotClicked( QListViewItem* item) { 120void TemplateDialogImpl::slotClicked( QListViewItem* item) {
112 if (!item) 121 if (!item)
113 return; 122 return;
114 123
115 TemplateListItem* tbl = static_cast<TemplateListItem*>(item); 124 TemplateListItem* tbl = static_cast<TemplateListItem*>(item);
116 edit()->setText( tbl->text() ); 125 edit()->setText( tbl->text() );
117} 126}
118 127