/
FuncHelper.cpp
69 lines (56 loc) · 1.75 KB
/
FuncHelper.cpp
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
#include "StdAfx.h"
#include "FuncHelper.h"
#include <QtXml>
CFuncHelper::CFuncHelper( QWidget* parent /*= NULL*/ )
: QDialog(parent)
{
QPushButton* pBtnRefresh = new QPushButton(this);
pBtnRefresh->setText("Ë¢ÐÂ");
m_listFuncs.setMinimumWidth(100);
QGridLayout* pLayout = new QGridLayout();
pLayout->addWidget(&m_listFuncs,0,0,10,3);
pLayout->addWidget(&m_labelFunc,0,4,10,7);
pLayout->addWidget(pBtnRefresh,11,0,2,10);
setLayout(pLayout);
connect(&m_listFuncs,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this,SLOT(onFuncsItemChanged(QListWidgetItem*,QListWidgetItem*)));
connect(pBtnRefresh,SIGNAL(clicked()),this,SLOT(onRefreshAll()));
onRefreshAll();
}
CFuncHelper::~CFuncHelper(void)
{
}
void CFuncHelper::onRefreshAll()
{
m_listFuncs.clear();
QString qsPath = qApp->applicationDirPath() + "/Funcs.xml";
QFile file(qsPath);
if(!file.open(QFile::ReadOnly))
return;
QDomDocument doc;
doc.setContent(file.readAll());
file.close();
QDomElement eleRoot = doc.firstChildElement("funcs");
if(!eleRoot.isElement())
return;
QDomElement eleFunc = eleRoot.firstChildElement("func");
while(eleFunc.isElement())
{
QDomElement eleName = eleFunc.firstChildElement("name");
QDomElement eleDesc = eleFunc.firstChildElement("desc");
if(eleName.isElement() && eleDesc.isElement())
{
QListWidgetItem* pItem = new QListWidgetItem(eleName.text());
pItem->setData(Qt::UserRole,eleDesc.text());
m_listFuncs.addItem(pItem);
}
eleFunc = eleFunc.nextSiblingElement("func");
}
}
void CFuncHelper::onFuncsItemChanged( QListWidgetItem* current, QListWidgetItem* /*previous*/ )
{
if(current)
{
m_labelFunc.setText(current->data(Qt::UserRole).toString());
}
}