File indexing completed on 2024-04-28 05:51:10

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #ifndef __kwidgetstreamer
0008 #define __kwidgetstreamer
0009 
0010 #include <QMap>
0011 #include <QStringList>
0012 
0013 class QObject;
0014 
0015 /**
0016    This class defines methods for streaming widget data.
0017 
0018    For each widget type rules are defined telling which attributes should be
0019    streamed. If you need to stream other attributes or to avoid streaming
0020    certain attributes, then this may be obtained by editing the property
0021    map, which is obtained by calling @ref propertyMap. For further control
0022    inherit from this class and override @ref toStream and @ref fromStream.
0023 
0024    The following example shows how you can avoid streaming
0025    <tt>numDigits</tt> for a QLCDNumber. The same approach applies if you
0026    want to add extra properties to be streamed.
0027    <pre>
0028    KWidgetStreamer streamer;
0029    KWidgetStreamer::PropertyMap& map = streamer.propertyMap();
0030    KWidgetStreamer::PropertyList& list = *map.find("QLCDNumber");
0031    list.remove("numDigits");
0032    </pre>
0033 **/
0034 class KWidgetStreamer
0035 {
0036 public:
0037     typedef QStringList PropertyList;
0038     typedef QMap<QString, PropertyList> PropertyMap;
0039     typedef QMap<QString, PropertyList>::ConstIterator PropertyMapIt;
0040     typedef QStringList::Iterator PropertyListIt;
0041 
0042     KWidgetStreamer();
0043     virtual ~KWidgetStreamer()
0044     {
0045     }
0046 
0047     virtual void toStream(const QObject *from, QDataStream &stream);
0048     virtual void fromStream(QDataStream &stream, QObject *to);
0049 
0050     PropertyMap &propertyMap()
0051     {
0052         return _map;
0053     }
0054 
0055 protected:
0056     void propertyToStream(const QObject *from, QDataStream &stream);
0057     void propertyFromStream(QDataStream &stream, QObject *to);
0058 
0059 private:
0060     PropertyMap _map;
0061 };
0062 
0063 #endif /* __kwidgetstreamer */