#include "kbdselctlockparadlg.h" #include #include "CustomWidget/kbdfindpointwidget.h" #include "../model_common/common.h" #include #include #include #include #include #include #include #include #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) <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 items = ds.getSqlItems(sql,CN_DESC,CN_TAG_NAME); QList hasSelectItem;//已经存在了,不需要添加到list中 QList 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 selectIndexs; foreach (QModelIndex index, m_list->selectionModel()->selectedRows()) { selectIndexs< selectItems; for(int i = selectIndexs.size()-1;i >= 0;i--) { selectItems << m_list->takeItem(selectIndexs.at(i)); } qDeleteAll(selectItems); }