pans
2016-12-15 87e3ee273b2f84081ac45926be9d8e5be3166eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/***************************************************************************************
 *      Copyright 2009-2011 Hikvision Digital Technology Co., Ltd.
 *      FileName        :   treemodel.cpp
 *      Description     :   Ê÷ÐÎÏÔʾģʽ£¬ÓëtreeviewÅäºÏʹÓÃ
 *      Modification    :   ÎÞ  
 *      Version         :   V1.0.0
 *      Time            :   2009-10,11
 *      Author          :   wanggp@hikvision.com
 **************************************************************************************/
#include <QIcon>
#include <QtGui>
#include "treeitem.h"
#include "treemodel.h"
 
/************************************************************************
 *        Function            :  TreeModel
 *        Description         :  ¹¹Ô캯Êý
 *        Input               :  data parent
 *        Output              :  ÎÞ
 *        Return              :  ÎÞ
*************************************************************************/
 TreeModel::TreeModel(const QString  &data, QObject *parent)
     : QStandardItemModel(parent)
 {
     QList<QVariant> rootData;
     rootData << "DeviceTree";
     rootItem = new TreeItem(rootData);
     setupModelData(data.split(QString("\n")), rootItem);
 }
 
/************************************************************************
 *        Function            :  ~TreeModel
 *        Description         :  Îö¹¹º¯Êý
 *        Input               :  ÎÞ
 *        Output              :  ÎÞ
 *        Return              :  ÎÞ
*************************************************************************/
 TreeModel::~TreeModel()
 {
     delete rootItem;
 }
 
/************************************************************************
 *        Function            :  setupModelData
 *        Description         :  ¹¹ÔìÊ÷ÐÎÁбí
 *        Input               :  lines  É豸ºÍͨµÀÐÅÏ¢
                                  parent É豸½Úµã
 *        Output              :  ÎÞ
 *        Return              :  ÎÞ
*************************************************************************/
void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
 {
    QList<TreeItem*> parents;
    parents << parent;
    QStandardItem *parentItem = invisibleRootItem();
 
    //QStandardItem *devicetreenode = new QStandardItem(QString("HIKVISION"));
    //devicetreenode->setEditable(0);
    
    
    //add by pyd
    QStandardItem *pDeviceRootItem = new QStandardItem(QString("device tree(right click to add device)"));
    //devicetreenode->appendRow(pDeviceRootItem);
    parentItem->appendRow(pDeviceRootItem);
    pDeviceRootItem->setIcon(QIcon(":/images/tree.bmp"));
    pDeviceRootItem->setEditable(0);
 
    QList<TreeItem*> parents1;
    QString deviceBegin("<device>");
    QString deviceEnd("</device>");
    QString channelBegin("<channel>");
    QString channelEnd("</channel>");
 
    QStandardItem *pDeviceItem = NULL;
    QStandardItem *pChannelItem = NULL;
    for ( QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it )
    {   
     //É豸½Úµã
        if ((*it)==deviceBegin)
        {
            ++it;
            pDeviceItem = new QStandardItem(*it);
            pDeviceRootItem->appendRow(pDeviceItem);
            pDeviceItem->setIcon(QIcon(":/images/logout.bmp"));
            pDeviceItem->setEditable(0);
        }
 
        //ͨµÀÐÅÏ¢
        QString chn =channelBegin;
        if ((*it)==chn)
        {
            ++it;
            pChannelItem = new QStandardItem(*it);
            pDeviceItem->appendRow(pChannelItem);
            pChannelItem->setIcon(QIcon(":/images/camera.bmp"));
            pChannelItem->setEditable(0);
        }
    }
}