summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-03-02 17:35:53 (UTC)
committer mickeyl <mickeyl>2003-03-02 17:35:53 (UTC)
commitb3b0d6ec136e550029b9cae7fb714d47071ea5b4 (patch) (side-by-side diff)
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
@@ -120,12 +120,17 @@ const QPen& OListView::columnSeparator() const
void OListView::setColumnSeparator( const QPen& p )
{
m_columnSeparator = p;
repaint();
}
+OListViewItem* OListView::childFactory()
+{
+ return new OListViewItem( this );
+}
+
#ifndef QT_NO_DATASTREAM
void OListView::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
qDebug( "storing OListView..." );
@@ -177,13 +182,13 @@ void OListView::serializeFrom( QDataStream& s )
int items;
s >> items;
qDebug( "read number of items = %d", items );
for ( int i = 0; i < items; ++i )
{
- OListViewItem* item = new OListViewItem( this );
+ OListViewItem* item = childFactory();
s >> *item;
}
qDebug( "OListView loaded." );
}
@@ -334,12 +339,17 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
+OListViewItem* OListViewItem::childFactory()
+{
+ return new OListViewItem( this );
+}
+
#ifndef QT_NO_DATASTREAM
void OListViewItem::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
qDebug( "storing OListViewItem..." );
@@ -385,13 +395,13 @@ void OListViewItem::serializeFrom( QDataStream& s )
int items;
s >> items;
qDebug( "read number of items = %d", items );
for ( int i = 0; i < items; ++i )
{
- OListViewItem* item = new OListViewItem( this );
+ OListViewItem* item = childFactory();
s >> (*item);
}
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
@@ -35,13 +35,13 @@
#include <qcolor.h>
#include <qlistview.h>
#include <qpen.h>
#include <qdatastream.h>
-class OListViewFactory;
+class OListViewItem;
/**
* A @ref QListView variant featuring visual and functional enhancements
* like an alternate background for odd rows, an autostretch mode
* for the width of the widget ( >= Qt 3 only ) and persistence capabilities.
*
@@ -112,12 +112,18 @@ class OListViewFactory;
/**
* @return the column separator pen
*/
const QPen& columnSeparator() const;
+ /**
+ * create a list view item as child of this object
+ * @return the new object
+ */
+ virtual OListViewItem* childFactory();
+
#ifndef QT_NO_DATASTREAM
/**
* serialize this object to a @ref QDataStream
* @param s the stream used to serialize this object.
*/
virtual void serializeTo( QDataStream& s ) const;
@@ -126,28 +132,16 @@ class OListViewFactory;
* serialize this object from a @ref QDataStream
* @param s the stream used to serialize this object.
*/
virtual void serializeFrom( QDataStream& s );
#endif
- /**
- * returns a factory for OListView classes
- * creates one on the fly if it doesn't exist
- * @return the XML Factory
- */
- #ifndef QT_NO_XML
- //OListViewFactory* Factory();
- #endif
-
private:
QColor m_alternateBackground;
bool m_fullWidth;
QPen m_columnSeparator;
- #ifndef QT_NO_XML
- //OListViewFactory* m_Factory;
- #endif
};
#ifndef QT_NO_DATASTREAM
/**
* \relates QListView
* Writes a listview to the stream and returns a reference to the stream.
@@ -198,12 +192,18 @@ class OListViewItem: public QListViewItem
const QColor& backgroundColor();
bool isAlternate();
void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
void init();
+ /**
+ * create a list view item as child of this object
+ * @return the new object
+ */
+ virtual OListViewItem* childFactory();
+
#ifndef QT_NO_DATASTREAM
/**
* serialize this object to or from a @ref QDataStream
* @param s the stream used to serialize this object.
*/
virtual void serializeTo( QDataStream& s ) const;
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
@@ -50,12 +50,17 @@ MScanListView::MScanListView( QWidget* parent, const char* name )
};
MScanListView::~MScanListView()
{
};
+OListViewItem* MScanListView::childFactory()
+{
+ return new MScanListItem( this );
+}
+
void MScanListView::serializeTo( QDataStream& s) const
{
qDebug( "serializing MScanListView" );
OListView::serializeTo( s );
}
@@ -195,20 +200,40 @@ MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid
:OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
{
qDebug( "creating scanlist item" );
decorateItem( type, essid, macaddr, wep, channel, signal );
}
+OListViewItem* MScanListItem::childFactory()
+{
+ return new MScanListItem( this );
+}
+
void MScanListItem::serializeTo( QDataStream& s ) const
{
+ qDebug( "serializing MScanListItem" );
OListViewItem::serializeTo( s );
+
+ s << _type;
+ s << (Q_UINT8) _wep;
}
void MScanListItem::serializeFrom( QDataStream& s )
{
+ qDebug( "serializing MScanListItem" );
OListViewItem::serializeFrom( s );
+
+ s >> _type;
+ s >> (Q_UINT8) _wep;
+
+ QString name;
+ name.sprintf( "wellenreiter/%s", (const char*) _type );
+ setPixmap( col_type, Resource::loadPixmap( name ) );
+ if ( _wep )
+ setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
+ listView()->triggerUpdate();
}
void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
{
qDebug( "decorating scanlist item %s / %s / %s [%d]",
(const char*) type,
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
@@ -30,12 +30,13 @@ class MScanListView: public OListView
public:
MScanListView( QWidget* parent = 0, const char* name = 0 );
virtual ~MScanListView();
void setManufacturerDB( ManufacturerDB* manufacturerdb );
+ virtual OListViewItem* childFactory();
virtual void serializeTo( QDataStream& s ) const;
virtual void serializeFrom( QDataStream& s );
public slots:
void addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
@@ -47,26 +48,26 @@ class MScanListView: public OListView
//****************************** MScanListItem ****************************************************************
class MScanListItem: public OListViewItem
{
public:
MScanListItem::MScanListItem( QListView* parent,
- QString type,
- QString essid,
- QString macaddr,
- bool wep,
- int channel,
- int signal );
+ QString type = "unknown",
+ QString essid = "unknown",
+ QString macaddr = "unknown",
+ bool wep = false,
+ int channel = 0,
+ int signal = 0 );
MScanListItem::MScanListItem( QListViewItem* parent,
- QString type,
- QString essid,
- QString macaddr,
- bool wep,
- int channel,
- int signal );
+ QString type = "unknown",
+ QString essid = "unknown",
+ QString macaddr = "unknown",
+ bool wep = false,
+ int channel = 0,
+ int signal = 0 );
protected:
virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
public:
@@ -83,12 +84,13 @@ class MScanListItem: public OListViewItem
void setSignal( int signal ) { /* TODO */ };
void receivedBeacon();
void setManufacturer( const QString& manufacturer );
+ virtual OListViewItem* childFactory();
virtual void serializeTo( QDataStream& s ) const;
virtual void serializeFrom( QDataStream& s );
private:
QString _type;
QString _essid;