int HeaderView::logicalIndexAt(lua_State * L) // ( int position ) const : int // ( const QPoint & pos ) const : int // ( int x, int y ) const : int { QHeaderView* obj = QtObject<QHeaderView>::check( L, 1); if( QPointF* r = QtValue<QPointF>::cast( L, 2 ) ) Util::push( L, obj->logicalIndexAt( r->toPoint() ) ); else if( Util::isNum( L, 3 ) ) Util::push( L, obj->logicalIndexAt( Util::toInt( L, 2), Util::toInt( L, 3) ) ); else Util::push( L, obj->logicalIndexAt( Util::toInt( L, 2) ) ); return 1; }
void MashStepTableModel::contextMenu(const QPoint &point) { QObject* calledBy = sender(); QHeaderView* hView = qobject_cast<QHeaderView*>(calledBy); int selected = hView->logicalIndexAt(point); unitDisplay currentUnit; unitScale currentScale; // Since we need to call generateVolumeMenu() two different ways, we need // to figure out the currentUnit and Scale here currentUnit = displayUnit(selected); currentScale = displayScale(selected); QMenu* menu; QAction* invoked; switch(selected) { case MASHSTEPAMOUNTCOL: menu = Brewtarget::setupVolumeMenu(parentTableWidget,currentUnit, currentScale); break; case MASHSTEPTEMPCOL: case MASHSTEPTARGETTEMPCOL: menu = Brewtarget::setupTemperatureMenu(parentTableWidget,currentUnit); break; case MASHSTEPTIMECOL: menu = Brewtarget::setupTimeMenu(parentTableWidget,currentScale); break; default: return; } invoked = menu->exec(hView->mapToGlobal(point)); if ( invoked == 0 ) return; QWidget* pMenu = invoked->parentWidget(); if ( pMenu == menu ) setDisplayUnit(selected,(unitDisplay)invoked->data().toInt()); else setDisplayScale(selected,(unitScale)invoked->data().toInt()); }
void ResTable::createHeaderPopupMenu(const QPoint& pos) { LOGDEB(("ResTable::createHeaderPopupMenu(%d, %d)\n", pos.x(), pos.y())); QHeaderView *header = tableView->horizontalHeader(); if (!header || !m_model) return; m_popcolumn = header->logicalIndexAt(pos); if (m_popcolumn < 0) return; const map<string, QString>& allfields = m_model->getAllFields(); const vector<string>& fields = m_model->getFields(); QMenu *popup = new QMenu(this); popup->addAction(tr("&Reset sort"), this, SLOT(resetSort())); popup->addSeparator(); popup->addAction(tr("&Save as CSV"), this, SLOT(saveAsCSV())); popup->addSeparator(); popup->addAction(tr("&Delete column"), this, SLOT(deleteColumn())); popup->addSeparator(); QAction *act; for (map<string, QString>::const_iterator it = allfields.begin(); it != allfields.end(); it++) { if (std::find(fields.begin(), fields.end(), it->first) != fields.end()) continue; act = new QAction(tr("Add \"%1\" column").arg(it->second), popup); act->setData(QString::fromUtf8(it->first.c_str())); connect(act, SIGNAL(triggered(bool)), this , SLOT(addColumn())); popup->addAction(act); } popup->popup(mapToGlobal(pos)); }