HM-SPMS/product/src/tools/model_plugin/CommonWidget/kbdselctlockparadlg.cpp

196 lines
6.6 KiB
C++
Raw Normal View History

#include "kbdselctlockparadlg.h"
#include <QListWidget>
#include "CustomWidget/kbdfindpointwidget.h"
#include "../model_common/common.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QLabel>
#include <QTimer>
#include <QRadioButton>
#include <QMessageBox>
#include "kbddbdesign.h"
KbdSelctLockParaDlg::KbdSelctLockParaDlg(QWidget *parent) : QDialog(parent)
{
QStringList strList;
strList << QString("sql@SELECT * FROM SYS_MODEL_LOCATION_INFO;%1:%2").arg(CN_LOCATION_ID).arg(CN_DESC)
<<QString("sql@SELECT * FROM SYS_MODEL_SUB_SYSTEM_INFO WHERE SUB_SYSTEM_ID not in (1,2,3);%1:%2").arg(CN_SUB_SYSTEM_ID).arg(CN_DESC)
<<QString("sql@SELECT TAG_NAME,DESCRIPTION FROM DEV_GROUP WHERE LOCATION_ID = '%1' AND SUB_SYSTEM = '%2';TAG_NAME:DESCRIPTION;root.child.id;root.child.child.id")
<<QString("sql@SELECT TAG_NAME,DESCRIPTION FROM DEV_INFO WHERE GROUP_TAG_NAME = '%1';TAG_NAME:DESCRIPTION;root.child.child.child.id")
<<QString("const@DIGITAL:%1;ANALOG:%2;MIX:%3").arg(tr("数字量出口")).arg(tr("模拟量出口")).arg(tr("枚举量出口"))
<<QString("sql@SELECT TAG_NAME,DESCRIPTION FROM %1 WHERE DEVICE='%2' AND COALESCE(IS_CONTROL,0) != 0;TAG_NAME:DESCRIPTION;root.child.child.child.child.child.id;root.child.child.child.child.id");
m_findPointWidget = new KbdFindPointWidget(strList,this);
m_rbSelect = new QRadioButton(tr("在本车站,本专业中挑选具有相同描述的测点"));
QVBoxLayout *vLayoutLeft = new QVBoxLayout;
vLayoutLeft->addWidget(m_findPointWidget);
vLayoutLeft->addWidget(m_rbSelect);
QPushButton *btRemove = new QPushButton(tr("<<删除"),this);
m_label = new QLabel("",this);
QVBoxLayout *vLayoutBt = new QVBoxLayout;
vLayoutBt->addStretch();
vLayoutBt->addWidget(btRemove);
vLayoutBt->addWidget(m_label);
vLayoutBt->addStretch();
m_list = new QListWidget(this);
m_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
QHBoxLayout *hLayout= new QHBoxLayout;
hLayout->setSpacing(0);
hLayout->addLayout(vLayoutLeft,5);
hLayout->addLayout(vLayoutBt);
hLayout->addWidget(m_list,2);
QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,this);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addLayout(hLayout);
vLayout->addWidget(box);
setLayout(vLayout);
connect(box,SIGNAL(rejected()),this,SLOT(reject()));
connect(box,SIGNAL(accepted()),this,SLOT(accept()));
connect(m_findPointWidget,SIGNAL(lastSelect(const QString &,const QString &)),
this,SLOT(onSelectPoint(const QString &,const QString &)));
connect(m_rbSelect,SIGNAL(toggled(bool)),this,SLOT(onSelectByLocationAndSubSystem()));
connect(btRemove,SIGNAL(clicked(bool)),this,SLOT(onRemove()));
connect(m_list,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(onRemove()));
resize(QSize(850,400));
}
void KbdSelctLockParaDlg::selectLocation(const QString &locationId)
{
//Q_UNUSED(locationId)
m_findPointWidget->selectItem(locationId);
}
void KbdSelctLockParaDlg::selectSubSystem(const QString &subSystem)
{
//Q_UNUSED(subSystem)
m_findPointWidget->selectItem(subSystem);
}
void KbdSelctLockParaDlg::selectGroup(const QString &group)
{
m_findPointWidget->selectItem(group);
}
void KbdSelctLockParaDlg::selectDevice(const QString &device)
{
m_findPointWidget->selectItem(device);
}
bool KbdSelctLockParaDlg::hasExistPoint(const QString &id)
{
bool find = false;
QListWidgetItem *item = NULL;
for(int i = 0; i < m_list->count(); i++)
{
item = m_list->item(i);
if(item->data(Qt::UserRole).toString() == id)
{
find = true;
break;
}
}
return find;
}
void KbdSelctLockParaDlg::onSelectPoint(const QString &id, const QString &desc)
{
if(hasExistPoint(id))
{
m_label->setText(tr("该测点\r\n已挑选"));
QTimer::singleShot(1000,this,SLOT(onClearTip()));
return;
}
QListWidgetItem *item = NULL;
item = new QListWidgetItem(desc+QString("(%1)").arg(id));
item->setData(Qt::UserRole,id);
item->setData(Qt::UserRole+1,m_findPointWidget->getSelectDataByIndex(1));//车站
item->setData(Qt::UserRole+2,m_findPointWidget->getSelectDataByIndex(2));//专业
m_list->addItem(item);
}
void KbdSelctLockParaDlg::onClearTip()
{
m_label->setText("");
}
void KbdSelctLockParaDlg::onSelectByLocationAndSubSystem()
{
QString locationId = m_findPointWidget->getSelectDataByIndex(1);
QString subSystem = m_findPointWidget->getSelectDataByIndex(2);
QString tableName = m_findPointWidget->getSelectDataByIndex(5);
QString pointDesc = m_findPointWidget->getSelectDescByIndex(6);
if(pointDesc.isEmpty())
{
QMessageBox::information(this,tr("消息"),tr("请先选中测点"));
return;
}
QString sql = QString("SELECT TAG_NAME,DESCRIPTION FROM %1 WHERE "
"LOCATION_ID='%2' AND SUB_SYSTEM='%3' AND COALESCE(IS_CONTROL,0) != 0 "
"AND DESCRIPTION = '%4';")
.arg(tableName)
.arg(locationId)
.arg(subSystem)
.arg(pointDesc);
KbdDbDesign ds;
QList<QListWidgetItem *> items = ds.getSqlItems(sql,CN_DESC,CN_TAG_NAME);
QList<QListWidgetItem *> hasSelectItem;//已经存在了,不需要添加到list中
QList<QListWidgetItem *> notSelectItem;
foreach (QListWidgetItem *item, items) {
if(hasExistPoint(item->data(Qt::UserRole).toString()))
{
hasSelectItem << item;
}
else
{
notSelectItem << item;
}
}
foreach (QListWidgetItem *it, notSelectItem) {
it->setText(it->text() + "(" + it->data(Qt::UserRole).toString() + ")");
it->setData(Qt::UserRole + 1,locationId);
it->setData(Qt::UserRole + 2,subSystem);
m_list->addItem(it);
}
qDeleteAll(hasSelectItem);
m_rbSelect->blockSignals(true);
m_rbSelect->setChecked(false);
m_rbSelect->blockSignals(false);
}
void KbdSelctLockParaDlg::onRemove()
{
QList<int> selectIndexs;
foreach (QModelIndex index, m_list->selectionModel()->selectedRows()) {
selectIndexs<<index.row();
}
if(selectIndexs.isEmpty())
return;
std::sort(selectIndexs.begin(),selectIndexs.end());
//从后面往前删除
QList<QListWidgetItem*> selectItems;
for(int i = selectIndexs.size()-1;i >= 0;i--)
{
selectItems << m_list->takeItem(selectIndexs.at(i));
}
qDeleteAll(selectItems);
}