Ejemplo n.º 1
0
///
//  Reset to default widget state
//
void ProjectChooser::resetAll()
{
    WAbstractItemModel *model = mProjectSelectionBox->model();

    mProjectSelectionBox->clear();
    mProjectSelectionBox->addItem("Default (All MRIDs)");
    model->setData(model->index(0, 0), boost::any(std::string("")), UserRole);
    mProjectSelectionBox->setCurrentIndex(0);
    mDeleteButton->setEnabled(false);


    std::string userProjectDir = getConfigOptionsPtr()->GetProjectDir() + "/" +
                                 getCurrentUserName();
    try
    {
        for(directory_iterator dirIter(userProjectDir); dirIter != directory_iterator(); ++dirIter)
        {
            const string extension = dirIter->path().extension().string();
            if (extension == ".xml")
            {
                mProjectSelectionBox->addItem(dirIter->path().string());
            }
        }
    }
    catch(...)
    {
        // Empty directory, which is fine
    }
}
Ejemplo n.º 2
0
void WAbstractItemModel::dropEvent(const WDropEvent& e, DropAction action,
				   int row, int column,
				   const WModelIndex& parent)
{
  // TODO: For now, we assumes selectionBehavior() == RowSelection !

  WItemSelectionModel *selectionModel
    = dynamic_cast<WItemSelectionModel *>(e.source());
  if (selectionModel) {
    WAbstractItemModel *sourceModel = selectionModel->model();

    /*
     * (1) Insert new rows (or later: cells ?)
     */
    if (action == MoveAction || row == -1) {
      if (row == -1)
	row = rowCount(parent);

      insertRows(row, selectionModel->selectedIndexes().size(), parent);
    }

    /*
     * (2) Copy data
     */
    WModelIndexSet selection = selectionModel->selectedIndexes();

    int r = row;
    for (WModelIndexSet::const_iterator i = selection.begin();
	 i != selection.end(); ++i) {
      WModelIndex sourceIndex = *i;
      if (selectionModel->selectionBehavior() == SelectRows) {
	WModelIndex sourceParent = sourceIndex.parent();

	for (int col = 0; col < sourceModel->columnCount(sourceParent); ++col) {
	  WModelIndex s = sourceModel->index(sourceIndex.row(), col,
					     sourceParent);
	  WModelIndex d = index(r, col, parent);
	  copyData(sourceModel, s, this, d);
	}

	++r;
      } else {
	  
      }
    }

    /*
     * (3) Remove original data
     */
    if (action == MoveAction) {
      while (!selectionModel->selectedIndexes().empty()) {
	WModelIndex i = Utils::last(selectionModel->selectedIndexes());

	sourceModel->removeRow(i.row(), i.parent());
      }
    }
  }
}
Ejemplo n.º 3
0
void gdImageCustomItem::onClicked()
{
  WAbstractItemModel* model = const_cast<WAbstractItemModel*>(index_.model());
  if ( m_bFirstRowReserved )
    if ( index_.row() == 0 )
      return;
  // TODO : remplacer par un event
  model->removeRows(index_.row(), 1);
}
Ejemplo n.º 4
0
void WItemDelegate::onCheckedChange(IndexCheckBox *cb) const
{
  WAbstractItemModel *model
    = const_cast<WAbstractItemModel *>(cb->index().model());

  if (cb->isTristate())
    model->setData(cb->index(), boost::any(cb->checkState()), CheckStateRole);
  else
    model->setData(cb->index(), boost::any(cb->isChecked()), CheckStateRole);
}
void gdDoubleSpinBoxCustomItem::onChanged()
{
  if ( m_bOnChange ) return;
  m_bOnChange = true;
  WAbstractItemModel*  model = const_cast<WAbstractItemModel*>(m_idx.model());
  double val = m_spb->value();
  model->setData(m_idx, gdcore_double2string(val, m_spb->decimals()));
  model->setData(m_idx, val, UserRole);
  m_bOnChange = false;
}
Ejemplo n.º 6
0
// Updates the model with the selected value
void gdSqlComboBoxCustomItem::onChanged()
{
  long selId = m_cbb->currentIndex();
  if ( m_bDebug )
    wApp->log("notice") << " gdSqlComboBoxCustomItem::onChanged selId : " << selId;
  WAbstractItemModel*  model = const_cast<WAbstractItemModel*>(m_idx.model());
  long k_id = asNumber(m_pCbbDelModel->data(selId, 0, UserRole));
  if ( m_bDebug )
    wApp->log("notice") << " gdSqlComboBoxCustomItem::onChanged k_id : " << k_id;
  model->setData(m_idx, k_id, UserRole);
}
Ejemplo n.º 7
0
///
//  Load button clicked [slot]
//
void ProjectChooser::loadClicked()
{
    if (mProjectSelectionBox->currentIndex() < 0)
            return;

    WAbstractItemModel *model = mProjectSelectionBox->model();
    boost::any userData = model->data(model->index(mProjectSelectionBox->currentIndex(), 0), DisplayRole);
    std::string result;
    if (!userData.empty())
    {
        result =  boost::any_cast<WString>(userData).toUTF8();
    }
    mProjectChosen.emit(result);
}
Ejemplo n.º 8
0
  void handleFinish(DialogCode result)
  {
    if (result == WDialog::Accepted) {
      /*
       * Update the model with data from the edit widgets.
       *
       * You will want to do some validation here...
       *
       * Note that we directly update the source model to avoid
       * problems caused by the dynamic sorting of the proxy model,
       * which reorders row numbers, and would cause us to switch to editing
       * the wrong data.
       */
      WAbstractItemModel *m = model_;
      int modelRow = item_.row();

      WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
      if (proxyModel) {
	m = proxyModel->sourceModel();
	modelRow = proxyModel->mapToSource(item_).row();
      }

      m->setData(modelRow, 1, boost::any(nameEdit_->text()));
      m->setData(modelRow, 2, boost::any(typeEdit_->currentText()));
      m->setData(modelRow, 3, boost::any(boost::lexical_cast<int>
					 (sizeEdit_->text().toUTF8())));
      m->setData(modelRow, 4, boost::any(createdPicker_->date()));
      m->setData(modelRow, 5, boost::any(modifiedPicker_->date()));
    }

    delete this;
  }
Ejemplo n.º 9
0
void PriceEditDialog::handleFinish(DialogCode result)
{
    if (result == WDialog::Accepted)
    {
        /*
         * Update the model with data from the edit widgets.
         *
         * You will want to do some validation here...
         *
         * Note that we directly update the source model to avoid
         * problems caused by the dynamic sorting of the proxy model,
         * which reorders row numbers, and would cause us to switch to editing
         * the wrong data.
         */

        if(m_chbCostEnabled->isChecked() && m_chbPercentEnabled->isChecked())
        {
            WMessageBox::show("Error", WString(tr("msg.ambiguous.select")), Ok);
            return;
        }


        /*! При выставленном варианте расчета статический Поле цена не доступна
            1) Вариант расчета 0 Динамический  1 Статический
            2) Устанавливается Цена или процент
            3) Процента или Цена

        */
        WAbstractItemModel *m = m_model;
        //int id =
        int modelRow = m_item.row();
        int valueType = 0;
        int modifyStatic = 0;
        //int staticValue = 0;
        double value = 0.00;
        //char number[50];

        WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
        if (proxyModel)
        {
            m = proxyModel->sourceModel();
            modelRow = proxyModel->mapToSource(m_item).row();
        }
            //modelRow++;



        if(m_chbPercentEnabled->isChecked())
        {
            valueType = 2;
            //sprintf(number,"%.2f%%",boost::lexical_cast<double>(m_lePercent->text().toUTF8()));
            //m->setData(modelRow, 3, boost::any(std::string("0.00")));
            m->setData(modelRow, 5, boost::any(m_lePercent->text().toUTF8()+"%"));/// Процент
            m->setData(modelRow, 2, boost::any(value = boost::lexical_cast<double>(m_lePercent->text().toUTF8())),UserRole);/// Процент

        }else if(m_chbCostEnabled->isChecked())
        {
            valueType = 1;
            //m->setData(modelRow, 3, boost::any(boost::lexical_cast<double>(m_leCost->text().toUTF8())));/// Цена
            //sprintf(number,"%.2f%%",boost::lexical_cast<double>(m_leCost->text().toUTF8()));
            //m->setData(modelRow, 2, boost::any(std::string("0.00%")));
            m->setData(modelRow, 6, boost::any(m_leCost->text().toUTF8()));/// Цена
            m->setData(modelRow, 2, boost::any(value = boost::lexical_cast<double>(m_leCost->text().toUTF8())),UserRole);/// Цена
        }else{
            if(atof(m_leCost->text().toUTF8().c_str()) || atof(m_lePercent->text().toUTF8().c_str()))
                WMessageBox::show("Error", WString(tr("msg.notselected.valuetype")), Ok);

        }

        if(m_chbModifyStatic->isChecked())
            modifyStatic = 1;
        //log("info")<<" Percetn "<<valueType<<" Dinamic "<<m_rbGroup->checkedId();
        m->setData(modelRow, 3, boost::any(valueType),UserRole); /// Value type Процент / Цена
        m->setData(modelRow, 4, boost::any(m_rbGroup->checkedId()),UserRole); /// PriceType Динамический статический
        m->setData(modelRow, 5, boost::any(modifyStatic),UserRole); /// Изменять фиксированные цены
        m->setData(modelRow, 6, boost::any(m_dpModified->date()),UserRole);
        m->setData(modelRow, 7, boost::any(m_roundingMethod->currentIndex()+1),UserRole);

        int priceType = ((m_rbGroup->checkedId()-1)<<1) | (valueType-1);
        bool changeFixed = false;
        WDate modifiDate = WDate::currentDate();

#ifdef DEBUG
        log("info")<<"updateUserPrice(m_id "<<m_id<<",valueType "<<valueType<<",value "<<value<<",priceType "<<priceType<<",changeFixed "<<changeFixed<<",modifiDate "<<modifiDate.toString()<<" rounding "<<m_roundingMethod->currentIndex()+1<<" ) "<<__LINE__;
#endif

        ((Portal *)WApplication::instance())->getSession()->updateUserPrice(m_id,valueType,value,priceType,changeFixed,modifiDate,m_roundingMethod->currentIndex()+1);
    }

    delete this;
}
Ejemplo n.º 10
0
TimeSeriesExample::TimeSeriesExample(Wt::WContainerWidget *parent):
  WContainerWidget(parent)
{
  new WText(WString::tr("scatter plot"), this);

  WAbstractItemModel *model = readCsvFile(
    WApplication::appRoot() + "timeseries.csv", this);

  if (!model)
    return;

  /*
   * Parses the first column as dates, to be able to use a date scale
   */
  for (int i = 0; i < model->rowCount(); ++i) {
    WString s = asString(model->data(i, 0));
    WDate d = WDate::fromString(s, "dd/MM/yy");
    model->setData(i, 0, d);
  }

  // Show a view that allows editing of the model.
  WContainerWidget *w = new WContainerWidget(this);
  WTableView *table = new WTableView(w);

  table->setMargin(10, Top | Bottom);
  table->setMargin(WLength::Auto, Left | Right);

  table->setModel(model);
  table->setSortingEnabled(false); // Does not make much sense for time series
  table->setColumnResizeEnabled(true);
  table->setSelectionMode(NoSelection);
  table->setAlternatingRowColors(true);
  table->setColumnAlignment(0, AlignCenter);
  table->setHeaderAlignment(0, AlignCenter);
  table->setRowHeight(22);

  // Editing does not really work without Ajax, it would require an
  // additional button somewhere to confirm the edited value.
  if (WApplication::instance()->environment().ajax()) {
    table->resize(800, 20 + 5*22);
    table->setEditTriggers(WAbstractItemView::SingleClicked);
  } else {
    table->resize(800, 20 + 5*22 + 25);
    table->setEditTriggers(WAbstractItemView::NoEditTrigger);
  }

  WItemDelegate *delegate = new WItemDelegate(this);
  delegate->setTextFormat("%.1f");
  table->setItemDelegate(delegate);
  table->setItemDelegateForColumn(0, new WItemDelegate(this));

  table->setColumnWidth(0, 80);
  for (int i = 1; i < model->columnCount(); ++i)
    table->setColumnWidth(i, 90);

  /*
   * Create the scatter plot.
   */
  WCartesianChart *chart = new WCartesianChart(this);
  //chart->setPreferredMethod(WPaintedWidget::PngImage);
  //chart->setBackground(gray);
  chart->setModel(model);        // set the model
  chart->setXSeriesColumn(0);    // set the column that holds the X data
  chart->setLegendEnabled(true); // enable the legend

  chart->setType(ScatterPlot);            // set type to ScatterPlot
  chart->axis(XAxis).setScale(DateScale); // set scale of X axis to DateScale

  // Automatically layout chart (space for axes, legend, ...)
  chart->setAutoLayoutEnabled();

  /*
   * Add first two columns as line series
   */
  for (int i = 1; i < 3; ++i) {
    WDataSeries s(i, LineSeries);
    s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
    chart->addSeries(s);
  }

  chart->resize(800, 400); // WPaintedWidget must be given explicit size

  chart->setMargin(10, Top | Bottom);            // add margin vertically
  chart->setMargin(WLength::Auto, Left | Right); // center horizontally

  new ChartConfig(chart, this);
}
Ejemplo n.º 11
0
CategoryExample::CategoryExample(Wt::WContainerWidget *parent):
  WContainerWidget(parent)
{
  new WText(WString::tr("category chart"), this);

  WAbstractItemModel *model
    = readCsvFile(WApplication::appRoot() + "category.csv", this);

  if (!model)
    return;

  // Show a view that allows editing of the model.
  WContainerWidget *w = new WContainerWidget(this);
  WTableView *table = new WTableView(w);

  table->setMargin(10, Top | Bottom);
  table->setMargin(WLength::Auto, Left | Right);

  table->setModel(model);
  table->setSortingEnabled(true);
  table->setColumnResizeEnabled(true);
  // table->setSelectionMode(ExtendedSelection);
  table->setAlternatingRowColors(true);
  table->setColumnAlignment(0, AlignCenter);
  table->setHeaderAlignment(0, AlignCenter);
  table->setRowHeight(22);

  // Editing does not really work without Ajax, it would require an
  // additional button somewhere to confirm the edited value.
  if (WApplication::instance()->environment().ajax()) {
    table->resize(600, 20 + 5*22);
    table->setEditTriggers(WAbstractItemView::SingleClicked);
  } else {
    table->resize(600, WLength::Auto);
    table->setEditTriggers(WAbstractItemView::NoEditTrigger);
  }

  // We use a single delegate for all items which rounds values to
  // the closest integer value.
  WItemDelegate *delegate = new WItemDelegate(this);
  delegate->setTextFormat("%.f");
  table->setItemDelegate(delegate);

  table->setColumnWidth(0, 80);
  for (int i = 1; i < model->columnCount(); ++i)
    table->setColumnWidth(i, 120);

  /*
   * Create the category chart.
   */
  WCartesianChart *chart = new WCartesianChart(this);
  // chart->setPreferredMethod(WPaintedWidget::PngImage);
  chart->setModel(model);        // set the model
  chart->setXSeriesColumn(0);    // set the column that holds the categories
  chart->setLegendEnabled(true); // enable the legend

  // Automatically layout chart (space for axes, legend, ...)
  chart->setAutoLayoutEnabled(true);

  /*
   * Add all (but first) column as bar series
   */
  for (int i = 1; i < model->columnCount(); ++i) {
    WDataSeries s(i, BarSeries);
    s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
    chart->addSeries(s);
  }

  chart->resize(800, 400);

  chart->setMargin(10, Top | Bottom);
  chart->setMargin(WLength::Auto, Left | Right);

  /*
   * Provide a widget to manipulate chart properties
   */
  new ChartConfig(chart, this);
}