123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #include "DialogGotoSelection.h"
- #include "Pou.h"
- DialogGotoSelection::DialogGotoSelection(const POU* pou, QWidget *parent)
- : QDialog(parent)
- , m_pou(pou)
- {
- ui.setupUi(this);
- // 对话框初始化
- this->initUI();
- }
- DialogGotoSelection::~DialogGotoSelection()
- {
- }
- /// <summary>
- /// 对话框初始化
- /// </summary>
- void DialogGotoSelection::initUI()
- {
- // 设置对话框标题
- this->setWindowTitle(("Goto Tools Selection"));
- this->setAttribute(Qt::WA_QuitOnClose);
- this->setWindowModality(Qt::ApplicationModal);
- // 添加分组信息(目前就固定一个分组)
- ui.comboValueGroup->addItem(m_pou->pouName());
- ui.comboValueGroup->setCurrentIndex(0);
- this->onComboGroupChanged(0);
- // Tree
- // 1列
- ui.treeTool->setColumnCount(1);
- // 隐藏表头
- ui.treeTool->setHeaderHidden(true);
- // 显示虚线
- ui.treeTool->setStyle(QStyleFactory::create("windows"));
- // 槽函数
- connect(ui.selectButton, SIGNAL(clicked()), this, SLOT(onButtonSelectClicked()));
- connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
- connect(ui.comboValueGroup, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboGroupChanged(int)));
- // 设置固定窗体大小
- this->setFixedSize(485, 490);
- }
- /// <summary>
- /// 添加兼容的Pou工具到树形结构中
- /// </summary>
- /// <param name="pPou"></param>
- void DialogGotoSelection::AddPouToolsToTree(const POU* pPou)
- {
- // 添加根节点
- QTreeWidgetItem* pRootItem = AddRootTreeItem("Tools");
- // 添加适配的工具
- const QVector<TOOL*>& allTools = pPou->GetAllStandardTools();
- QVectorIterator<TOOL*> i(allTools);
- while (i.hasNext())
- {
- const TOOL* pTool = i.next();
- // 此处只要最标准的Tool
- if (pTool->isStandardTool())
- {
- // 添加工具到列表中
- this->AddToolTreeItem(pRootItem, pTool);
- }
- }
- // 将树形结构展开
- ui.treeTool->expandAll();
- }
- /// <summary>
- /// // 添加根节点
- /// </summary>
- /// <param name="toolName"></param>
- /// <returns></returns>
- QTreeWidgetItem* DialogGotoSelection::AddRootTreeItem(const QString& toolName)
- {
- QTreeWidgetItem* newItem = new QTreeWidgetItem(QStringList(toolName));
- newItem->setIcon(0, QIcon(":/image/tool_tree_item.png"));
- // 使父节点不可选中
- newItem->setFlags(Qt::ItemIsEnabled);
- ui.treeTool->addTopLevelItem(newItem);
- return newItem;
- }
- /// <summary>
- /// 添加Tool子节点
- /// </summary>
- /// <param name="pToolItem"></param>
- /// <param name="pTool"></param>
- void DialogGotoSelection::AddToolTreeItem(QTreeWidgetItem* pRootItem, const TOOL* pTool)
- {
- QTreeWidgetItem* newItem = new QTreeWidgetItem(pRootItem, QStringList(pTool->strInstanceName));
- newItem->setIcon(0, QIcon(":/image/Input.png"));
- pRootItem->addChild(newItem);
- }
- /// <summary>
- /// select按钮
- /// </summary>
- void DialogGotoSelection::onButtonSelectClicked()
- {
- // 获取用户选择的节点
- QList<QTreeWidgetItem*> selItems = ui.treeTool->selectedItems();
- if (selItems.size() <= 0)
- {
- // 如果选择的节点无效,则不允许关闭
- Utility::VPCriticalMessageBox(" The tool selected is invalid!");
- return;
- }
- // 获取用户选择的Tool
- m_selToolInstName = selItems[0]->text(0);
- this->accept();
- }
- /// <summary>
- /// Combo框选择变更时,需要切换对应的工具列表(当前仅一个分组)
- /// </summary>
- /// <param name="nIndex"></param>
- void DialogGotoSelection::onComboGroupChanged(int nIndex)
- {
- Q_UNUSED(nIndex);
- // 先将当前的树形控件清空
- ui.treeTool->clear();
- // 重新添加节点和数据结构
- AddPouToolsToTree(m_pou);
- }
|