//-----------------------------------------------------------------------------
void OsiTestSolverInterface::setRowSetTypes(const int* indexFirst,
					   const int* indexLast,
					   const char* senseList,
					   const double* rhsList,
					   const double* rangeList)
{
  if (indexLast - indexFirst < getNumRows() / 3) {
    while (indexFirst < indexLast) {
      setRowType(*indexFirst++, *senseList++, *rhsList++, *rangeList++);
    }
  } else {
    // it's better to convert everything at once
    while (indexFirst < indexLast) {
      const int ind = *indexFirst++;
      rowsense_[ind] = *senseList++;
      rhs_[ind] = *rhsList++;
      rowrange_[ind] = *rangeList++;
    }
    convertSensesToBounds_();
  }
}
Example #2
0
bool MyMoneyReport::read ( const QDomElement& e )
{
  // The goal of this reading method is 100% backward AND 100% forward
  // compatability.  Any report ever created with any version of KMyMoney
  // should be able to be loaded by this method (as long as it's one of the
  // report types supported in this version, of course)

  bool result = false;

  if (
    "REPORT" == e.tagName()
    &&
    (
      ( e.attribute ( "type" ).find ( "pivottable 1." ) == 0 )
      ||
      ( e.attribute ( "type" ).find ( "querytable 1." ) == 0 )
      ||
      ( e.attribute ( "type" ).find ( "infotable 1." ) == 0 )
    )
  )
  {
    result = true;
    clear();

    int i;
    m_name = e.attribute ( "name" );
    m_comment = e.attribute ( "comment", "Extremely old report" );

    //set report type
    if(!e.attribute ( "type" ).find ( "pivottable" )) {
      m_reportType = MyMoneyReport::ePivotTable;
    } else if(!e.attribute ( "type" ).find ( "querytable" )) {
      m_reportType = MyMoneyReport::eQueryTable;
    } else if(!e.attribute ( "type" ).find ( "infotable" )) {
      m_reportType = MyMoneyReport::eInfoTable;
    } else {
      m_reportType = MyMoneyReport::eNoReport;
    }

    // Removed the line that screened out loading reports that are called
    // "Default Report".  It's possible for the user to change the comment
    // to this, and we'd hate for it to break as a result.
    m_group = e.attribute ( "group" );
    m_id = e.attribute ( "id" );

    //check for reports with older settings which didn't have the detail attribute
    if ( e.hasAttribute ( "detail" ) )
    {
      i = kDetailLevelText.findIndex ( e.attribute ( "detail", "all" ) );
      if ( i != -1 )
        m_detailLevel = static_cast<EDetailLevel> ( i );
    } else if ( e.attribute ( "showsubaccounts", "0" ).toUInt() ) {
      //set to show all accounts
      m_detailLevel = eDetailAll;
    } else {
      //set to show the top level account instead
      m_detailLevel = eDetailTop;
    }

    m_convertCurrency = e.attribute ( "convertcurrency", "1" ).toUInt();
    m_favorite = e.attribute ( "favorite", "0" ).toUInt();
    m_tax = e.attribute ( "tax", "0" ).toUInt();
    m_investments = e.attribute ( "investments", "0" ).toUInt();
    m_loans = e.attribute ( "loans", "0" ).toUInt();
    m_includeSchedules = e.attribute ( "includeschedules", "0" ).toUInt();
    m_columnsAreDays = e.attribute ( "columnsaredays", "0" ).toUInt();
    m_includeTransfers = e.attribute ( "includestransfers", "0" ).toUInt();
    if ( e.hasAttribute ( "budget" ) )
      m_budgetId = e.attribute ( "budget" );
    m_includeBudgetActuals = e.attribute ( "includesactuals", "0" ).toUInt();
    m_includeUnusedAccounts = e.attribute ( "includeunused", "0" ).toUInt();
    m_includeForecast = e.attribute ( "includesforecast", "0" ).toUInt();
    m_includePrice = e.attribute ( "includesprice", "0" ).toUInt();
    m_includeAveragePrice = e.attribute ( "includesaverageprice", "0" ).toUInt();
    m_includeMovingAverage = e.attribute ( "includesmovingaverage", "0" ).toUInt();
    if( m_includeMovingAverage )
      m_movingAverageDays = e.attribute ( "movingaveragedays", "1" ).toUInt();

    //only load chart data if it is a pivot table
    if ( m_reportType == ePivotTable ) {
      i = kChartTypeText.findIndex ( e.attribute ( "charttype" ) );

      if ( i != -1 )
        m_chartType = static_cast<EChartType> ( i );

      //if it is invalid, set to first type
      if (m_chartType == eChartEnd)
        m_chartType = eChartLine;

      m_chartDataLabels = e.attribute ( "chartdatalabels", "1" ).toUInt();
      m_chartGridLines = e.attribute ( "chartgridlines", "1" ).toUInt();
      m_chartByDefault = e.attribute ( "chartbydefault", "0" ).toUInt();
      m_chartLineWidth = e.attribute ( "chartlinewidth", "2" ).toUInt();
    } else {
      m_chartType = static_cast<EChartType> ( 0 );
      m_chartDataLabels = true;
      m_chartGridLines = true;
      m_chartByDefault = false;
      m_chartLineWidth = 1;
    }

    QString datelockstr = e.attribute ( "datelock", "userdefined" );
    // Handle the pivot 1.2/query 1.1 case where the values were saved as
    // numbers
    bool ok = false;
    i = datelockstr.toUInt ( &ok );
    if ( !ok )
    {
      i = kDateLockText.findIndex ( datelockstr );
      if ( i == -1 )
        i = userDefined;
    }
    setDateFilter ( static_cast<dateOptionE> ( i ) );

    i = kRowTypeText.findIndex ( e.attribute ( "rowtype", "expenseincome" ) );
    if ( i != -1 )
    {
      setRowType ( static_cast<ERowType> ( i ) );
      // recent versions of KMyMoney always showed a total column for
      // income/expense reports. We turn it on for backward compatability
      // here. If the total column is turned off, the flag will be reset
      // in the next step
      if ( i == eExpenseIncome )
        m_showRowTotals = true;
    }
    if ( e.hasAttribute ( "showrowtotals" ) )
      m_showRowTotals = e.attribute ( "showrowtotals" ).toUInt();

    i = kColumnTypeText.findIndex ( e.attribute ( "columntype", "months" ) );
    if ( i != -1 )
      setColumnType ( static_cast<EColumnType> ( i ) );

    unsigned qc = 0;
    QStringList columns = QStringList::split ( ",", e.attribute ( "querycolumns", "none" ) );
    QStringList::const_iterator it_column = columns.begin();
    while ( it_column != columns.end() )
    {
      i = kQueryColumnsText.findIndex ( *it_column );
      if ( i > 0 )
        qc |= ( 1 << ( i - 1 ) );

      ++it_column;
    }
    setQueryColumns ( static_cast<EQueryColumns> ( qc ) );

    QDomNode child = e.firstChild();
    while ( !child.isNull() && child.isElement() )
    {
      QDomElement c = child.toElement();
      if ( "TEXT" == c.tagName() && c.hasAttribute ( "pattern" ) )
      {
        setTextFilter ( QRegExp ( c.attribute ( "pattern" ), c.attribute ( "casesensitive", "1" ).toUInt(), !c.attribute ( "regex", "1" ).toUInt() ), c.attribute ( "inverttext", "0" ).toUInt() );
      }
      if ( "TYPE" == c.tagName() && c.hasAttribute ( "type" ) )
      {
        i = kTypeText.findIndex ( c.attribute ( "type" ) );
        if ( i != -1 )
          addType ( i );
      }
      if ( "STATE" == c.tagName() && c.hasAttribute ( "state" ) )
      {
        i = kStateText.findIndex ( c.attribute ( "state" ) );
        if ( i != -1 )
          addState ( i );
      }
      if ( "NUMBER" == c.tagName() )
      {
        setNumberFilter ( c.attribute ( "from" ), c.attribute ( "to" ) );
      }
      if ( "AMOUNT" == c.tagName() )
      {
        setAmountFilter ( MyMoneyMoney ( c.attribute ( "from", "0/100" ) ), MyMoneyMoney ( c.attribute ( "to", "0/100" ) ) );
      }
      if ( "DATES" == c.tagName() )
      {
        QDate from, to;
        if ( c.hasAttribute ( "from" ) )
          from = QDate::fromString ( c.attribute ( "from" ), Qt::ISODate );
        if ( c.hasAttribute ( "to" ) )
          to = QDate::fromString ( c.attribute ( "to" ), Qt::ISODate );
        MyMoneyTransactionFilter::setDateFilter ( from, to );
      }
      if ( "PAYEE" == c.tagName() )
      {
        addPayee ( c.attribute ( "id" ) );
      }
      if ( "CATEGORY" == c.tagName() && c.hasAttribute ( "id" ) )
      {
        addCategory ( c.attribute ( "id" ) );
      }
      if ( "ACCOUNT" == c.tagName() && c.hasAttribute ( "id" ) )
      {
        addAccount ( c.attribute ( "id" ) );
      }
      if ( "ACCOUNTGROUP" == c.tagName() && c.hasAttribute ( "group" ) )
      {
        i = kAccountTypeText.findIndex ( c.attribute ( "group" ) );
        if ( i != -1 )
          addAccountGroup ( static_cast<MyMoneyAccount::accountTypeE> ( i ) );
      }
      child = child.nextSibling();
    }
  }
  return result;
}