1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

update qqt dict

This commit is contained in:
tianduanrui 2017-11-25 10:58:30 +08:00
parent 64da436354
commit d58c928b26
5 changed files with 223 additions and 260 deletions

View File

@ -1,8 +1,7 @@
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG += ordered CONFIG += ordered
SUBDIRS = src/qqt.pro \ SUBDIRS = src/qqt.pro
test/qqtdicttest
##----------------------------------------------------------------- ##-----------------------------------------------------------------
##basic example ##basic example
@ -81,3 +80,4 @@ greaterThan(QT_MAJOR_VERSION, 4):SUBDIRS += examples/qqthttpdownload
#SUBDIRS += test/svgtest #SUBDIRS += test/svgtest
#SUBDIRS += test/framelesshelperwidget #SUBDIRS += test/framelesshelperwidget
#SUBDIRS += test/treeviewtest #SUBDIRS += test/treeviewtest
#SUBDIRS += test/qqtdicttest

View File

@ -8,6 +8,7 @@
#include "qqtqtiowebpageparser.h" #include "qqtqtiowebpageparser.h"
#include "qqtdictionary.h" #include "qqtdictionary.h"
#define plinen() pline() << "\n"
int main ( int argc, char* argv[] ) int main ( int argc, char* argv[] )
{ {
QQtApplication a ( argc, argv ); QQtApplication a ( argc, argv );
@ -29,27 +30,27 @@ int main ( int argc, char* argv[] )
//MainWindow w; //MainWindow w;
//w.show(); //w.show();
QQtDict d0; QQtDictNode d0;
d0["cc"] = "dd"; d0["cc"] = "dd";
qDebug() << d0["cc"].getValue(); qDebug() << d0["cc"].getValue();
QQtDict d1; QQtDictNode d1;
QQtDict d2 ( QVariant ( "CCCC" ) ); QQtDictNode d2 ( QVariant ( "CCCC" ) );
d1.appendValue ( d2 ); d1.appendChild ( d2 );
qDebug() << d1[0].getValue(); qDebug() << d1[0].getValue();
d1[0] = "ff"; d1[0] = "ff";
qDebug() << d1[0].getValue(); qDebug() << d1[0].getValue();
QQtDict d3; QQtDictNode d3;
d3["cc"]["dd"] = "ee"; d3["cc"]["dd"] = "ee";
qDebug() << d3["cc"]["dd"].getValue().toString(); qDebug() << d3["cc"]["dd"].getValue().toString();
QQtDict d4; QQtDictNode d4;
for ( int i = 0; i < 5; i++ ) for ( int i = 0; i < 5; i++ )
{ {
QQtDict d ( QVariant ( QString::number ( i ) ) ); QQtDictNode d ( QVariant ( QString::number ( i ) ) );
d4.appendValue ( d ); d4.appendChild ( d );
} }
qDebug() << d4.count(); qDebug() << d4.count();
@ -59,20 +60,55 @@ int main ( int argc, char* argv[] )
qDebug() << d4[i].getValue().toString(); qDebug() << d4[i].getValue().toString();
} }
QQtDict d5; QQtDictNode d5;
/*后续有map操作这一步就没有用了*/
d5.appendChild ( "5.7" ); d5.appendChild ( "5.7" );
d5.appendChild ( "5.8" ); d5.appendChild ( "5.8" );
d5.appendChild ( "5.9" ); d5.appendChild ( "5.9" );
/*后续有map操作这一步就没有用了*/
d5["5.7"].appendChild ( "5.7.2" ); d5["5.7"].appendChild ( "5.7.2" );
d5["5.7"].appendChild ( "5.7.3" ); d5["5.7"].appendChild ( "5.7.3" );
d5["5.7"].appendChild ( "5.7.4" ); d5["5.7"].appendChild ( "5.7.4" );
d5["5.7"]["5.7.4"].appendChild ( "xxx.dmg" );
d5["5.7"]["5.7.4"]["xxx.dmg"].appendValue ( "xxx.dmg" );
d5["5.7"]["5.7.4"]["xxx.dmg"].appendValue ( "2017-12-12" );
d5["5.7"]["5.7.4"]["xxx.dmg"].appendValue ( "1.2G" );
d5["5.7"]["5.7.4"]["xxx.dmg"].appendValue ( "Detail" );
pline() << "\n" << d5["5.7"]["5.7.4"]; d5["5.7"]["5.7.4"].appendChild ( "xxx.dmg" );
d5["5.7"]["5.7.4"][0].appendChild ( "xxx.dmg" );
d5["5.7"]["5.7.4"][0].appendChild ( "2017-12-12" );
d5["5.7"]["5.7.4"][0].appendChild ( "1.2G" );
d5["5.7"]["5.7.4"][0].appendChild ( "Detail" );
d5["5.7"]["5.7.4"][0].insertChild ( 4, "Detail2" );
//pline() << "\n" << d5;
pline() << "\n" << d5["5.7"];
QQtMapNodeIterator itor ( d5["5.7"].getMap() );
while ( itor.hasNext() )
{
itor.next();
pline() << "\n" << itor.key() << itor.value();
}
pline () << d5["5.7"]["5.7.4"][0].getType();
pline () << d5["5.7"]["5.7.4"][0].count();
for ( int i = 0; i < d5["5.7"]["5.7.4"][0].count(); i++ )
{
plinen() << d5["5.7"]["5.7.4"][0][i].getValue().toString();
}
QQtDictNode node = d5;
plinen() << node["5.7"]["5.7.4"][0][0].getValue().toString();
/*在这里有list操作前边"5.7"的map就没有用了*/
/*但是再过去做过的list类型的操作都会被保留也就是说中间出现过概念错误没问题还保留着*/
d5["5.7"].appendChild ( "5.7.5" );
for ( int i = 0; i < d5["5.7"].count(); i++ )
{
pline() << d5["5.7"][i].getValue().toString();
}
return 0;//a.exec(); return 0;//a.exec();
} }

View File

@ -1,12 +1,12 @@
#include "qqtdictionary.h" #include "qqtdictionary.h"
QQtDict::QQtDict ( QObject* parent ) : QQtDictNode::QQtDictNode ( QObject* parent ) :
QObject ( parent ) QObject ( parent )
{ {
m_type = DictMax; m_type = DictMax;
} }
bool QQtDict::isValue() const bool QQtDictNode::isValue() const
{ {
bool is = false; bool is = false;
@ -16,89 +16,68 @@ bool QQtDict::isValue() const
return is; return is;
} }
QQtDict::EDictType QQtDict::getType() const QQtDictNode::EDictType QQtDictNode::getType() const
{ {
return m_type; return m_type;
} }
void QQtDict::setType ( QQtDict::EDictType type ) void QQtDictNode::setType ( QQtDictNode::EDictType type )
{ {
m_type = type; m_type = type;
} }
void QQtDict::setValue ( QVariant& value ) void QQtDictNode::setChild ( const QVariant& value )
{ {
m_type = DictValue; m_type = DictValue;
m_value = value; m_value = value;
} }
void QQtDict::setValue ( QList<QQtDict>& list ) void QQtDictNode::setChild ( const QList<QQtDictNode>& list )
{ {
m_type = DictList; m_type = DictList;
m_list = list; m_list = list;
} }
void QQtDict::setValue ( QMap<QString, QQtDict>& map ) void QQtDictNode::setChild ( const QMap<QString, QQtDictNode>& map )
{ {
m_type = DictMap; m_type = DictMap;
m_map = map; m_map = map;
} }
void QQtDict::setChild ( QList<QQtDict>& list ) void QQtDictNode::appendChild ( const QString& value )
{ {
setValue ( list ); appendChild ( QQtDictNode ( QVariant ( value ) ) );
} }
void QQtDict::setChild ( QMap<QString, QQtDict>& map ) void QQtDictNode::appendChild ( const QQtDictNode& dict )
{
setValue ( map );
}
void QQtDict::appendValue ( const QString& value )
{
m_type = DictList;
m_list.push_back ( QQtDict ( QVariant ( value ) ) );
}
void QQtDict::appendValue ( const QQtDict& dict )
{ {
m_type = DictList; m_type = DictList;
m_list.append ( dict ); m_list.append ( dict );
} }
void QQtDict::appendChild ( const QQtDict& dict ) void QQtDictNode::insertChild ( const QString& key, const QQtDictNode& dict )
{
appendValue ( dict );
}
void QQtDict::insertValue ( const QString& key, QQtDict& dict )
{ {
m_type = DictMap; m_type = DictMap;
m_map.insert ( key, dict ); m_map.insert ( key, dict );
} }
void QQtDict::insertChild ( const QString& key, QQtDict& dict ) void QQtDictNode::insertChild ( int index, const QString& value )
{ {
insertValue ( key, dict ); insertChild ( index, QQtDictNode ( QVariant ( value ) ) );
} }
void QQtDict::insertValue ( int index, QQtDict& dict ) void QQtDictNode::insertChild ( int index, const QQtDictNode& dict )
{ {
m_type = DictList; m_type = DictList;
m_list.insert ( index, dict ); m_list.insert ( index, dict );
} }
void QQtDict::appendChild ( const QString& value ) void QQtDictNode::insertChild ( const QString& key, const QString& value )
{ {
appendValue ( value ); insertChild ( key, QQtDictNode ( QVariant ( value ) ) );
} }
void QQtDict::insertChild ( int index, QQtDict& dict ) int QQtDictNode::count() const
{
insertValue ( index, dict );
}
int QQtDict::count() const
{ {
int cnt = -1; int cnt = -1;
@ -112,7 +91,7 @@ int QQtDict::count() const
return cnt; return cnt;
} }
bool QQtDict::isNull() const bool QQtDictNode::isNull() const
{ {
if ( m_type == DictMax ) if ( m_type == DictMax )
return true; return true;
@ -120,11 +99,11 @@ bool QQtDict::isNull() const
return false; return false;
} }
bool QQtDict::isValid() const bool QQtDictNode::isValid() const
{ {
return isNull(); return isNull();
} }
bool QQtDict::isEmpty() const bool QQtDictNode::isEmpty() const
{ {
bool isEmpty = true; bool isEmpty = true;
@ -156,179 +135,137 @@ bool QQtDict::isEmpty() const
} }
bool QQtDict::isList() const bool QQtDictNode::isList() const
{ {
bool is = false; bool is = false;
if ( !m_type == DictList )
is = true;
return is;
}
bool QQtDict::isMap() const
{
bool is = false;
if ( !m_type == DictMap )
is = true;
return is;
}
QString& QQtDict::getName() const
{
return ( QString& ) m_name;
}
bool QQtDict::hasKey ( const QString& key ) const
{
bool has = false;
if ( m_type == DictMap )
if ( m_map.contains ( key ) )
has = true;
return has;
}
bool QQtDict::hasKey ( const QQtDict& value ) const
{
bool has = false;
if ( m_type == DictList ) if ( m_type == DictList )
if ( m_list.contains ( value ) ) is = true;
has = true;
return is;
}
bool QQtDictNode::isMap() const
{
bool is = false;
if ( m_type == DictMap )
is = true;
return is;
}
bool QQtDictNode::hasChild ( const QString& key ) const
{
bool has = false;
if ( m_map.contains ( key ) )
has = true;
return has; return has;
} }
bool QQtDict::hasChild ( const QString& key ) const bool QQtDictNode::hasChild ( const QQtDictNode& value ) const
{ {
return hasKey ( key ); bool has = false;
if ( m_list.contains ( value ) )
has = true;
return has;
} }
bool QQtDict::hasChild ( const QQtDict& value ) const void QQtDictNode::modValue ( const QVariant& value )
{ {
return hasKey ( value ); m_type = DictValue;
m_value = value;
} }
void QQtDict::modValue ( QVariant& value ) void QQtDictNode::modChild ( int index, const QQtDictNode& value )
{ {
if ( DictValue == m_type ) m_type = DictList;
{ m_list[index] = value;
m_value = value;
}
} }
void QQtDict::modValue ( int index, QQtDict& value ) void QQtDictNode::modChild ( QString key, const QQtDictNode& value )
{ {
if ( DictList == m_type ) m_type = DictMap;
{ m_map[key] = value;
m_list[index] = value;
}
} }
void QQtDict::modValue ( QString key, QQtDict& value ) void QQtDictNode::clear()
{ {
if ( DictMap == m_type ) m_value.clear();
{ m_list.clear();
m_map[key] = value; m_map.clear();
}
} }
void QQtDict::modChild ( int index, QQtDict& value ) void QQtDictNode::remove ( int index )
{ {
modValue ( index, value ); m_list.removeAt ( index );
} }
void QQtDict::modChild ( QString key, QQtDict& value ) void QQtDictNode::remove ( const QString& key )
{ {
modValue ( key, value ); m_map.remove ( key );
} }
void QQtDict::clear() QQtDictNode::QQtDictNode ( const QQtDictNode& other, QObject* parent ) :
{
if ( DictValue == m_type )
{
m_value.clear();
}
else if ( DictList == m_type )
{
m_list.clear();
}
else if ( DictMap == m_type )
{
m_map.clear();
}
}
void QQtDict::remove ( int index )
{
if ( DictList == m_type )
{
m_list.removeAt ( index );
}
}
void QQtDict::remove ( const QString& key )
{
if ( DictMap == m_type )
{
m_map.remove ( key );
}
}
QQtDict::QQtDict ( const QQtDict& other, QObject* parent ) :
QObject ( parent ) QObject ( parent )
{ {
*this = other; *this = other;
} }
QQtDict::QQtDict ( const QString name, QQtDict::EDictType type, QObject* parent ) : QQtDictNode::QQtDictNode ( const QQtDictNode::EDictType type, QObject* parent ) :
QObject ( parent )
{
m_name = name;
m_type = type;
}
QQtDict::QQtDict ( const QQtDict::EDictType type, QObject* parent ) :
QObject ( parent ) QObject ( parent )
{ {
m_type = type; m_type = type;
} }
QQtDict::QQtDict ( const QVariant& value, QObject* parent ) : const QQtDictNode& QQtDictNode::operator[] ( const QString& key ) const
{
return m_map[key];
}
const QQtDictNode& QQtDictNode::operator[] ( int index ) const
{
return m_list[index];
}
QQtDictNode::QQtDictNode ( const QVariant& value, QObject* parent ) :
QObject ( parent ) QObject ( parent )
{ {
m_value = value; *this = value;
m_type = DictValue;
} }
QQtDict& QQtDict::operator [] ( int index ) QQtDictNode& QQtDictNode::operator [] ( int index )
{ {
return ( QQtDict& ) m_list.operator [] ( index ); m_type = DictList;
return ( QQtDictNode& ) m_list.operator [] ( index );
} }
QQtDict& QQtDict::operator [] ( QString key ) QQtDictNode& QQtDictNode::operator [] ( const QString& key )
{ {
m_type = DictMap;
return m_map.operator [] ( key ); return m_map.operator [] ( key );
} }
QQtDict& QQtDict::operator = ( const QMap<QString, QQtDict>& map ) QQtDictNode& QQtDictNode::operator = ( const QMap<QString, QQtDictNode>& map )
{ {
m_type = DictMap;
m_map = map; m_map = map;
return *this; return *this;
} }
QQtDict& QQtDict::operator = ( const QList<QQtDict>& list ) QQtDictNode& QQtDictNode::operator = ( const QList<QQtDictNode>& list )
{ {
m_type = DictList;
m_list = list; m_list = list;
return *this; return *this;
} }
QQtDict& QQtDict::operator = ( const QQtDict& other ) QQtDictNode& QQtDictNode::operator = ( const QQtDictNode& other )
{ {
EDictType type = other.getType(); EDictType type = other.getType();
@ -352,21 +289,20 @@ QQtDict& QQtDict::operator = ( const QQtDict& other )
break; break;
} }
m_name = other.getName();
m_type = type; m_type = type;
return *this; return *this;
} }
QQtDict& QQtDict::operator = ( const QVariant& value ) QQtDictNode& QQtDictNode::operator = ( const QVariant& value )
{ {
m_type = DictValue;
m_value = value; m_value = value;
return *this; return *this;
} }
bool QQtDict::operator == ( const QQtDict& other ) const bool QQtDictNode::operator == ( const QQtDictNode& other ) const
{ {
if ( m_type == other.getType() && if ( m_type == other.getType() &&
other.getName() == m_name &&
other.getList() == m_list && other.getList() == m_list &&
other.getMap() == m_map && other.getMap() == m_map &&
other.getValue() == m_value ) other.getValue() == m_value )
@ -375,51 +311,41 @@ bool QQtDict::operator == ( const QQtDict& other ) const
return false; return false;
} }
QMap<QString, QQtDict>& QQtDict::getMap() const QMap<QString, QQtDictNode>& QQtDictNode::getMap() const
{ {
return ( QMap<QString, QQtDict>& ) m_map; return ( QMap<QString, QQtDictNode>& ) m_map;
} }
QList<QQtDict>& QQtDict::getList() const QList<QQtDictNode>& QQtDictNode::getList() const
{ {
return ( QList<QQtDict>& ) m_list; return ( QList<QQtDictNode>& ) m_list;
} }
QVariant& QQtDict::getValue() const QVariant& QQtDictNode::getValue() const
{ {
return ( QVariant& ) m_value; return ( QVariant& ) m_value;
} }
QQtDict& QQtDict::getValue ( int index ) const QQtDictNode& QQtDictNode::getChild ( int index )
{
return ( QQtDict& ) m_list[index];
}
QQtDict& QQtDict::getValue ( const QString& key )
{
return m_map[key];
}
QQtDict& QQtDict::getChild ( int index )
{ {
return m_list[index]; return m_list[index];
} }
QQtDict& QQtDict::getChild ( QString key ) QQtDictNode& QQtDictNode::getChild ( const QString& key )
{ {
return m_map[key]; return m_map[key];
} }
QDebug operator<< ( QDebug dbg, const QQtDict& d )
QDebug operator<< ( QDebug dbg, const QQtDictNode& d )
{ {
dbg.nospace() << "{" << dbg.nospace() << "\n{" <<
"\n Type:" << d.getType() << " Type:" << d.getType() <<
"\n Count:" << d.count() << " Count:" << d.count() <<
"\n Name:" << d.getName() << " Value:" << d.getValue() <<
"\n Value:" << d.getValue() << " List:" << d.getList() <<
"\n List:" << d.getList() << " Map:" << d.getMap() <<
"\n Map:" << d.getMap() << "}";
"\n}";
return dbg.space(); return dbg.space();
} }

View File

@ -7,6 +7,17 @@
#include <qqtcore.h> #include <qqtcore.h>
#include <qqt-local.h> #include <qqt-local.h>
/*
* 使
*
*/
class QQtDictNode;
typedef QMap<QString, QQtDictNode> QQtMapNode;
typedef QMapIterator<QString, QQtDictNode> QQtMapNodeIterator;
typedef QList<QQtDictNode> QQtListNode;
typedef QListIterator<QQtDictNode> QQtListNodeIterator;
/** /**
* @brief The QQtDictionary class * @brief The QQtDictionary class
* QQt * QQt
@ -20,7 +31,7 @@
* QVariant 使 * QVariant 使
* 便 * 便
*/ */
class QQTSHARED_EXPORT QQtDict : public QObject class QQTSHARED_EXPORT QQtDictNode : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS ( EDictType ) Q_ENUMS ( EDictType )
@ -37,8 +48,9 @@ public:
DictMax DictMax
} EDictType; } EDictType;
explicit QQtDict ( QObject* parent = 0 ); /*explicit 函数只能作为构造函数,不能作为拷贝构造函数,拷贝构造函数不可加*/
virtual ~QQtDict() {} explicit QQtDictNode ( QObject* parent = 0 );
virtual ~QQtDictNode() {}
bool isNull() const; bool isNull() const;
bool isValid() const; bool isValid() const;
@ -48,66 +60,52 @@ public:
bool isList() const; bool isList() const;
bool isMap() const; bool isMap() const;
/*遍历字典*/
int count() const;
bool hasChild ( const QString& key ) const;
bool hasChild ( const QQtDictNode& value ) const;
/*获取数据*/ /*获取数据*/
QString& getName() const;
/*获取全部数据*/ /*获取全部数据*/
QMap<QString, QQtDict>& getMap() const; QMap<QString, QQtDictNode>& getMap() const;
QList<QQtDict>& getList() const ; QList<QQtDictNode>& getList() const ;
/*获取单个数据*/ /*获取单个数据*/
QVariant& getValue() const; QVariant& getValue() const;
QQtDict& getValue ( int index ) const; QQtDictNode& getChild ( int index );
QQtDict& getValue ( const QString& key ); QQtDictNode& getChild ( const QString& key );
/*获取一个个孩子*/ /*获取一个个孩子*/
/*list item*/
QQtDict& getChild ( int index );
/*map item*/
QQtDict& getChild ( QString key );
/*类型*/ /*类型*/
EDictType getType() const; EDictType getType() const;
/*如果设置Value的时候改变了Type将会以新的Type为准*/ /*如果设置Value的时候改变了Type将会以新的Type为准*/
void setType ( EDictType type ); void setType ( EDictType type );
/*插入数据自动设置type*/ /*插入数据自动设置type*/
/*自己本身没有孩子,是个叶子,添加值*/ /*自己本身没有孩子,是个叶子,添加值*/
void setValue ( QVariant& value ); void setChild ( const QVariant& value );
/*自己本身有孩子,添加全部孩子*/ /*自己本身有孩子,添加全部孩子*/
/*whole value list*/ /*whole value list*/
void setValue ( QList<QQtDict>& list ); void setChild ( const QList<QQtDictNode>& list );
/*whole value map*/ /*whole value map*/
void setValue ( QMap<QString, QQtDict>& map ); void setChild ( const QMap<QString, QQtDictNode>& map );
/*list*/
void setChild ( QList<QQtDict>& list );
/*map*/
void setChild ( QMap<QString, QQtDict>& map );
/*自己本身没有孩子,添加一个个的孩子*/ /*自己本身没有孩子,添加一个个的孩子*/
void appendValue ( const QString& value );
void appendValue ( const QQtDict& dict );
void appendChild ( const QString& value ); void appendChild ( const QString& value );
void appendChild ( const QQtDict& dict ); void appendChild ( const QQtDictNode& dict );
/*自己本身有孩子,添加一个个的孩子*/ /*自己本身有孩子,添加一个个的孩子*/
void insertValue ( const QString& key, QQtDict& dict ); void insertChild ( int index, const QString& value );
void insertChild ( const QString& key, QQtDict& dict ); void insertChild ( int index, const QQtDictNode& dict );
void insertValue ( int index, QQtDict& dict ); void insertChild ( const QString& key, const QString& value );
void insertChild ( int index, QQtDict& dict ); void insertChild ( const QString& key, const QQtDictNode& dict );
/*遍历字典*/
int count() const;
bool hasKey ( const QString& key ) const;
bool hasKey ( const QQtDict& value ) const;
bool hasChild ( const QString& key ) const;
bool hasChild ( const QQtDict& value ) const;
/*操作数据,改变数据*/ /*操作数据,改变数据*/
void modValue ( QVariant& value ); void modValue ( const QVariant& value );
void modValue ( int index, QQtDict& value ); void modChild ( int index, const QQtDictNode& value );
void modValue ( QString key, QQtDict& value ); void modChild ( QString key, const QQtDictNode& value );
void modChild ( int index, QQtDict& value );
void modChild ( QString key, QQtDict& value );
/*删除数据*/ /*删除数据*/
void clear ( ); void clear ( );
@ -115,21 +113,23 @@ public:
void remove ( const QString& key ); void remove ( const QString& key );
/*深拷贝*/ /*深拷贝*/
explicit QQtDict ( const QQtDict& other, QObject* parent = 0 ); QQtDictNode ( const QQtDictNode& other, QObject* parent = 0 );
explicit QQtDict ( const QVariant& value, QObject* parent = 0 ); QQtDictNode ( const QVariant& value, QObject* parent = 0 );
explicit QQtDict ( const QString name, EDictType type = DictMap, QObject* parent = 0 ); QQtDictNode ( const EDictType type, QObject* parent = 0 );
explicit QQtDict ( const EDictType type, QObject* parent = 0 );
/*操作符*/ /*操作符*/
/*警告:可读、可写*/
/*don't out of range*/ /*don't out of range*/
QQtDict& operator [] ( int index ); QQtDictNode& operator [] ( int index );
/**/ const QQtDictNode& operator[] ( int index ) const;
QQtDict& operator [] ( QString key ); QQtDictNode& operator [] ( const QString& key );
QQtDict& operator = ( const QMap<QString, QQtDict>& map ); const QQtDictNode& operator[] ( const QString& key ) const;
QQtDict& operator = ( const QList<QQtDict>& list );
QQtDict& operator = ( const QQtDict& other ); QQtDictNode& operator = ( const QMap<QString, QQtDictNode>& map );
QQtDict& operator = ( const QVariant& value ); QQtDictNode& operator = ( const QList<QQtDictNode>& list );
bool operator == ( const QQtDict& other ) const; QQtDictNode& operator = ( const QQtDictNode& other );
QQtDictNode& operator = ( const QVariant& value );
bool operator == ( const QQtDictNode& other ) const;
/*与其他数据结构兼容*/ /*与其他数据结构兼容*/
QString toXML(); QString toXML();
@ -142,21 +142,22 @@ signals:
public slots: public slots:
private: private:
/*节点类型*/ /*节点类型,指示性变量*/
EDictType m_type; EDictType m_type;
/*节点名字*/
QString m_name;
/*节点的可能内容枚举*/ /*节点的可能内容枚举*/
/*叶子:是个数据*/ /*叶子:是个数据*/
/*值保存在这里*/
QVariant m_value; QVariant m_value;
/*不是叶子列表,是个叶子列表,是个叶子列表的值*/ /*不是叶子列表,是个叶子列表,是个叶子列表的值*/
QList<QQtDict> m_list; //[index] /*列表保存在这里*//*不如仅仅使用map方便*/
QList<QQtDictNode> m_list; //[index]
/*不是叶子映射,是个子字典,是个叶子,是个叶子的值组合*/ /*不是叶子映射,是个子字典,是个叶子,是个叶子的值组合*/
QMap<QString, QQtDict> m_map; /*映射保存在这里QStirng可以升级为QVariant*/
QMap<QString, QQtDictNode> m_map;
/*是个列表和子字典,这是错误的,不可能的*/ /*是个列表和子字典,这是错误的,不可能的*/
}; };
QDebug operator<< ( QDebug dbg, const QQtDict& d ); QDebug operator<< ( QDebug dbg, const QQtDictNode& d );
#endif // QQTDICTIONARY_H #endif // QQTDICTIONARY_H

View File

@ -19,7 +19,7 @@ private Q_SLOTS:
void testCase2(); void testCase2();
private: private:
QQtDict dict; QQtDictNode dict;
}; };
QqtdicttestTest::QqtdicttestTest() QqtdicttestTest::QqtdicttestTest()