void ParameterWidget::applySaved(int pId, int filter_id) { qDebug() << "in applySaved, pid is: " << pId; QGridLayout *container; QLayoutItem *child; QLayoutItem *child2; QHBoxLayout *layout2; QWidget *found; QDate tempdate; XSqlQuery qry; QString query; QString filterValue; int xid; QMapIterator<int, QPair<QString, QVariant> > j(_filterValues); clearFilters(); if (!parent()) return; //if (pId == 0) //addParam(); if (_filterList->id() == -1) { _filterSetName->clear(); setSelectedFilter(-1); emit updated(); return; } if (filter_id == 0 && _filterList->id() != -1) filter_id = _filterList->id(_filterList->currentIndex()); const QMetaObject *metaobject = this->parent()->metaObject(); QString classname(metaobject->className()); //look up filter from database query = " SELECT filter_value " " FROM filter " " WHERE filter_username=current_user " " AND filter_id=:id " " AND filter_screen=:screen "; qry.prepare(query); qry.bindValue(":screen", classname); qry.bindValue(":id", filter_id ); qry.exec(); if (qry.first()) filterValue = qry.value("filter_value").toString(); QStringList filterRows = filterValue.split("|"); QString tempFilter = QString(); int windowIdx = _filtersLayout->rowCount(); for (int i = 0; i < filterRows.size(); ++i) { tempFilter = filterRows[i]; if ( !(tempFilter.isEmpty()) ) { //0 is filterType, 1 is filterValue, 2 is parameterwidgettype QStringList tempFilterList = tempFilter.split(":"); this->addParam(); QLayoutItem *test = _filtersLayout->itemAtPosition(windowIdx, 0)->layout()->itemAt(0); XComboBox *mybox = (XComboBox*)test->widget(); QString key = this->getParameterTypeKey(tempFilterList[0]); int idx = mybox->findText(key); mybox->setCurrentIndex(idx); QString row; row = row.setNum(windowIdx); container = _filtersLayout->findChild<QGridLayout *>("topLayout" + row); child = container->itemAtPosition(0, 0)->layout()->itemAt(0); layout2 = (QHBoxLayout *)child->layout(); child2 = layout2->itemAt(0); found = child2->widget(); int widgetType = tempFilterList[2].toInt(); //grab pointer to newly created filter object switch (widgetType) { case Date: DLineEdit *dLineEdit; dLineEdit = (DLineEdit*)found; dLineEdit->setDate(QDate::fromString(tempFilterList[1], "yyyy-MM-dd"), true); break; case User: UsernameCluster *usernameCluster; usernameCluster = (UsernameCluster*)found; usernameCluster->setUsername(tempFilterList[1]); break; case Crmacct: CRMAcctCluster *crmacctCluster; crmacctCluster = (CRMAcctCluster*)found; crmacctCluster->setId(tempFilterList[1].toInt()); break; case Contact: ContactCluster *contactCluster; contactCluster = (ContactCluster*)found; contactCluster->setId(tempFilterList[1].toInt()); break; case XComBox: XComboBox *xBox; xBox = (XComboBox*)found; //fix for setid not emitting id signal if id found for filter is first in list //set to any other valid id first to fix it xBox->setId(2); xid = tempFilterList[1].toInt(); qDebug() << "xid is: " << xid; xBox->setId(xid); while (j.hasNext()) { j.next(); QPair<QString, QVariant> tempPair = j.value(); qDebug() << j.key() << ": " << tempPair.second << endl; } break; default: QLineEdit *lineEdit; lineEdit = (QLineEdit*)found; lineEdit->setText(tempFilterList[1]); storeFilterValue(-1, lineEdit); break; } }//end of if windowIdx++; }//end of for _filterSetName->setText( _filterList->currentText() ); setSelectedFilter(filter_id); emit updated(); }
void ParameterWidget::applySaved(int pId, int filter_id) { QWidget *found = 0; QDate tempdate; XSqlQuery qry; QString query; QString filterValue; QDate today = QDate::currentDate(); int xid, init_filter_id; init_filter_id = filter_id; QMapIterator<int, QPair<QString, QVariant> > j(_filterValues); QPair<QString, ParameterWidgetTypes> tempPair; clearFilters(); if (!parent()) return; if (_filterList->id() == -1) { emit updated(); return; } if (filter_id == 0 && _filterList->id() != -1) filter_id = _filterList->id(_filterList->currentIndex()); QString classname(parent()->objectName()); if (classname.isEmpty()) classname = parent()->metaObject()->className(); query = " SELECT filter_value, " " CASE WHEN (filter_username IS NULL) THEN true " " ELSE false END AS shared " " FROM filter " " WHERE filter_id=:id "; qry.prepare(query); qry.bindValue(":id", filter_id ); qry.exec(); if (qry.first()) { filterValue = qry.value("filter_value").toString(); _shared = qry.value("shared").toBool(); } QStringList filterRows = filterValue.split("|"); QString tempFilter = QString(); int windowIdx = _filtersLayout->rowCount(); if (filterRows.size() == 1 && pId == 0 && filter_id != 0) { emit updated(); return; } for (int i = 0; i < filterRows.size(); ++i) { tempFilter = filterRows[i]; if ( !(tempFilter.isEmpty()) ) { //0 is filterType, 1 is filterValue, 2 is parameterwidgettype QStringList tempFilterList = tempFilter.split(":"); QString key = this->getParameterTypeKey(tempFilterList[0]); if (key.isEmpty()) { //parametertype is no longer found, prompt user to delete filter if (QMessageBox::question(this, tr("Invalid Filter Set"), tr("This filter set contains an obsolete filter and will be deleted. Do you want to do this?"), QMessageBox::No | QMessageBox::Default, QMessageBox::Yes) == QMessageBox::No) return; else { QString query = "delete from filter where filter_id=:filter_id"; XSqlQuery qry; qry.prepare(query); qry.bindValue(":filter_id", filter_id); qry.exec(); setSavedFilters(); return; } } else { this->addParam(); QLayoutItem *test = _filtersLayout->itemAtPosition(windowIdx, 0)->layout()->itemAt(0); XComboBox *mybox = (XComboBox*)test->widget(); int idx = mybox->findText(key); mybox->setCurrentIndex(idx); found = getFilterWidget(windowIdx); int widgetType = tempFilterList[2].toInt(); //grab pointer to newly created filter object switch (widgetType) { case Date: DLineEdit *dLineEdit; dLineEdit = qobject_cast<DLineEdit*>(found); if (dLineEdit != 0) dLineEdit->setDate(today.addDays(tempFilterList[1].toInt()), true); break; case User: UsernameCluster *usernameCluster; usernameCluster = qobject_cast<UsernameCluster*>(found); if (usernameCluster != 0) usernameCluster->setUsername(tempFilterList[1]); break; case Crmacct: CRMAcctCluster *crmacctCluster; crmacctCluster = qobject_cast<CRMAcctCluster*>(found); if (crmacctCluster != 0) crmacctCluster->setId(tempFilterList[1].toInt()); break; case Contact: ContactCluster *contactCluster; contactCluster = qobject_cast<ContactCluster*>(found); if (contactCluster != 0) contactCluster->setId(tempFilterList[1].toInt()); break; case XComBox: XComboBox *xBox; xBox = qobject_cast<XComboBox*>(found); if (xBox != 0) { //fix for setid not emitting id signal if id found for filter is first in list //set to any other valid id first to fix it xBox->setId(2); xid = tempFilterList[1].toInt(); xBox->setId(xid); } break; case Multiselect: { QTableWidget *tab; tab = qobject_cast<QTableWidget*>(found); if (tab != 0) { QStringList savedval = tempFilterList[1].split(","); bool oldblk = tab->blockSignals(true); /* the obvious, loop calling tab->selectRow(), gives one selected row, so try this to get multiple selections: make only the desired values selectable, select everything, and connect to a slot that can clean up after us. yuck. */ for (int j = 0; j < tab->rowCount(); j++) { if (! savedval.contains(tab->item(j, 0)->data(Qt::UserRole).toString())) tab->item(j, 0)->setFlags(tab->item(j, 0)->flags() & (~ Qt::ItemIsSelectable)); } QTableWidgetSelectionRange range(0, 0, tab->rowCount() - 1, tab->columnCount() - 1); tab->setRangeSelected(range, true); connect(tab, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(resetMultiselect(QTableWidgetItem*))); tab->blockSignals(oldblk); storeFilterValue(-1, tab); } } break; default: { QLineEdit *lineEdit; lineEdit = qobject_cast<QLineEdit*>(found); if (lineEdit != 0) { lineEdit->setText(tempFilterList[1]); storeFilterValue(-1, lineEdit); } } break; }//end of switch }//end of not empty key else windowIdx++; }//end of if tempfilter not empty