📄 module.cpp
字号:
QBrush brush( isThin?"white":FILL_COLOR ); QPen pen( BORDER_COLOR ); canvasRectangle->setX( x ); canvasRectangle->setY( y ); canvasRectangle->setSize( width, height ); canvasRectangle->setBrush( brush ); canvasRectangle->setPen( pen ); canvasRectangle->show(); if ( isThin ){ canvasText->setText( "" ); } else { // Now get the text and make sure that everything fits into the box. // The problem with QFontMetrics.width is that it doesn't take into // acount "\n", so we have to check on every line :( QString t = updateFont( name ); if ( isProfiling ){ QValueList< QPair< long long int, long long int > > profs = radio->getProfiling( id ); if ( profs[1].second > profValues[0].second ){ // We have something new profValues[1] = profValues[0]; profValues[0] = profs[1]; } long long int mean = profValues[0].first / profValues[0].second; long long int last = ( profValues[0].first - profValues[1].first ) / ( profValues[0].second - profValues[1].second ); // We only show data time t += "\n" + updateFont( QString( "|%1us| - %2us" ). arg( mean ).arg( last ) ); } for ( uint s=0; s<MAX_STATS_DISPLAY; s++ ){ Stats *stats = displayStats[s]; if ( stats ){ stats->update(); t += "\n" + updateFont( stats->getName() + ": " + stats->value ); } } // text position, color, ... canvasText->setText( t ); canvasText->setX( x + 5 ); canvasText->setY( y + 5 ); canvasText->setColor( TEXT_COLOR ); canvasText->setFont( canvasFont ); canvasText->setZ( 3000 ); // make sure the text doesn't appear behind the module canvasText->show(); } pen.setColor( LEG_COLOR ); brush.setColor( LEG_COLOR ); int endY = y - LEG_LENGTH; int startY = y; // top legs (inputs) if ( numberIn > 128 ) { cout << "Strange: numberIn > 128 at module.cpp:193" << endl; numberIn = 0; } for ( int posX = x + LEG_LEFT_OFFSET, i=0; i < numberIn; posX += LEG_WIDTH + legInterval, i++ ) { inputFeet.at(i)->setX( posX ); inputFeet.at(i)->setY( startY - LEG_LENGTH ); inputFeet.at(i)->show(); } startY = y + height; endY = startY + LEG_LENGTH; // bottom legs (outputs) if ( numberOut > 128 ) { cout << "Strange: numberOut > 128 at module.cpp:201" << endl; numberOut = 0; } for ( int posX = x + LEG_LEFT_OFFSET, i=0; i < numberOut; posX += LEG_WIDTH + legInterval, i++ ) { outputFeet.at(i)->setX( posX ); outputFeet.at(i)->setY( startY ); outputFeet.at(i)->show(); } visible = true;}/*******************************************************************************//* Function: getInputXPosition() *//* Description: Gives the x coordinate of the specified input port. *//* Inputs: inputNumber: port number. *//* Returns: the x coordinate of the specified input port. *//*******************************************************************************/int Module::getInputXPosition( int inputNumber ) { int linkInterval = legInterval + LEG_WIDTH; return ( x + LEG_LEFT_OFFSET + LEG_WIDTH / 2 + inputNumber * linkInterval );}/*******************************************************************************//* Function: getInputYPosition() *//* Description: Gives the y coordinate of an input port. *//* Inputs: none (all ports have the same y coordinate). *//* Returns: the y coordinate of an input port. *//*******************************************************************************/int Module::getInputYPosition() { return ( y - LEG_LENGTH );}/*******************************************************************************//* Function: getOutputXPosition() *//* Description: Gives the x coordinate of the specified output port. *//* Inputs: outputNumber: port number. *//* Returns: the x coordinate of the specified output port. *//*******************************************************************************/int Module::getOutputXPosition( int outputNumber ) { return ( this->getInputXPosition( outputNumber ) );}/*******************************************************************************//* Function: getOutputYPosition() *//* Description: Gives the y coordinate of an output port. *//* Inputs: none (all ports have the same y coordinate). *//* Returns: the y coordinate of an output port. *//*******************************************************************************/int Module::getOutputYPosition() { return ( y + height + LEG_LENGTH );}/*******************************************************************************//* Function: addInputLink() *//* Description: adds a link to the module's input links vector. *//* Inputs: link: pointer to the link to add. *//* Returns: void. *//*******************************************************************************/void Module::addInputLink( IOLink* link ) { //append a copy of the link at the end of the vector inputLinkVect.push_back( *link );}/*******************************************************************************//* Function: addOutputLink() *//* Description: adds a link to the module's output links vector. *//* Inputs: link: pointer to the link to add. *//* Returns: void. *//*******************************************************************************/void Module::addOutputLink( IOLink* link ) { //append a copy of the link at the end of the vector outputLinkVect.push_back( *link );}/*******************************************************************************//* Function: addStats() *//* Description: adds a Stats to the module's Stats list. *//* Inputs: stats: pointer to the Stat. *//* Returns: void. *//*******************************************************************************/void Module::addStats( Stats* stats ) { statsList.append( stats );}/*******************************************************************************//* Function: addConfig() *//* Description: adds a Config to the module's Config list. *//* Inputs: config: pointer to the Config. *//* Returns: void. *//*******************************************************************************/void Module::addConfig( Config* config ) { configList.append( config );}/*******************************************************************************//* Function: addPort() *//* Description: adds a Stats to the module's Port list. *//* Inputs: port: pointer to the port. *//* Returns: void. *//*******************************************************************************/void Module::addPort( Port* port ) { portList.append( port );}/*******************************************************************************//* Function: setText() *//* Description: displays "variableName: variableValue" on the module. *//* Inputs: variableName: name of the variable that is monitored. *//* Returns: void. *//*******************************************************************************/void Module::setText( QString variableName ) { // get stats Stats *stats = NULL; int listSize = statsList.count(); for ( int i = 0; i < listSize; i++ ) { if ( variableName == statsList.at( i )->getName() ) { stats = statsList.at( i ); break; } } if ( !stats ){ cout << "Error: asked for " << variableName << " which doesn't exist..\n"; return; } for ( int i=MAX_STATS_DISPLAY-1; i>0; i-- ){ displayStats[i] = displayStats[i-1]; } displayStats[0] = stats;}void Module::processData(){ cout << "going to process modules " << id << endl; radio->processData( id );}void Module::plotData( int id, enum blockType_e bt ){ if ( bt == block_stats ) { // show the (int) value ON the module int count = statsList.count(); if ( id >= count ) { PRINT( "HOUSTON WE HAVE A PROBLEM" ); return ; } Stats* stats = statsList.at( id ); if ( stats->isValue() && stats->isShown() ) { // show the value on the module setText( stats->getName() ); return ; } } // else open a new window with 2D-graph QDesktopWidget *d = QApplication::desktop(); int desktopWidth = d->width(); // returns desktop width MainSub *frame = new MainSub( 0, 0, Qt::WType_Dialog ); frame->move( desktopWidth - 500, 0 ); QWidget *mainW = new QWidget( frame ); frame->setCentralWidget( mainW ); QVBoxLayout *vBox = new QVBoxLayout( mainW, 1, 1, "vertical" ); image = NULL; // Initialise the graphical display switch ( bt ) { case block_stats: Stats *s; s = statsList.at( id ); if ( s->getType() == NO_SIGNAL ){ // We have an image image = new Image( mainW, s->radio, s->module_id, s->id ); } else { graphic = new Show( name, s, mainW ); } break; case block_port: graphic = new Show( name, portList.at( id ), mainW ); break; default: return ; } if ( image ){ vBox->addWidget( image ); } else { // It is not an image, so it's a plot... vBox->addWidget( graphic ); graphic->AddTypes( vBox ); graphic->AddExport( vBox ); connect( frame, SIGNAL( closing() ), graphic, SLOT( close() ) ); frame->resize( 400, 400 ); } frame->show();}/** * Show the configuration-part of this module */void Module::showConfig(){ if ( !configWin ){ configWin = new ConfWind( this ); configWin->show(); } else { // Resurrecting config-window, as it's not really closed... configWin->show(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -