summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-03-02 17:35:53 (UTC)
committer mickeyl <mickeyl>2003-03-02 17:35:53 (UTC)
commitb3b0d6ec136e550029b9cae7fb714d47071ea5b4 (patch) (unidiff)
tree9cc1fb741bb548c90915487572c49a1ae48e33eb
parentd0e64d0c7961de1c3ecb886ae76c6701f268d767 (diff)
downloadopie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.zip
opie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.tar.gz
opie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.tar.bz2
add child item factory to allow subclasses adding custom data items
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/cornucopia/olistview.cpp14
-rw-r--r--noncore/net/wellenreiter/cornucopia/olistview.h26
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.cpp25
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.h26
4 files changed, 64 insertions, 27 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.cpp b/noncore/net/wellenreiter/cornucopia/olistview.cpp
index f2d3730..c292eb9 100644
--- a/noncore/net/wellenreiter/cornucopia/olistview.cpp
+++ b/noncore/net/wellenreiter/cornucopia/olistview.cpp
@@ -114,24 +114,29 @@ void OListView::setAlternateBackground( const QColor &c )
114 114
115const QPen& OListView::columnSeparator() const 115const QPen& OListView::columnSeparator() const
116{ 116{
117 return m_columnSeparator; 117 return m_columnSeparator;
118} 118}
119 119
120void OListView::setColumnSeparator( const QPen& p ) 120void OListView::setColumnSeparator( const QPen& p )
121{ 121{
122 m_columnSeparator = p; 122 m_columnSeparator = p;
123 repaint(); 123 repaint();
124} 124}
125 125
126OListViewItem* OListView::childFactory()
127{
128 return new OListViewItem( this );
129}
130
126#ifndef QT_NO_DATASTREAM 131#ifndef QT_NO_DATASTREAM
127void OListView::serializeTo( QDataStream& s ) const 132void OListView::serializeTo( QDataStream& s ) const
128{ 133{
129 #warning Caution... the binary format is still under construction... 134 #warning Caution... the binary format is still under construction...
130 qDebug( "storing OListView..." ); 135 qDebug( "storing OListView..." );
131 136
132 // store number of columns and the labels 137 // store number of columns and the labels
133 s << columns(); 138 s << columns();
134 for ( int i = 0; i < columns(); ++i ) 139 for ( int i = 0; i < columns(); ++i )
135 s << columnText( i ); 140 s << columnText( i );
136 141
137 // calculate the number of top-level items to serialize 142 // calculate the number of top-level items to serialize
@@ -171,25 +176,25 @@ void OListView::serializeFrom( QDataStream& s )
171 QString coltext; 176 QString coltext;
172 s >> coltext; 177 s >> coltext;
173 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 178 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
174 setColumnText( i, coltext ); 179 setColumnText( i, coltext );
175 } 180 }
176 181
177 int items; 182 int items;
178 s >> items; 183 s >> items;
179 qDebug( "read number of items = %d", items ); 184 qDebug( "read number of items = %d", items );
180 185
181 for ( int i = 0; i < items; ++i ) 186 for ( int i = 0; i < items; ++i )
182 { 187 {
183 OListViewItem* item = new OListViewItem( this ); 188 OListViewItem* item = childFactory();
184 s >> *item; 189 s >> *item;
185 } 190 }
186 191
187 qDebug( "OListView loaded." ); 192 qDebug( "OListView loaded." );
188 193
189} 194}
190 195
191QDataStream& operator<<( QDataStream& s, const OListView& lv ) 196QDataStream& operator<<( QDataStream& s, const OListView& lv )
192{ 197{
193 lv.serializeTo( s ); 198 lv.serializeTo( s );
194} 199}
195 200
@@ -328,24 +333,29 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in
328 { 333 {
329 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 334 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
330 } 335 }
331 QListViewItem::paintCell( p, _cg, column, width, alignment ); 336 QListViewItem::paintCell( p, _cg, column, width, alignment );
332 337
333 //FIXME: Use styling here! 338 //FIXME: Use styling here!
334 339
335 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 340 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
336 p->setPen( pen ); 341 p->setPen( pen );
337 p->drawLine( width-1, 0, width-1, height() ); 342 p->drawLine( width-1, 0, width-1, height() );
338} 343}
339 344
345OListViewItem* OListViewItem::childFactory()
346{
347 return new OListViewItem( this );
348}
349
340#ifndef QT_NO_DATASTREAM 350#ifndef QT_NO_DATASTREAM
341void OListViewItem::serializeTo( QDataStream& s ) const 351void OListViewItem::serializeTo( QDataStream& s ) const
342{ 352{
343 #warning Caution... the binary format is still under construction... 353 #warning Caution... the binary format is still under construction...
344 qDebug( "storing OListViewItem..." ); 354 qDebug( "storing OListViewItem..." );
345 355
346 // store item text 356 // store item text
347 for ( int i = 0; i < listView()->columns(); ++i ) 357 for ( int i = 0; i < listView()->columns(); ++i )
348 { 358 {
349 s << text( i ); 359 s << text( i );
350 } 360 }
351 361
@@ -379,25 +389,25 @@ void OListViewItem::serializeFrom( QDataStream& s )
379 QString coltext; 389 QString coltext;
380 s >> coltext; 390 s >> coltext;
381 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 391 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
382 setText( i, coltext ); 392 setText( i, coltext );
383 } 393 }
384 394
385 int items; 395 int items;
386 s >> items; 396 s >> items;
387 qDebug( "read number of items = %d", items ); 397 qDebug( "read number of items = %d", items );
388 398
389 for ( int i = 0; i < items; ++i ) 399 for ( int i = 0; i < items; ++i )
390 { 400 {
391 OListViewItem* item = new OListViewItem( this ); 401 OListViewItem* item = childFactory();
392 s >> (*item); 402 s >> (*item);
393 } 403 }
394 404
395 qDebug( "OListViewItem loaded." ); 405 qDebug( "OListViewItem loaded." );
396} 406}
397 407
398QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 408QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
399{ 409{
400 lvi.serializeTo( s ); 410 lvi.serializeTo( s );
401} 411}
402 412
403QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 413QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.h b/noncore/net/wellenreiter/cornucopia/olistview.h
index 9df5500..8911e22 100644
--- a/noncore/net/wellenreiter/cornucopia/olistview.h
+++ b/noncore/net/wellenreiter/cornucopia/olistview.h
@@ -29,25 +29,25 @@
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33#ifndef OLISTVIEW_H 33#ifndef OLISTVIEW_H
34#define OLISTVIEW_H 34#define OLISTVIEW_H
35 35
36#include <qcolor.h> 36#include <qcolor.h>
37#include <qlistview.h> 37#include <qlistview.h>
38#include <qpen.h> 38#include <qpen.h>
39#include <qdatastream.h> 39#include <qdatastream.h>
40 40
41class OListViewFactory; 41class OListViewItem;
42 42
43/** 43/**
44 * A @ref QListView variant featuring visual and functional enhancements 44 * A @ref QListView variant featuring visual and functional enhancements
45 * like an alternate background for odd rows, an autostretch mode 45 * like an alternate background for odd rows, an autostretch mode
46 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. 46 * for the width of the widget ( >= Qt 3 only ) and persistence capabilities.
47 * 47 *
48 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 48 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
49 * @short OListView list/tree widget. 49 * @short OListView list/tree widget.
50 */ 50 */
51 class OListView: public QListView 51 class OListView: public QListView
52{ 52{
53 public: 53 public:
@@ -106,54 +106,48 @@ class OListViewFactory;
106 void setColumnSeparator( const QPen &p ); 106 void setColumnSeparator( const QPen &p );
107 107
108 /** 108 /**
109 * @return the alternate background color 109 * @return the alternate background color
110 */ 110 */
111 const QColor& alternateBackground() const; 111 const QColor& alternateBackground() const;
112 112
113 /** 113 /**
114 * @return the column separator pen 114 * @return the column separator pen
115 */ 115 */
116 const QPen& columnSeparator() const; 116 const QPen& columnSeparator() const;
117 117
118 /**
119 * create a list view item as child of this object
120 * @return the new object
121 */
122 virtual OListViewItem* childFactory();
123
118 #ifndef QT_NO_DATASTREAM 124 #ifndef QT_NO_DATASTREAM
119 /** 125 /**
120 * serialize this object to a @ref QDataStream 126 * serialize this object to a @ref QDataStream
121 * @param s the stream used to serialize this object. 127 * @param s the stream used to serialize this object.
122 */ 128 */
123 virtual void serializeTo( QDataStream& s ) const; 129 virtual void serializeTo( QDataStream& s ) const;
124 130
125 /** 131 /**
126 * serialize this object from a @ref QDataStream 132 * serialize this object from a @ref QDataStream
127 * @param s the stream used to serialize this object. 133 * @param s the stream used to serialize this object.
128 */ 134 */
129 virtual void serializeFrom( QDataStream& s ); 135 virtual void serializeFrom( QDataStream& s );
130 #endif 136 #endif
131 137
132 /**
133 * returns a factory for OListView classes
134 * creates one on the fly if it doesn't exist
135 * @return the XML Factory
136 */
137 #ifndef QT_NO_XML
138 //OListViewFactory* Factory();
139 #endif
140
141 private: 138 private:
142 QColor m_alternateBackground; 139 QColor m_alternateBackground;
143 bool m_fullWidth; 140 bool m_fullWidth;
144 QPen m_columnSeparator; 141 QPen m_columnSeparator;
145 #ifndef QT_NO_XML
146 //OListViewFactory* m_Factory;
147 #endif
148}; 142};
149 143
150#ifndef QT_NO_DATASTREAM 144#ifndef QT_NO_DATASTREAM
151/** 145/**
152 * \relates QListView 146 * \relates QListView
153 * Writes a listview to the stream and returns a reference to the stream. 147 * Writes a listview to the stream and returns a reference to the stream.
154 */ 148 */
155QDataStream& operator<<( QDataStream& s, const OListView& lv ); 149QDataStream& operator<<( QDataStream& s, const OListView& lv );
156/** 150/**
157 * \relates QListView 151 * \relates QListView
158 * Reads a listview from the stream and returns a reference to the stream. 152 * Reads a listview from the stream and returns a reference to the stream.
159 */ 153 */
@@ -192,24 +186,30 @@ class OListViewItem: public QListViewItem
192 QString, QString = QString::null, 186 QString, QString = QString::null,
193 QString = QString::null, QString = QString::null, 187 QString = QString::null, QString = QString::null,
194 QString = QString::null, QString = QString::null, 188 QString = QString::null, QString = QString::null,
195 QString = QString::null, QString = QString::null ); 189 QString = QString::null, QString = QString::null );
196 190
197 virtual ~OListViewItem(); 191 virtual ~OListViewItem();
198 192
199 const QColor& backgroundColor(); 193 const QColor& backgroundColor();
200 bool isAlternate(); 194 bool isAlternate();
201 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 195 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
202 void init(); 196 void init();
203 197
198 /**
199 * create a list view item as child of this object
200 * @return the new object
201 */
202 virtual OListViewItem* childFactory();
203
204 #ifndef QT_NO_DATASTREAM 204 #ifndef QT_NO_DATASTREAM
205 /** 205 /**
206 * serialize this object to or from a @ref QDataStream 206 * serialize this object to or from a @ref QDataStream
207 * @param s the stream used to serialize this object. 207 * @param s the stream used to serialize this object.
208 */ 208 */
209 virtual void serializeTo( QDataStream& s ) const; 209 virtual void serializeTo( QDataStream& s ) const;
210 210
211 /** 211 /**
212 * serialize this object to or from a @ref QDataStream 212 * serialize this object to or from a @ref QDataStream
213 * @param s the stream used to serialize this object. 213 * @param s the stream used to serialize this object.
214 */ 214 */
215 virtual void serializeFrom( QDataStream& s ); 215 virtual void serializeFrom( QDataStream& s );
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index 58a04fb..be1245e 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -44,24 +44,29 @@ MScanListView::MScanListView( QWidget* parent, const char* name )
44 addColumn( tr( "First Seen" ) ); 44 addColumn( tr( "First Seen" ) );
45 setColumnAlignment( 7, AlignCenter ); 45 setColumnAlignment( 7, AlignCenter );
46 addColumn( tr( "Last Seen" ) ); 46 addColumn( tr( "Last Seen" ) );
47 setColumnAlignment( 8, AlignCenter ); 47 setColumnAlignment( 8, AlignCenter );
48 setRootIsDecorated( true ); 48 setRootIsDecorated( true );
49 setAllColumnsShowFocus( true ); 49 setAllColumnsShowFocus( true );
50}; 50};
51 51
52MScanListView::~MScanListView() 52MScanListView::~MScanListView()
53{ 53{
54}; 54};
55 55
56OListViewItem* MScanListView::childFactory()
57{
58 return new MScanListItem( this );
59}
60
56void MScanListView::serializeTo( QDataStream& s) const 61void MScanListView::serializeTo( QDataStream& s) const
57{ 62{
58 qDebug( "serializing MScanListView" ); 63 qDebug( "serializing MScanListView" );
59 OListView::serializeTo( s ); 64 OListView::serializeTo( s );
60} 65}
61 66
62void MScanListView::serializeFrom( QDataStream& s) 67void MScanListView::serializeFrom( QDataStream& s)
63{ 68{
64 qDebug( "serializing MScanListView" ); 69 qDebug( "serializing MScanListView" );
65 OListView::serializeFrom( s ); 70 OListView::serializeFrom( s );
66} 71}
67 72
@@ -189,32 +194,52 @@ MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QS
189 qDebug( "creating scanlist item" ); 194 qDebug( "creating scanlist item" );
190 decorateItem( type, essid, macaddr, wep, channel, signal ); 195 decorateItem( type, essid, macaddr, wep, channel, signal );
191} 196}
192 197
193MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, 198MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr,
194 bool wep, int channel, int signal ) 199 bool wep, int channel, int signal )
195 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) 200 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
196{ 201{
197 qDebug( "creating scanlist item" ); 202 qDebug( "creating scanlist item" );
198 decorateItem( type, essid, macaddr, wep, channel, signal ); 203 decorateItem( type, essid, macaddr, wep, channel, signal );
199} 204}
200 205
206OListViewItem* MScanListItem::childFactory()
207{
208 return new MScanListItem( this );
209}
210
201void MScanListItem::serializeTo( QDataStream& s ) const 211void MScanListItem::serializeTo( QDataStream& s ) const
202{ 212{
213 qDebug( "serializing MScanListItem" );
203 OListViewItem::serializeTo( s ); 214 OListViewItem::serializeTo( s );
215
216 s << _type;
217 s << (Q_UINT8) _wep;
204} 218}
205 219
206void MScanListItem::serializeFrom( QDataStream& s ) 220void MScanListItem::serializeFrom( QDataStream& s )
207{ 221{
222 qDebug( "serializing MScanListItem" );
208 OListViewItem::serializeFrom( s ); 223 OListViewItem::serializeFrom( s );
224
225 s >> _type;
226 s >> (Q_UINT8) _wep;
227
228 QString name;
229 name.sprintf( "wellenreiter/%s", (const char*) _type );
230 setPixmap( col_type, Resource::loadPixmap( name ) );
231 if ( _wep )
232 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
233 listView()->triggerUpdate();
209} 234}
210 235
211void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 236void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
212{ 237{
213 qDebug( "decorating scanlist item %s / %s / %s [%d]", 238 qDebug( "decorating scanlist item %s / %s / %s [%d]",
214 (const char*) type, 239 (const char*) type,
215 (const char*) essid, 240 (const char*) essid,
216 (const char*) macaddr, 241 (const char*) macaddr,
217 channel ); 242 channel );
218 243
219 // set icon for managed or adhoc mode 244 // set icon for managed or adhoc mode
220 QString name; 245 QString name;
diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h
index 66c701b..222217c 100644
--- a/noncore/net/wellenreiter/gui/scanlist.h
+++ b/noncore/net/wellenreiter/gui/scanlist.h
@@ -24,77 +24,79 @@ class QString;
24class ManufacturerDB; 24class ManufacturerDB;
25 25
26class MScanListView: public OListView 26class MScanListView: public OListView
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30 public: 30 public:
31 MScanListView( QWidget* parent = 0, const char* name = 0 ); 31 MScanListView( QWidget* parent = 0, const char* name = 0 );
32 virtual ~MScanListView(); 32 virtual ~MScanListView();
33 33
34 void setManufacturerDB( ManufacturerDB* manufacturerdb ); 34 void setManufacturerDB( ManufacturerDB* manufacturerdb );
35 35
36 virtual OListViewItem* childFactory();
36 virtual void serializeTo( QDataStream& s ) const; 37 virtual void serializeTo( QDataStream& s ) const;
37 virtual void serializeFrom( QDataStream& s ); 38 virtual void serializeFrom( QDataStream& s );
38 39
39 public slots: 40 public slots:
40 void addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); 41 void addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
41 42
42 private: 43 private:
43 ManufacturerDB* _manufacturerdb; 44 ManufacturerDB* _manufacturerdb;
44 45
45}; 46};
46 47
47//****************************** MScanListItem **************************************************************** 48//****************************** MScanListItem ****************************************************************
48 49
49class MScanListItem: public OListViewItem 50class MScanListItem: public OListViewItem
50{ 51{
51 public: 52 public:
52 MScanListItem::MScanListItem( QListView* parent, 53 MScanListItem::MScanListItem( QListView* parent,
53 QString type, 54 QString type = "unknown",
54 QString essid, 55 QString essid = "unknown",
55 QString macaddr, 56 QString macaddr = "unknown",
56 bool wep, 57 bool wep = false,
57 int channel, 58 int channel = 0,
58 int signal ); 59 int signal = 0 );
59 60
60 MScanListItem::MScanListItem( QListViewItem* parent, 61 MScanListItem::MScanListItem( QListViewItem* parent,
61 QString type, 62 QString type = "unknown",
62 QString essid, 63 QString essid = "unknown",
63 QString macaddr, 64 QString macaddr = "unknown",
64 bool wep, 65 bool wep = false,
65 int channel, 66 int channel = 0,
66 int signal ); 67 int signal = 0 );
67 68
68 69
69 protected: 70 protected:
70 virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); 71 virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
71 72
72 public: 73 public:
73 QString type; 74 QString type;
74 75
75 public: 76 public:
76 //const QString& type() { return _type; }; 77 //const QString& type() { return _type; };
77 const QString& essid() { return _essid; }; 78 const QString& essid() { return _essid; };
78 const QString& macaddr() { return _macaddr; }; 79 const QString& macaddr() { return _macaddr; };
79 bool wep() { return _wep; }; 80 bool wep() { return _wep; };
80 int channel() { return _channel; }; 81 int channel() { return _channel; };
81 int signal() { return _signal; }; 82 int signal() { return _signal; };
82 int beacons() { return _beacons; }; 83 int beacons() { return _beacons; };
83 84
84 void setSignal( int signal ) { /* TODO */ }; 85 void setSignal( int signal ) { /* TODO */ };
85 void receivedBeacon(); 86 void receivedBeacon();
86 87
87 void setManufacturer( const QString& manufacturer ); 88 void setManufacturer( const QString& manufacturer );
88 89
90 virtual OListViewItem* childFactory();
89 virtual void serializeTo( QDataStream& s ) const; 91 virtual void serializeTo( QDataStream& s ) const;
90 virtual void serializeFrom( QDataStream& s ); 92 virtual void serializeFrom( QDataStream& s );
91 93
92 private: 94 private:
93 QString _type; 95 QString _type;
94 QString _essid; 96 QString _essid;
95 QString _macaddr; 97 QString _macaddr;
96 bool _wep; 98 bool _wep;
97 int _channel; 99 int _channel;
98 int _signal; 100 int _signal;
99 int _beacons; 101 int _beacons;
100 102