author | mickeyl <mickeyl> | 2003-03-02 17:35:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-02 17:35:53 (UTC) |
commit | b3b0d6ec136e550029b9cae7fb714d47071ea5b4 (patch) (unidiff) | |
tree | 9cc1fb741bb548c90915487572c49a1ae48e33eb | |
parent | d0e64d0c7961de1c3ecb886ae76c6701f268d767 (diff) | |
download | opie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.zip opie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.tar.gz opie-b3b0d6ec136e550029b9cae7fb714d47071ea5b4.tar.bz2 |
add child item factory to allow subclasses adding custom data items
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.cpp | 14 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.h | 26 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 33 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 26 |
4 files changed, 68 insertions, 31 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 | |||
@@ -122,8 +122,13 @@ void OListView::setColumnSeparator( const QPen& p ) | |||
122 | m_columnSeparator = p; | 122 | m_columnSeparator = p; |
123 | repaint(); | 123 | repaint(); |
124 | } | 124 | } |
125 | 125 | ||
126 | OListViewItem* OListView::childFactory() | ||
127 | { | ||
128 | return new OListViewItem( this ); | ||
129 | } | ||
130 | |||
126 | #ifndef QT_NO_DATASTREAM | 131 | #ifndef QT_NO_DATASTREAM |
127 | void OListView::serializeTo( QDataStream& s ) const | 132 | void 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... |
@@ -179,9 +184,9 @@ void OListView::serializeFrom( QDataStream& s ) | |||
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." ); |
@@ -336,8 +341,13 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in | |||
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 | ||
345 | OListViewItem* OListViewItem::childFactory() | ||
346 | { | ||
347 | return new OListViewItem( this ); | ||
348 | } | ||
349 | |||
340 | #ifndef QT_NO_DATASTREAM | 350 | #ifndef QT_NO_DATASTREAM |
341 | void OListViewItem::serializeTo( QDataStream& s ) const | 351 | void 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... |
@@ -387,9 +397,9 @@ void OListViewItem::serializeFrom( QDataStream& s ) | |||
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." ); |
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 | |||
@@ -37,9 +37,9 @@ | |||
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 | ||
41 | class OListViewFactory; | 41 | class 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 |
@@ -114,8 +114,14 @@ class OListViewFactory; | |||
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. |
@@ -128,24 +134,12 @@ class OListViewFactory; | |||
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 | /** |
@@ -200,8 +194,14 @@ class OListViewItem: public QListViewItem | |||
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. |
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 | |||
@@ -52,8 +52,13 @@ MScanListView::MScanListView( QWidget* parent, const char* name ) | |||
52 | MScanListView::~MScanListView() | 52 | MScanListView::~MScanListView() |
53 | { | 53 | { |
54 | }; | 54 | }; |
55 | 55 | ||
56 | OListViewItem* MScanListView::childFactory() | ||
57 | { | ||
58 | return new MScanListItem( this ); | ||
59 | } | ||
60 | |||
56 | void MScanListView::serializeTo( QDataStream& s) const | 61 | void MScanListView::serializeTo( QDataStream& s) const |
57 | { | 62 | { |
58 | qDebug( "serializing MScanListView" ); | 63 | qDebug( "serializing MScanListView" ); |
59 | OListView::serializeTo( s ); | 64 | OListView::serializeTo( s ); |
@@ -95,9 +100,9 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo | |||
95 | { | 100 | { |
96 | // animate the item | 101 | // animate the item |
97 | 102 | ||
98 | /* | 103 | /* |
99 | 104 | ||
100 | const QPixmap* pixmap = item->pixmap( 0 ); | 105 | const QPixmap* pixmap = item->pixmap( 0 ); |
101 | const QPixmap* nextpixmap = ani2; | 106 | const QPixmap* nextpixmap = ani2; |
102 | if ( pixmap == ani1 ) | 107 | if ( pixmap == ani1 ) |
103 | nextpixmap = ani2; | 108 | nextpixmap = ani2; |
@@ -111,14 +116,14 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo | |||
111 | 116 | ||
112 | //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap ); | 117 | //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap ); |
113 | 118 | ||
114 | // we have already seen this net, check all childs if MAC exists | 119 | // we have already seen this net, check all childs if MAC exists |
115 | 120 | ||
116 | network = item; | 121 | network = item; |
117 | 122 | ||
118 | item = static_cast<MScanListItem*> ( item->firstChild() ); | 123 | item = static_cast<MScanListItem*> ( item->firstChild() ); |
119 | assert( item ); // this shouldn't fail | 124 | assert( item ); // this shouldn't fail |
120 | 125 | ||
121 | while ( item && ( item->text( 2 ) != macaddr ) ) | 126 | while ( item && ( item->text( 2 ) != macaddr ) ) |
122 | { | 127 | { |
123 | qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); | 128 | qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); |
124 | item = static_cast<MScanListItem*> ( item->itemBelow() ); | 129 | item = static_cast<MScanListItem*> ( item->itemBelow() ); |
@@ -197,16 +202,36 @@ MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid | |||
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 | ||
206 | OListViewItem* MScanListItem::childFactory() | ||
207 | { | ||
208 | return new MScanListItem( this ); | ||
209 | } | ||
210 | |||
201 | void MScanListItem::serializeTo( QDataStream& s ) const | 211 | void 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 | ||
206 | void MScanListItem::serializeFrom( QDataStream& s ) | 220 | void 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 | ||
211 | void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) | 236 | void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) |
212 | { | 237 | { |
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 | |||
@@ -32,8 +32,9 @@ class MScanListView: public OListView | |||
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: |
@@ -49,22 +50,22 @@ class MScanListView: public OListView | |||
49 | class MScanListItem: public OListViewItem | 50 | class 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 ); |
@@ -85,8 +86,9 @@ class MScanListItem: public OListViewItem | |||
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: |