Example #1
0
  /*! \brief Creates the file table view (a WTableView)
   */
  WTableView *fileView() {
    WTableView *tableView = new WTableView();

    tableView->setAlternatingRowColors(true);

    tableView->setModel(fileFilterModel_);
    tableView->setSelectionMode(ExtendedSelection);
    tableView->setDragEnabled(true);

    tableView->setColumnWidth(0, 100);
    tableView->setColumnWidth(1, 150);
    tableView->setColumnWidth(2, 100);
    tableView->setColumnWidth(3, 60);
    tableView->setColumnWidth(4, 100);
    tableView->setColumnWidth(5, 100);

    WItemDelegate *delegate = new WItemDelegate(this);
    delegate->setTextFormat(FileModel::dateDisplayFormat);
    tableView->setItemDelegateForColumn(4, delegate);
    tableView->setItemDelegateForColumn(5, delegate);

    tableView->setColumnAlignment(3, AlignRight);
    tableView->setColumnAlignment(4, AlignRight);
    tableView->setColumnAlignment(5, AlignRight);

    tableView->sortByColumn(1, AscendingOrder);

    tableView->doubleClicked().connect(this, &TreeViewDragDrop::editFile);

    fileView_ = tableView;

    return tableView;
  }
Example #2
0
void HelloApplication::generation_cb(WStandardItemModel* obs_model, std::string txt)
{
    observations_table->setModel(obs_model);

    output_->setText(txt);

    dbo::QueryModel< dbo::ptr< evo_period > >* period_mod = (dbo::QueryModel< dbo::ptr< evo_period > >*)period_table->model();
    period_mod->reload();
    dbo::QueryModel< dbo::ptr< generation > >* generation_mod = (dbo::QueryModel< dbo::ptr< generation > >*)generation_table->model();
    generation_mod->reload();

    triggerUpdate();
}
Example #3
0
PieExample::PieExample(WContainerWidget *parent):
  WContainerWidget(parent)
{
  new WText(WString::tr("pie chart"), this);

  WStandardItemModel *model = new WStandardItemModel(this);
  model->setItemPrototype(new NumericItem());
  
  //headers
  model->insertColumns(model->columnCount(), 2);
  model->setHeaderData(0, WString("Item"));
  model->setHeaderData(1, WString("Sales"));

  //data
  model->insertRows(model->rowCount(), 6);
  int row = 0;
  model->setData(row, 0, WString("Blueberry"));
  model->setData(row, 1, 120);
  // model->setData(row, 1, WString("Blueberry"), ToolTipRole);
  row++;
  model->setData(row, 0, WString("Cherry"));
  model->setData(row, 1, 30);
  row++;
  model->setData(row, 0, WString("Apple"));
  model->setData(row, 1, 260);
  row++;
  model->setData(row, 0, WString("Boston Cream"));
  model->setData(row, 1, 160);
  row++;
  model->setData(row, 0, WString("Other"));
  model->setData(row, 1, 40);
  row++;
  model->setData(row, 0, WString("Vanilla Cream"));
  model->setData(row, 1, 120);
  row++;

  //set all items to be editable and selectable
  for (int row = 0; row < model->rowCount(); ++row)
    for (int col = 0; col < model->columnCount(); ++col)
      model->item(row, col)->setFlags(ItemIsSelectable | ItemIsEditable);

  WContainerWidget *w = new WContainerWidget(this);
  WTableView* table = new WTableView(w);

  table->setMargin(10, Top | Bottom);
  table->setMargin(WLength::Auto, Left | Right);
  table->setSortingEnabled(true);
  table->setModel(model);
  table->setColumnWidth(1, 100);
  table->setRowHeight(22);

  if (WApplication::instance()->environment().ajax()) {
    table->resize(150 + 100 + 14, 20 + 6 * 22);
    table->setEditTriggers(WAbstractItemView::SingleClicked);
  } else {
    table->resize(150 + 100 + 14, WLength::Auto);
    table->setEditTriggers(WAbstractItemView::NoEditTrigger);    
  }

  /*
   * Create the pie chart.
   */
  WPieChart *chart = new WPieChart(this);
  chart->setModel(model);       // set the model
  chart->setLabelsColumn(0);    // set the column that holds the labels
  chart->setDataColumn(1);      // set the column that holds the data

  // configure location and type of labels
  chart->setDisplayLabels(Outside | TextLabel | TextPercentage);

  // enable a 3D and shadow effect
  chart->setPerspectiveEnabled(true, 0.2);
  chart->setShadowEnabled(true);

  // explode the first item
  chart->setExplode(0, 0.3);

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

  chart->setMargin(10, Top | Bottom);            // add margin vertically
  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
}
Example #4
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);
}
Example #5
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);
}
Example #6
0
WTornetApplication::WTornetApplication( const Wt::WEnvironment& env )
:WApplication(env){
    setTitle("Tornet"); 
    setCssTheme( "polished" );
    wlog("...");
  try {
    auto cont = new Wt::WContainerWidget(  );

    Wt::WTableView* t = new Wt::WTableView(cont);
    t->setAlternatingRowColors(true);
    t->setSortingEnabled(true);

    WUserItemModel* uim = new WUserItemModel( tn::tornet_app::instance()->get_node()->get_peers(), t );
    
    auto proxy = new Wt::WSortFilterProxyModel(this);
    proxy->setSourceModel(uim);
    t->setModel( proxy );

    root()->addWidget( new Wt::WText( "Publish File or Site" ) );
    my->path_edit = new Wt::WLineEdit(root());
    my->path_edit->setWidth( 300 );
    my->path_edit->setFocus();

    auto publish = new Wt::WPushButton( "Publish", root() );
    root()->addWidget( new Wt::WBreak() );
    publish->clicked().connect(this, &WTornetApplication::onPublish ); 
    my->path_edit->enterPressed().connect( this, &WTornetApplication::onPublish );


    root()->addWidget( new Wt::WBreak() );
    root()->addWidget( new WText( "Peers" ) );
    root()->addWidget( t );

    my->link_model = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<tn::PublishedResource> >(this);
    my->link_model->setQuery( my->session.db().find<tn::PublishedResource>() );
    my->link_model->addAllFieldsAsColumns();

    my->links = new WTableView();
    my->links->setModel( my->link_model );
    root()->addWidget( new Wt::WBreak() );
    root()->addWidget( new WText( "Files" ) );
    root()->addWidget(my->links);

    root()->addWidget( new Wt::WBreak() );
    root()->addWidget( new WText( "Sites" ) );
    root()->addWidget( new Wt::WBreak() );

    root()->addWidget( new Wt::WText( "Domain " ) );
    my->site_domain_edit = new Wt::WLineEdit(root());
    my->site_domain_edit->setWidth(300);

    root()->addWidget( new Wt::WText( "Document Root  " ) );
    my->site_path_edit = new Wt::WLineEdit(root());
    my->site_path_edit->setWidth(450);


    auto publish_site = new Wt::WPushButton( "Publish Site", root() );
    publish_site->clicked().connect(this, &WTornetApplication::onPublishSite ); 
    root()->addWidget( new Wt::WBreak() );

    auto ts_model = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<tn::Domain> >(this);
    ts_model->setQuery( my->session.db().find<tn::Domain>() );
    ts_model->addAllFieldsAsColumns();

    WTableView* tsv = new WTableView();
    tsv->setModel( ts_model );
    root()->addWidget( new Wt::WBreak() );
    root()->addWidget( new WText( "Domains" ) );
    root()->addWidget(tsv);

  } catch ( ... ) {
    elog( "%s", fc::current_exception().diagnostic_information().c_str() );
  }
}