MyWindow :: MyWindow( ): XFrameWindow( 100 , "Handling events!", XFrameWindow::defaultStyle)
{
    //at first we define a color which is used to paint the background
    //we chose white as background color
    XColor color(COL_WHITE);
    SetBackgroundColor( &color );

    //Set the position of this window
    //left-lower corner is 100,100, width is 300, height is 200
    XRect rect(100,100,300,230);
    SetSize(&rect);

    //now we create some control windows so events can be posted
    //at first a combobox
    XComboBox * combo = new XComboBox( this, XRect( 20, 100, 200, 90), IDC_LISTNAME, CB_DROPDOWNLIST | WIN_VISIBLE);
    //insert some rows
    combo->InsertItem( "Line 1");
    combo->InsertItem( "Line 2");
    combo->InsertItem( "Line 3");
    combo->InsertItem( "Line 4");
    combo->InsertItem( "Line 5");

    //create a simple entry field
    XEntryField * entry = new XEntryField( this, XRect( 20, 60, 100, 20), IDE_ENTRYNAME, ES_MARGIN | EN_LEFT | WIN_VISIBLE);

    //make this window the active window
    Activate();
}
Beispiel #2
0
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();
}
Beispiel #3
0
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();
}
Beispiel #4
0
void apWorkBench::sCalculateTotalOpen()
{
  // copied and edited from selectPayments.cpp
  ParameterList params;
  _vendorgroup->appendValue(params);
  params.append("voucher", tr("Voucher"));
  params.append("debitMemo", tr("D/M"));

  XComboBox *bankaccnt = _payables->findChild<XComboBox*>("_bankaccnt");
  if (bankaccnt->isValid())
  {
    q.prepare( "SELECT bankaccnt_curr_id "
               "FROM bankaccnt "
               "WHERE (bankaccnt_id=:bankaccnt_id);" );
    q.bindValue(":bankaccnt_id", bankaccnt->id());
    q.exec();
    if (q.first())
      params.append("curr_id", q.value("bankaccnt_curr_id").toInt());
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  
  
  if (_payables->findChild<XComboBox*>("_selectDate")->currentIndex() == 1)
    params.append("olderDate", _payables->findChild<DLineEdit*>("_onOrBeforeDate")->date());
  else if(_payables->findChild<XComboBox*>("_selectDate")->currentIndex() == 2)
  {
    params.append("startDate", _payables->findChild<DLineEdit*>("_startDate")->date());
    params.append("endDate", _payables->findChild<DLineEdit*>("_endDate")->date());
  }
  
  MetaSQLQuery due(
         "SELECT SUM((apopen_amount - apopen_paid - "
         "                      COALESCE((SELECT SUM(checkitem_amount + checkitem_discount) "
         "                                FROM checkitem, checkhead "
         "                                WHERE ((checkitem_checkhead_id=checkhead_id) "
         "                                   AND (checkitem_apopen_id=apopen_id) "
         "                                   AND (NOT checkhead_void) "
         "                                   AND (NOT checkhead_posted)) "
         "                               ), 0)) / apopen_curr_rate) AS openamount_base,"
         "       SUM(COALESCE(currToBase(apselect_curr_id, apselect_amount,"
         "                               CURRENT_DATE), 0)) AS selected_base "
         "FROM vend, apopen"
         "     LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id) "
         "WHERE ((apopen_open)"
         " AND (apopen_doctype IN ('V', 'D'))"
         " AND (apopen_vend_id=vend_id)"
         "<? if exists(\"vend_id\") ?>"
         " AND (vend_id=<? value(\"vend_id\") ?>)"
         "<? elseif exists(\"vendtype_id\") ?>"
         " AND (vend_vendtype_id=<? value(\"vendtype_id\") ?>)"
         "<? elseif exists(\"vendtype_pattern\") ?>"
         " AND (vend_vendtype_id IN (SELECT vendtype_id"
         "                           FROM vendtype"
         "                           WHERE (vendtype_code ~ <? value(\"vendtype_pattern\") ?>)))"
         "<? endif ?>"
         "<? if exists(\"olderDate\") ?>"
         " AND (apopen_duedate < <? value(\"olderDate\") ?>)"
         "<? elseif exists(\"startDate\") ?>"
         " AND (apopen_duedate BETWEEN <? value(\"startDate\") ?> AND <? value(\"endDate\") ?>)"
         "<? endif ?>"
         "<? if exists(\"curr_id\") ?>"
         " AND (apopen_curr_id=<? value(\"curr_id\") ?>)"
         "<? endif ?>"
         ");" );
  q = due.toQuery(params);
  if (q.first())
    _apopenTotal->setLocalValue(q.value("openamount_base").toDouble());
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  // copied from unappliedAPCreditMemos and edited
  MetaSQLQuery cr(
             "SELECT SUM((apopen_amount - apopen_paid)/ apopen_curr_rate) AS basebalance "
             "FROM apopen, vend "
             "WHERE ( (apopen_doctype='C')"
             " AND (apopen_open)"
             " AND (apopen_vend_id=vend_id)"
             "<? if exists(\"vend_id\") ?>"
             " AND (vend_id=<? value(\"vend_id\") ?>)"
             "<? elseif exists(\"vendtype_id\") ?>"
             " AND (vend_vendtype_id=<? value(\"vendtype_id\") ?>)"
             "<? elseif exists(\"vendtype_pattern\") ?>"
             " AND (vend_vendtype_id IN (SELECT vendtype_id"
             "                           FROM vendtype"
             "                           WHERE (vendtype_code ~ <? value(\"vendtype_pattern\") ?>)))"
             "<? endif ?>"
             ");");
  q = cr.toQuery(params);
  if (q.first())
  {
    _apopenTotal->setLocalValue(_apopenTotal->localValue() -
                                q.value("basebalance").toDouble());
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Beispiel #5
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();

}
Beispiel #6
0
void ParameterWidget::save()
{
  QString filter;
  QString filtersetname;
  QString variantString;
  QString username;
  QString query;
  QVariant tempVar;
  int filter_id;
  QMessageBox msgBox;

  filtersetname = _filterSetName->text();

  if ( filtersetname.isEmpty() )
  {
    msgBox.setText(tr("Please enter a name for this filter set before saving."));
    msgBox.exec();
    return;
  }
  else
  {

    QMapIterator<int, QPair<QString, QVariant> > i(_filterValues);
    while (i.hasNext())
    {
      i.next();
      QPair<QString, QVariant> tempPair = i.value();

      tempVar = tempPair.second;

      QLayoutItem *test = _filtersLayout->itemAtPosition(i.key(), 0)->layout()->itemAt(0);
      XComboBox* mybox = (XComboBox*)test->widget();
      QStringList split = mybox->itemData(mybox->currentIndex()).toString().split(":");

      if ( tempVar.canConvert<QString>() )
      {
        variantString = tempVar.toString();
        filter = filter + tempPair.first + ":" + variantString + ":" + split[1] + "|";
      }
    }

    const QMetaObject *metaobject = this->parent()->metaObject();
    QString classname(metaobject->className());

    XSqlQuery qry, qry2, qry3;

    qry.exec("SELECT current_user;");
    if (qry.first())
      username = qry.value("current_user").toString();

    //check to see if filter name exists for this screen
    QString filter_query = "select filter_name "
                           "from filter "
                           "where filter_name=:name and filter_username=:username "
                           " and filter_screen=:screen";
    qry2.prepare(filter_query);
    qry2.bindValue(":name", filtersetname);
    qry2.bindValue(":username" , username);
    qry2.bindValue(":screen", classname);

    qry2.exec();

    //if the filter name is found, update it
    if (qry2.first() && !qry2.isNull(0))
      query = "update filter set filter_value=:value "
              "where filter_screen=:screen "
              " and filter_name=:name "
              " and filter_username=:username";
    else
      query = "insert into filter (filter_screen, filter_name, filter_value, filter_username) "
              " values (:screen, :name, :value, :username) ";

    qry.prepare(query);
    qry.bindValue(":screen", classname);
    qry.bindValue(":value", filter);
    qry.bindValue(":username" , username);
    qry.bindValue(":name", filtersetname );

    if (qry.exec())
    {
      query = "select filter_id "
              "from filter "
              "where filter_name=:name "
              " and filter_username=:username "
              " and filter_screen=:screen";
      qry3.prepare(query);
      qry3.bindValue(":screen", classname);
      qry3.bindValue(":username" , username);
      qry3.bindValue(":name", filtersetname );
      qry3.exec();

      if (qry3.first())
        filter_id = qry.value("filter_id").toInt();

      emit filterSetSaved();
    }
  }
  setSavedFilters();
  _filterList->setCurrentIndex(_filterList->findText(filtersetname));
}
Beispiel #7
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;
  }

}
Beispiel #8
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();
}
Beispiel #9
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);
}
Beispiel #10
0
    docAttachPrivate(docAttach *parent)
      : p(parent)
    {
      // url and file match _docType->populate below, at least for now
      map.insert(-3,                           new StackDescriptor(p->_urlPage,     p->_url));
      map.insert(-2,                           new StackDescriptor(p->_filePage,    p->_file));
      map.insert(Documents::Contact,           new StackDescriptor(p->_cntctPage,   p->_cntct));
      map.insert(Documents::CRMAccount,        new StackDescriptor(p->_crmacctPage, p->_crmacct));
      map.insert(Documents::Customer,          new StackDescriptor(p->_custPage,    p->_cust));
      map.insert(Documents::Employee,          new StackDescriptor(p->_empPage,     p->_emp));
      map.insert(Documents::Uninitialized,     new StackDescriptor(p->_filePage,    p->_file));
      map.insert(Documents::Uninitialized,     new StackDescriptor(p->_imagePage,   p->_img));
      map.insert(Documents::Incident,          new StackDescriptor(p->_incdtPage,   p->_incdt));
      map.insert(Documents::Invoice,           new StackDescriptor(p->_invoicePage, p->_invoice));
      map.insert(Documents::Item,              new StackDescriptor(p->_itemPage,    p->_item));
      map.insert(Documents::Opportunity,       new StackDescriptor(p->_oppPage,     p->_opp));
      map.insert(Documents::Project,           new StackDescriptor(p->_projPage,    p->_proj));
      map.insert(Documents::PurchaseOrder,     new StackDescriptor(p->_poPage,      p->_po));
      map.insert(Documents::SalesOrder,        new StackDescriptor(p->_soPage,      p->_so));
      map.insert(Documents::Vendor,            new StackDescriptor(p->_vendPage,    p->_vend));
      map.insert(Documents::Uninitialized,     new StackDescriptor(p->_urlPage,     p->_url));
      map.insert(Documents::WorkOrder,         new StackDescriptor(p->_woPage,      p->_wo));

      if (! _x_privileges) return; // Qt Designer doesn't connect to the database

      XSqlQuery q("SELECT * FROM source"
                  " WHERE source_widget NOT IN ('', 'core');");
      QUiLoader uil(p);
      while (q.next())
      {
        QWidget *w = 0;
        QString  description = q.value("source_widget").toString();
        if (DEBUG)
          qDebug() << "checking" << q.value("source_name") << description;
        if (description.startsWith("SELECT", Qt::CaseInsensitive))
        {
          XComboBox *c = new XComboBox();
          c->populate(description);
          w = c;
        }
        else if (description.contains("Cluster"))
        {
          w = uil.createWidget(description, p,
                               "_" + q.value("source_name").toString());
        }
        if (w) {
          QString litValue = q.value("source_descrip").toString();
          QWidget     *page = new QWidget();
          QFormLayout *lyt  = new QFormLayout(p);
          QLabel      *lit  = new QLabel(QT_TRANSLATE_NOOP("docAttach", litValue));
          page->setLayout(lyt);
          lyt->addRow(lit, w);
          p->_documentsStack->addWidget(page);
          map.insert(q.value("source_docass_num").toInt(), new StackDescriptor(page, w));
          if (DEBUG) qDebug() << "created a widget for" << description;
        }
        else
        {
          qDebug() << "Could not create a widget for" << description;
        }
      }
      ErrorReporter::error(QtCriticalMsg, 0, "Error Getting Document Types",
                           q, __FILE__, __LINE__);
    }
Beispiel #11
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