123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include "DialogTaskPou.h"
- #include "PouManager.h"
- // 根节点的名称
- #define ROOT_NAME "ALL_POUS"
- DialogTaskPou::DialogTaskPou(QWidget *parent)
- : QDialog(parent)
- {
- ui.setupUi(this);
- // 对话框界面初始化
- init();
- // 添加所有的Pou到树形结构中
- this->AddPousToTree();
- }
- DialogTaskPou::~DialogTaskPou()
- {
- }
- /// <summary>
- /// 对话框初始化
- /// </summary>
- void DialogTaskPou::init()
- {
- // 设置对话框标题
- this->setWindowTitle(("POU Selection ( Multi Selection )"));
- this->setAttribute(Qt::WA_QuitOnClose);
- this->setWindowModality(Qt::ApplicationModal);
- // Tree
- // 1列
- ui.treePou->setColumnCount(1);
- // 隐藏表头
- ui.treePou->setHeaderHidden(true);
- // 显示虚线
- ui.treePou->setStyle(QStyleFactory::create("windows"));
- // 多选
- ui.treePou->setSelectionMode(QAbstractItemView::MultiSelection);
- // 槽函数
- connect(ui.selectButton, SIGNAL(clicked()), this, SLOT(onButtonSelectClicked()));
- connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
- // 设置固定窗体大小
- this->setFixedSize(463, 460);
- //this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
- }
- /// <summary>
- /// 添加所有的Pou到树形结构中
- /// </summary>
- void DialogTaskPou::AddPousToTree()
- {
- // 首先添加一个父节点
- QTreeWidgetItem* rootItem = new QTreeWidgetItem(QStringList(ROOT_NAME));
- rootItem->setIcon(0, QIcon(":/image/tool_tree_item.png"));
- // 使父节点不可选中
- rootItem->setFlags(Qt::ItemIsEnabled);
- ui.treePou->addTopLevelItem(rootItem);
- // 循环添加所有的Pou
- // 从公共区域获取全部变量
- const QMap<QString, POU*>& allPous = g_pPouManager->getAllPous();
- // 遍历所有的Pou信息
- QMapIterator<QString, POU*> it(allPous);
- while (it.hasNext())
- {
- // 以Pou分组名称为节点添加
- QString strPouGroupName = it.next().key();
- // 需要跳过Hardware以及功能块类型的Pou
- if (strPouGroupName == GROUP_NAME_HARDWARE)
- {
- continue;
- }
- POU* pPou = it.value();
- // 加上工具数量
- int nToolCount = pPou->GetStandardToolsCount();
- strPouGroupName += " (" + QString::number(nToolCount) + " tools)";
- QTreeWidgetItem* pouItem = new QTreeWidgetItem(rootItem, QStringList(strPouGroupName));
- pouItem->setIcon(0, QIcon(":/image/tree_item.png"));
- rootItem->addChild(pouItem);
- // 将新加入的item和对应的Interface绑定
- m_ItemPous.insert(pouItem, it.value());
- }
- // 展开树状节点
- ui.treePou->expandAll();
- }
- /// <summary>
- /// select按钮
- /// </summary>
- void DialogTaskPou::onButtonSelectClicked()
- {
- // 清空当前选择
- m_selPous.clear();
- // 获取选择项(多选)
- QList<QTreeWidgetItem*> selectedItemList = ui.treePou->selectedItems();
- // 如果选择的数量为0,则提示重新选择
- if (selectedItemList.size() <= 0)
- {
- Utility::VPCriticalMessageBox("Please select a valid pou.");
-
- return;
- }
- // 找到对应的数据结构项
- for (QTreeWidgetItem * pSelItem : selectedItemList)
- {
- if (m_ItemPous.contains(pSelItem))
- {
- m_selPous.push_back(m_ItemPous[pSelItem]);
- }
- }
- this->accept();
- }
|