#pragma warning(push,0) // #include "Family.h" #include #include "OSGFramework.h" #include "TiShiDlg.h" #include "ui_TiShi.h" #include "CStringType.h" #include "CheckHeadView.h" #include #pragma warning(pop) // using namespace pai::ios::welllog; BEGIN_OSGGRAPHICS_NAMESPACE CTiShiDlg::CTiShiDlg(QWidget * parent, Qt::WindowFlags flags) : QDialog(parent,flags) { m_pUI = new Ui_TiShi(); m_pUI->setupUi(this); QObject::connect(m_pUI->okbtn, SIGNAL(clicked()), this, SLOT(slotSave())); QObject::connect(m_pUI->cancelbtn, SIGNAL(clicked()), this, SLOT(slotCancel())); connect(m_pUI->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(settingTableChanged(int, int))); } void CTiShiDlg::slotSave() { QStringList nameList; for(int i = 0;itableWidget->rowCount ();i++) { bool IsCheck=0; for(int j = 1;jtableWidget->columnCount ();j++) { if(m_pUI->tableWidget->item (i,j)->checkState ()==Qt::Checked) { IsCheck=1;break; } } if(!IsCheck)nameList.append(m_pUI->tableWidget->item (i,0)->text()); } if(nameList.count()==0) { accept(); return; } QString name="\r\n"; for(int i=0;i=20)break; name+=nameList.at(i)+"\r\n"; } QMessageBox::warning(NULL,"提示","下列井没有任何勾选项:"+name+"请勾选后再加载"); return; } /** *@brief 取消槽函数 */ void CTiShiDlg::slotCancel() { reject (); } void CTiShiDlg::init() { m_pUI->tableWidget->setColumnCount(5); m_pUI->tableWidget->setRowCount(namelist.size()); QStringList header; header<<"井名"<<"替换"<<"合并"<<"另存"<<"放弃"; m_pUI->tableWidget->setHorizontalHeaderLabels(header); m_pUI->tableWidget->horizontalHeader()->setStretchLastSection(true); m_pUI->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); #pragma region 表头重画为勾选 QVector rVector; rVector <<1<<2 <<3; CheckHeadView* pCheckHeadView = new CheckHeadView(rVector,Qt::Horizontal,m_pUI->tableWidget); auto pCheckBox=pCheckHeadView->GetCheckBox(1); if(pCheckBox) { pCheckBox->setChecked(true); } m_pUI->tableWidget->setHorizontalHeader(pCheckHeadView); connect(pCheckHeadView, SIGNAL(SignalStatus(int, bool)), this, SLOT(slotSetMode(int, bool))); #pragma endregion 表头重画为勾选 for(int i = 0;itableWidget->rowCount ();i++) { m_pUI->tableWidget->setItem(i,0,new QTableWidgetItem(namelist.at(i))); for(int j=1;jtableWidget->columnCount ();j++) { QTableWidgetItem *check=new QTableWidgetItem; if(j==1)check->setCheckState (Qt::Checked); else check->setCheckState (Qt::Unchecked); m_pUI->tableWidget->setItem(i,j,check); //插入复选框 } } } void CTiShiDlg::slotSetMode(int col,bool flag) { SetMode(col,flag); if(flag) { CheckHeadView* pCheckHeadView=(CheckHeadView*)m_pUI->tableWidget->horizontalHeader(); for(int i=1;i<=4;i++) { if(i==col)continue; SetMode(i,false); if(i==4)continue;//最后一列没有头部勾选 auto pCheckBox=pCheckHeadView->GetCheckBox(i); if(pCheckBox) { pCheckBox->setChecked(false); } } } } void CTiShiDlg::SetMode(int col,bool flag) { for(int i = 0;itableWidget->rowCount ();i++) { if(flag)m_pUI->tableWidget->item (i,col)->setCheckState(Qt::Checked); else m_pUI->tableWidget->item (i,col)->setCheckState(Qt::Unchecked); /*for(int j = 1;jtableWidget->columnCount ();j++) { if(j-1==mode)m_pUI->tableWidget->item (i,j)->setCheckState(Qt::Checked); else m_pUI->tableWidget->item (i,j)->setCheckState(Qt::Unchecked); }*/ } } void CTiShiDlg::settingTableChanged(int row, int col) { if(!col)return; if(m_pUI->tableWidget->item (row,col)->checkState ()==Qt::Unchecked) { for(int j = 1;jtableWidget->columnCount ();j++) { if(m_pUI->tableWidget->item (row,j)->checkState ()==Qt::Checked)return; } m_pUI->tableWidget->item (row,col)->setCheckState(Qt::Checked); } for(int j = 1;jtableWidget->columnCount ();j++) { if(j==col)m_pUI->tableWidget->item (row,j)->setCheckState(Qt::Checked); else m_pUI->tableWidget->item (row,j)->setCheckState(Qt::Unchecked); } // CheckHeadView* pCheckHeadView=(CheckHeadView*)m_pUI->tableWidget->horizontalHeader(); for(int i=1;i<=3;i++) { if(i==col)continue; auto pCheckBox=pCheckHeadView->GetCheckBox(i); if(pCheckBox) { pCheckBox->setChecked(false); } } // } END_OSGGRAPHICS_NAMESPACE