Esempio n. 1
0
//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();

}
Esempio n. 2
0
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();
}
Esempio n. 3
0
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;
  }

}
Esempio n. 4
0
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