void ParameterWidget::storeFilterValue(QDate date) { QObject *filter = (QObject *)sender(); QLayoutItem *test; QLayoutItem *test2; QLayoutItem *child; QLayoutItem *child2; QGridLayout *layout; QHBoxLayout *layout2; QWidget *found; XComboBox *mybox; int foundRow = 0; for (int i = 1; i < _filtersLayout->rowCount(); i++) { test = _filtersLayout->itemAtPosition(i, 1); if (test) { layout = (QGridLayout *)test->layout(); child =layout->itemAtPosition(0, 0); layout2 = (QHBoxLayout *)child->layout()->itemAt(0); child2 = layout2->itemAt(0); found = child2->widget(); if (found == filter ) foundRow = i; } } test2 = _filtersLayout->itemAtPosition(foundRow, 0)->layout()->itemAt(0); mybox = (XComboBox*)test2->widget(); QString currText = mybox->currentText(); QPair<QString, ParameterWidgetTypes> tempPair = _types[currText]; _filterValues[foundRow] = qMakePair(tempPair.first, QVariant(date)); //if (!mybox->currentText().isEmpty()) //{ //_usedTypes->removeAll(mybox->currentText()); if (!_usedTypes.isEmpty()) _usedTypes.remove(foundRow); _usedTypes[foundRow] = mybox->currentText(); _addFilterRow->setDisabled(false); repopulateComboboxes(); emit updated(); }
void ParameterWidget::removeParam(int pRow) { QLayoutItem *test; QLayoutItem *test2; test = _filtersLayout->itemAtPosition(pRow, 0)->layout()->itemAt(0); XComboBox *mybox = (XComboBox*)test->widget(); QVariant filterVar(mybox->itemData(mybox->currentIndex())); QString filterType = filterVar.toString(); QStringList split = filterType.split(":"); QPair<QString, QVariant> tempPair = _filterValues.value(split[0].toInt()); _filterValues.remove(split[0].toInt()); test2 = _filtersLayout->itemAtPosition(pRow, 0)->layout()->takeAt(1); delete test2; test2 = 0; _filtersLayout->update(); _addFilterRow->setDisabled(false); repopulateComboboxes(); if (!mybox->currentText().isEmpty()) _usedTypes.remove(pRow); emit updated(); }
//stores the value of a filter object into the filtervalues map void ParameterWidget::storeFilterValue(int pId, QObject* filter) { if (!filter) { filter = (QObject *)sender(); } QLayoutItem *test; QLayoutItem *test2; QLayoutItem *child; QLayoutItem *child2; QGridLayout *layout; QHBoxLayout *layout2; QWidget *found; XComboBox *mybox; int foundRow = 0; for (int i = 1; i < _filtersLayout->rowCount(); i++) { test = _filtersLayout->itemAtPosition(i, 1); if (test) { layout = (QGridLayout *)test->layout(); child = layout->itemAtPosition(0, 0); layout2 = (QHBoxLayout *)child->layout()->itemAt(0); child2 = layout2->itemAt(0); found = child2->widget(); if (found == filter ) { foundRow = i; } } } test2 = _filtersLayout->itemAtPosition(foundRow, 0)->layout()->itemAt(0); mybox = (XComboBox*)test2->widget(); QString _currText = mybox->currentText(); QPair<QString, ParameterWidgetTypes> tempPair = _types[_currText]; const QMetaObject *metaobject = filter->metaObject(); QString classname(metaobject->className()); if (pId == -1) { if (classname == "QLineEdit") { QLineEdit *lineEdit = (QLineEdit *)filter; _filterValues[foundRow] = qMakePair(tempPair.first, QVariant(lineEdit->text())); emit updated(); } } else { if (classname == "UsernameCluster") { UsernameCluster *usernameCluster = (UsernameCluster *)filter; QString username = usernameCluster->username(); _filterValues[foundRow] = qMakePair(tempPair.first, QVariant(username)); emit updated(); } else { _filterValues[foundRow] = qMakePair(tempPair.first, QVariant(pId)); emit updated(); } } if (!_usedTypes.isEmpty()) _usedTypes.remove(foundRow); _usedTypes[foundRow] = mybox->currentText(); _addFilterRow->setDisabled(false); repopulateComboboxes(); }
void ParameterWidget::changeFilterObject(int index) { XComboBox *mybox = (XComboBox *)sender(); QStringList split = mybox->itemData(index).toString().split(":"); QString row = split.at(0); int type = split.at(1).toInt(); XSqlQuery qry; QWidget *widget = _filterGroup->findChild<QWidget *>("widget" + row); QWidget *button = _filterGroup->findChild<QToolButton *>("button" + row); QHBoxLayout *layout = _filterGroup->findChild<QHBoxLayout *>("widgetLayout1" + row);; QPair<QString, ParameterWidgetTypes> tempPair; DLineEdit *dLineEdit= new DLineEdit(_filterGroup); UsernameCluster *usernameCluster = new UsernameCluster(_filterGroup); CRMAcctCluster *crmacctCluster = new CRMAcctCluster(_filterGroup); QLineEdit *lineEdit = new QLineEdit(_filterGroup); XComboBox *xBox = new XComboBox(_filterGroup); ContactCluster *contactCluster = new ContactCluster(_filterGroup); if (widget && layout && button) delete widget; else return; switch (type) { case Date: delete usernameCluster; delete crmacctCluster; delete lineEdit; delete xBox; delete contactCluster; dLineEdit->setObjectName("widget" + row); layout->insertWidget(0, dLineEdit); connect(button, SIGNAL(clicked()), dLineEdit, SLOT( deleteLater() ) ); connect(dLineEdit, SIGNAL(newDate(QDate)), this, SLOT( storeFilterValue(QDate) ) ); break; case User: delete dLineEdit; delete crmacctCluster; delete lineEdit; delete xBox; delete contactCluster; usernameCluster->setObjectName("widget" + row); usernameCluster->setNameVisible(false); usernameCluster->setDescriptionVisible(false); usernameCluster->setLabel(""); layout->insertWidget(0, usernameCluster); connect(button, SIGNAL(clicked()), usernameCluster, SLOT( deleteLater() ) ); connect(usernameCluster, SIGNAL(newId(int)), this, SLOT( storeFilterValue(int) ) ); break; case Crmacct: delete dLineEdit; delete usernameCluster; delete lineEdit; delete xBox; delete contactCluster; crmacctCluster->setObjectName("widget" + row); crmacctCluster->setNameVisible(false); crmacctCluster->setDescriptionVisible(false); crmacctCluster->setLabel(""); layout->insertWidget(0, crmacctCluster); connect(button, SIGNAL(clicked()), crmacctCluster, SLOT( deleteLater() ) ); connect(crmacctCluster, SIGNAL(newId(int)), this, SLOT( storeFilterValue(int) ) ); break; case Contact: delete dLineEdit; delete usernameCluster; delete lineEdit; delete xBox; delete crmacctCluster; contactCluster->setObjectName("widget" + row); contactCluster->setDescriptionVisible(false); contactCluster->setLabel(""); layout->insertWidget(0, contactCluster); connect(button, SIGNAL(clicked()), contactCluster, SLOT( deleteLater() ) ); connect(contactCluster, SIGNAL(newId(int)), this, SLOT( storeFilterValue(int) ) ); break; case XComBox: delete dLineEdit; delete usernameCluster; delete lineEdit; delete crmacctCluster; delete contactCluster; xBox->setObjectName("widget" + row); xBox->setType(_comboTypes[mybox->currentText()]); if (_comboTypes[mybox->currentText()] == XComboBox::Adhoc) { qry.prepare( _comboQuery[mybox->currentText()] ); qry.exec(); xBox->populate(qry); } layout->insertWidget(0, xBox); connect(button, SIGNAL(clicked()), xBox, SLOT( deleteLater() ) ); connect(xBox, SIGNAL(newID(int)), this, SLOT( storeFilterValue(int) ) ); break; default: delete dLineEdit; delete usernameCluster; delete crmacctCluster; delete xBox; delete contactCluster; lineEdit->setObjectName("widget" + row); layout->insertWidget(0, lineEdit); connect(button, SIGNAL(clicked()), lineEdit, SLOT( deleteLater() ) ); connect(lineEdit, SIGNAL(editingFinished()), this, SLOT( storeFilterValue() ) ); break; } }