void PlotDataGroupWidget::tableContextMenu(const QPoint& pos) { PlotDataGroup* plotDataGroup = dynamic_cast<PlotDataGroup*>(processor_); QModelIndex index = table_->indexAt(pos); contextMenuTable_->clear(); addFunctionMenu_->clear(); averageFunctionMenu_->clear(); histogramFunctionMenu_->clear(); PlotData* data = const_cast<PlotData*>(plotDataGroup->getPlotData()); QAction* newAct; QList<QVariant>* qlist = new QList<QVariant>(); std::string s; s = "Reset All"; newAct = new QAction(QString::fromStdString(s),this); contextMenuTable_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(selectResetAll())); s = "Reset Last"; newAct = new QAction(QString::fromStdString(s),this); contextMenuTable_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(selectResetLast())); contextMenuTable_->addSeparator(); bool found = false; s = "Delete Function"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(0); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); for(size_t i=0; i< aggregatedcolumns.size(); ++i){ if(index.column() == aggregatedcolumns.at(i).first){ found = true; break; } } if (!found || aggregatedcolumns.size() == 0 || data->getColumnType(index.column()) == PlotBase::EMPTY) { newAct->setEnabled(false); } else { newAct->setEnabled(true); } qlist->clear(); addFunctionMenu_->addSeparator(); s = "Arithmetic"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::AVERAGE)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); averageFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Geometric"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::GEOMETRICMEAN)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); averageFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Harmonic"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::HARMONICMEAN)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); averageFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); addFunctionMenu_->addMenu(averageFunctionMenu_); s = "Count"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::COUNT)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Max"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MAX)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Median"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MEDIAN)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Min"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MIN)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Mode"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MODE)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Standard Deviation"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::STANDARDDEVIATION)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Sum"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::SUM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Variance"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::VARIANCE)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); addFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); addFunctionMenu_->addSeparator(); //Histogramm-Menu s = "Count"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::COUNTHISTOGRAM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); histogramFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Min"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MINHISTOGRAM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); histogramFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Max"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MAXHISTOGRAM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); histogramFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Median"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::MEDIANHISTOGRAM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); histogramFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); s = "Sum"; newAct = new QAction(QString::fromStdString(s),this); qlist->push_back(static_cast<int>(AggregationFunction::SUMHISTOGRAM)); qlist->push_back(index.column()); newAct->setData(QVariant(*qlist)); histogramFunctionMenu_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(addFunction())); qlist->clear(); addFunctionMenu_->addMenu(histogramFunctionMenu_); if (data->getColumnType(index.column()) != PlotBase::NUMBER) { addFunctionMenu_->setEnabled(false); } else { addFunctionMenu_->setEnabled(true); } contextMenuTable_->addMenu(addFunctionMenu_); s = "Group By"; newAct = new QAction(QString::fromStdString(s),this); newAct->setData(QVariant(index.column())); contextMenuTable_->addAction(newAct); QObject::connect(newAct,SIGNAL(triggered()),this,SLOT(groupby())); for(size_t i=0; i< aggregatedcolumns.size(); ++i){ if(index.column() == aggregatedcolumns.at(i).first){ found = true; break; } } if (found || aggregatedcolumns.size() == 0 || data->getColumnType(index.column()) == PlotBase::EMPTY) { newAct->setEnabled(false); } else { newAct->setEnabled(true); } qlist->clear(); contextMenuTable_->popup(table_->mapToGlobal(pos)); delete qlist; }
auto operator()(Container&& container) const { // explicit return type in lambda so reference types are preserved return imap([](auto&& group) -> impl::iterator_deref<Container> { return *std::begin(group.second); }, groupby(std::forward<Container>(container))); }
/// Evaluate the query condition where on the data records in directory /// datadir. Make use of the ibis::table interface. It retrieves the /// values of the first column as strings after evaluating the query /// conditions. void tester::query(const char *datadir, const char *where) { if (datadir == 0 || where == 0 || *datadir == 0 || *where == 0) return; std::auto_ptr<ibis::table> table(ibis::table::create(datadir)); if (table.get() == 0) { LOGGER(ibis::gVerbose >= 0) << "failed to load table from " << datadir; return; } if (table->name() == 0 || *(table->name()) == 0) { LOGGER(ibis::gVerbose >= 0) << "failed to find any data records in directory " << datadir; return; } if (table->nColumns() == 0) { LOGGER(ibis::gVerbose >= 0) << "Table " << table->name() << " in " << datadir << " is empty"; return; } ibis::table::stringArray cnames = table->columnNames(); if (cnames.empty()) { LOGGER(ibis::gVerbose >= 0) << "failed to retrieve column names from table " << table->name() << " in " << datadir; return; } std::string selall = cnames.front(); for (unsigned j = 1; j < cnames.size(); ++ j) { selall += ", "; selall += cnames[j]; } // create in-memory table to process where std::auto_ptr<ibis::table> inmemory(table->select(selall.c_str(), "1=1")); if (inmemory.get() == 0) { LOGGER(ibis::gVerbose >= 0) << "failed to select all rows from table " << table->name(); return; } if (ibis::gVerbose > 0) { // an extra test with group-by std::auto_ptr<ibis::table> groupby(inmemory->groupby(cnames.front())); if (groupby.get() == 0) { LOGGER(ibis::gVerbose > 0) << "failed to evaluate groupby(" << cnames.front() << " on table " << inmemory->name(); } else { std::cout << "\nThe result of groupby(" << cnames.front() << ")\n"; groupby->dump(std::cout); std::cout << std::endl; } } std::string sel1 = cnames.front(); sel1 += ", count(*)"; std::auto_ptr<ibis::table> select(inmemory->select(sel1.c_str(), where)); if (select.get() == 0) { LOGGER(ibis::gVerbose >= 0) << "failed to select \"" << where << "\" on table" << inmemory->name(); return; } std::cout << "Number of rows produced by \"SELECT " << sel1 << " WHERE " << where << "\": " << select->nRows() << std::endl; select->dump(std::cout); } // tester::query