Esempio n. 1
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. 2
0
void ParameterWidget::addParam()
{
  XComboBox *xcomboBox = new XComboBox(_filterGroup);
  QToolButton *toolButton = new QToolButton(_filterGroup);
  QLineEdit *lineEdit = new QLineEdit(_filterGroup);
  QGridLayout *gridLayout = new QGridLayout();
  QVBoxLayout *xcomboLayout = new QVBoxLayout();
  QHBoxLayout *widgetLayout1 = new QHBoxLayout();
  QVBoxLayout *widgetLayout2 = new QVBoxLayout();
  QVBoxLayout *buttonLayout = new QVBoxLayout();

  int nextRow = _filtersLayout->rowCount();
  QString currRow = QString().setNum(nextRow);

  // Set up objects
  gridLayout->setObjectName("topLayout" + currRow);

  xcomboLayout->setObjectName("xcomboLayout" + currRow);
  xcomboLayout->setContentsMargins(0, 0, 0, 0);

  xcomboBox->setObjectName("xcomboBox" + currRow);
  xcomboBox->addItem("", currRow + ":" + "2");

  widgetLayout1->setObjectName("widgetLayout1" + currRow);

  widgetLayout2->setObjectName("widgetLayout2" + currRow);
  widgetLayout2->setContentsMargins(0, 0, 0, 0);

  lineEdit->setObjectName("widget" + currRow);
  lineEdit->setDisabled(true);

  buttonLayout->setObjectName("buttonLayout" + currRow);
  buttonLayout->setContentsMargins(0, 0, 0, 0);

  toolButton->setObjectName("button" + currRow);
  toolButton->setText(tr("-"));

  //grab the items provided by other widgets to populate xcombobox with
  QMapIterator<QString, QPair<QString, ParameterWidgetTypes> > i(_types);
  while (i.hasNext())
  {
    i.next();
    QPair<QString, ParameterWidgetTypes> tempPair = i.value();
    QString value = QString().setNum(nextRow) + ":" + QString().setNum(tempPair.second);
    if ( _usedTypes.isEmpty() || !containsUsedType(i.key()) )
      xcomboBox->addItem(i.key(), value );
  }

  xcomboLayout->addWidget(xcomboBox);
  xcomboLayout->addItem(new QSpacerItem(20, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));

  // Place the default line edit/button combo
  widgetLayout1->addWidget(lineEdit);
  widgetLayout1->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Fixed));

  widgetLayout2->addLayout(widgetLayout1);
  widgetLayout2->addItem(new QSpacerItem(20, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));

  gridLayout->addLayout(widgetLayout2, 0, 0, 1, 1);

  // Place Button
  buttonLayout->addWidget(toolButton);
  buttonLayout->addItem(new QSpacerItem(10, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));

  gridLayout->addLayout(buttonLayout, 0, 1, 1, 1);

  _filtersLayout->addLayout(gridLayout, nextRow, 1, 1, 1);
  _filtersLayout->addLayout(xcomboLayout, nextRow, 0, 1, 1);

  // Hook up connections
  connect(toolButton, SIGNAL(clicked()), _filterSignalMapper, SLOT(map()));
  connect(toolButton, SIGNAL(clicked()), gridLayout, SLOT( deleteLater() ) );
  connect(toolButton, SIGNAL(clicked()), xcomboBox, SLOT( deleteLater() ) );
  connect(toolButton, SIGNAL(clicked()), lineEdit, SLOT( deleteLater() ) );
  connect(toolButton, SIGNAL(clicked()), toolButton, SLOT( deleteLater() ) );
  connect(xcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT( changeFilterObject(int)) );
  connect(lineEdit, SIGNAL(editingFinished()), this, SLOT( storeFilterValue() ) );

  _filterSignalMapper->setMapping(toolButton, nextRow);

  _addFilterRow->setDisabled(true);
}