HAL
searchcolumndialog.cpp
Go to the documentation of this file.
2 #include <QVBoxLayout>
3 #include <QFrame>
4 #include <QPushButton>
5 #include <QDebug>
6 
7 namespace hal {
8 
10  : mDisableHandler(false)
11  {
12  //TODO FIX check logic
13  setWindowTitle("Search in:");
14  QVBoxLayout* layout = new QVBoxLayout(this);
15  mCheckAllColumns = new QCheckBox("All columns", this);
16  connect(mCheckAllColumns,&QCheckBox::stateChanged,this,&SearchColumnDialog::handleCheckStateChanged);
17  layout->addWidget(mCheckAllColumns);
18 
19  QFrame* frame = new QFrame(this);
20  frame->setLineWidth(3);
22  QVBoxLayout* flay = new QVBoxLayout(frame);
23  int inx = 0;
24  for (const QString& col : colNames)
25  {
26  QCheckBox* cbox = new QCheckBox(col, frame);
27  cbox->setChecked(selected.isEmpty() || selected.contains(inx));
28  connect(cbox,&QCheckBox::stateChanged,this,&SearchColumnDialog::handleCheckStateChanged);
29  flay->addWidget(cbox);
30  mCheckColumn.append(cbox);
31  ++inx;
32  }
33  layout->addWidget(frame);
34 
38  layout->addWidget(mButtonBox);
39  handleCheckStateChanged(0);
40  }
41 
42  void SearchColumnDialog::handleCheckStateChanged(int state)
43  {
44  if (mDisableHandler) return;
45 
46  bool allChecked = true;
47  bool nullChecked = true;
48 
49  if (sender()==mCheckAllColumns && state == Qt::Checked)
50  {
51  mDisableHandler = true;
52  for (QCheckBox* cbox : mCheckColumn)
53  cbox->setChecked(true);
54  mDisableHandler = false;
55  }
56  else if (sender()==mCheckAllColumns && state == Qt::Unchecked)
57  {
58  mDisableHandler = true;
59  //check if everything is checked
60  for(QCheckBox* cbox: mCheckColumn){
61  if(!cbox->isChecked())
62  {
63  allChecked = false;
64  break;
65  }
66  }
67  if(allChecked){
68  for (QCheckBox* cbox : mCheckColumn)
69  cbox->setChecked(false);
70  }
71  mDisableHandler = false;
72  }
73 
74 
75  for (const QCheckBox* cbox : mCheckColumn)
76  {
77  if (cbox->isChecked())
78  nullChecked = false;
79  else
80  allChecked = false;
81  }
82  // if all columns are checked then check top checkbox - otherwise uncheck it
83  if (mCheckAllColumns->isChecked() != allChecked)
84  {
85  mCheckAllColumns->setCheckState(allChecked ? Qt::Checked : Qt::Unchecked);
86  mCheckAllColumns->setChecked(allChecked);
87  }
88  mButtonBox->button(QDialogButtonBox::Ok)->setDisabled(nullChecked);
89  }
90 
92  {
93  if (mCheckAllColumns->isChecked()) return "All columns";
94 
95  QString retval;
96  for (const QCheckBox* cbox : mCheckColumn)
97  {
98  if (!cbox->isChecked()) continue;
99  if (!retval.isEmpty()) retval += ',';
100  retval += cbox->text();
101  }
102  return retval;
103  }
104 
106  {
107  QList<int> retval;
108  if (mCheckAllColumns->isChecked()) return retval;
109 
110  int inx = 0;
111  for (const QCheckBox* cbox : mCheckColumn)
112  {
113  if (cbox->isChecked()) retval.append(inx);
114  ++inx;
115  }
116  return retval;
117  }
118 
120  {
121  handleCheckStateChanged(0);
122  QDialog::accept();
123  }
124 }
SearchColumnDialog(const QStringList &colNames, const QList< int > &selected)
QString selectedColumnNames() const
QList< int > selectedColumns() const
void setChecked(bool)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setCheckState(Qt::CheckState state)
void stateChanged(int state)
virtual void accept()
virtual void reject()
QPushButton * button(QDialogButtonBox::StandardButton which) const const
void setLineWidth(int)
void setFrameStyle(int style)
void addWidget(QWidget *w)
void append(const T &value)
bool contains(const T &value) const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * sender() const const
bool isEmpty() const const
QLayout * layout() const const
void setDisabled(bool disable)
void setWindowTitle(const QString &)