KWStatisticsDialog::KWStatisticsDialog( QWidget *parent, KWDocument *document ) : KDialogBase(parent, "statistics", true, i18n("Statistics"),KDialogBase::Ok, KDialogBase::Ok, false ) { QWidget *page = new QWidget( this ); setMainWidget(page); QVBoxLayout *topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); QTabWidget *tab = new QTabWidget( page ); QFrame *pageAll = 0; QFrame *pageGeneral = 0; QFrame *pageSelected = 0; for (int i=0; i < 7; ++i) { m_resultLabelAll[i] = 0; m_resultLabelSelected[i] = 0; if ( i < 6 ) m_resultGeneralLabel[i]=0; } m_doc = document; m_parent = parent; m_canceled = true; // add Tab "General" pageGeneral = new QFrame( this ); tab->addTab( pageGeneral, i18n( "General" ) ); addBoxGeneral( pageGeneral, m_resultGeneralLabel ); calcGeneral( m_resultGeneralLabel ); // add Tab "All" pageAll = new QFrame( this ); tab->addTab( pageAll, i18n( "Text" ) ); addBox( pageAll, m_resultLabelAll, true ); m_canceled = true; pageSelected = new QFrame( this ); tab->addTab( pageSelected, i18n( "Selected Text" ) ); // let's see if there's selected text bool b = docHasSelection(); tab->setTabEnabled(pageSelected, b); if ( b ) { addBox( pageSelected, m_resultLabelSelected, false); // assign results to 'selected' tab. if ( !calcStats( m_resultLabelSelected, true,true ) ) return; if ( !calcStats( m_resultLabelAll, false,false ) ) return; showPage( 2 ); } else { // assign results if ( !calcStats( m_resultLabelAll, false, false ) ) return; showPage( 1 ); } topLayout->addWidget( tab ); m_canceled = false; }
void TransactionWidget::loadTransactions( const QString &str ) { table->Clear(); startLineEdit->clear(); QString ans = str.trimmed(); if( ans.isEmpty() || ans.isNull() ) return; QStringList list = ans.split("\n"); if( list.count() <= 0 ) return; if( ans.indexOf("\t") < 0 && ans.indexOf("\n") < 0 ) { bool ok = false; pCount = list.first().toInt(&ok); if( !ok ) return; if( state >= pageList.count() ) return; if( pCount == 0 ) { if( state == 1 ) calcStats(); //loadAccountSaldoRequest(); return; } pageList[state]->pCount = pCount; buttons->setEnabled( pageList[state]->pCount > 1 ? true : false ); loadTransactionsRequest(); return; } table->loadData( str ); table->setEnabled( true ); table->setFocus(); if( state == 1 && !saldoLoaded ) calcStats(); //loadAccountSaldoRequest(); changeActionsEnabled(); if( !load ) { QDate date = getLastDate(); dateEdit->setDate( date ); endDateEdit->setDate( date ); date = date.addDays(-10); startDateEdit->setDate( date ); } load = true; }
void Connection::doSetup() { qDebug() << Q_FUNC_INFO << thread(); /* New connections can be created from other thread contexts, such as when AudioEngine calls getIODevice.. - we need to ensure that connections and their associated sockets are running in the same thread as the servent. HINT: export QT_FATAL_WARNINGS=1 helps to catch these kind of errors. */ if( QThread::currentThread() != m_servent->thread() ) { // Connections should always be in the same thread as the servent. qDebug() << "Fixing thead affinity..."; moveToThread( m_servent->thread() ); qDebug() << Q_FUNC_INFO << thread(); } //stats timer calculates BW used by this connection m_statstimer = new QTimer; m_statstimer->moveToThread( this->thread() ); m_statstimer->setInterval( 1000 ); connect( m_statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) ); m_statstimer->start(); m_statstimer_mark.start(); m_sock->moveToThread( thread() ); connect( m_sock.data(), SIGNAL( bytesWritten( qint64 ) ), SLOT( bytesWritten( qint64 ) ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( disconnected() ), SLOT( socketDisconnected() ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( error( QAbstractSocket::SocketError ) ), SLOT( socketDisconnectedError( QAbstractSocket::SocketError ) ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( readyRead() ), SLOT( readyRead() ), Qt::QueuedConnection ); // if connection not authed/setup fast enough, kill it: QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authCheckTimeout() ) ); if( outbound() ) { Q_ASSERT( !m_firstmsg.isNull() ); sendMsg( m_firstmsg ); } else { sendMsg( Msg::factory( PROTOVER, Msg::SETUP ) ); } // call readyRead incase we missed the signal in between the servent disconnecting and us // connecting to the signal - won't do anything if there are no bytesAvailable anyway. readyRead(); }
void KWStatisticsDialog::slotRefreshValue(bool state) { m_canceled = true; // let's see if there's selected text bool b = docHasSelection(); if ( b ) { if ( !calcStats( m_resultLabelSelected, true, true ) ) return; if ( !calcStats( m_resultLabelAll, false, state ) ) return; } else { // assign results if ( !calcStats( m_resultLabelAll, false, state ) ) return; } m_canceled = false; }
/****************************************************************************** * calculate tree statistics *****************************************************************************/ void calcStats(BSPNode *node, int depth, int &noLeafs, gfxReal &avgDepth, gfxReal &triPerLeaf,int &totalTris) { if(node->members != NULL) { totalTris += node->members->size(); } //depth = 15; // DBEUG! if( (node->child[0]==NULL) && (node->child[1]==NULL) ) { // leaf noLeafs++; avgDepth += depth; triPerLeaf += node->members->size(); } else { for(int i=0;i<2;i++) calcStats(node->child[i], depth+1, noLeafs, avgDepth, triPerLeaf, totalTris); } }
/*********************************************************************** * Character * shot ***********************************************************************/ void fired::Character::updateStats() { calcStats(&attrStats, &attr); updateEquip(); stats = baseStats + attrStats + equipStats; }
//ntlTree::ntlTree(int depth, int objnum, vector<ntlVec3Gfx> *vertices, vector<ntlVec3Gfx> *normals, vector<ntlTriangle> *trilist) : ntlTree::ntlTree(int depth, int objnum, ntlScene *scene, int triFlagMask) : mStart(0.0), mEnd(0.0), mMaxDepth( depth ), mMaxListLength( objnum ), mpRoot( NULL) , mpNodeStack( NULL), mpTBB( NULL ), mTriangleMask( 0xFFFF ), mCurrentDepth(0), mCurrentNodes(0), mTriDoubles(0) { // init scene data pointers mpVertices = scene->getVertexPointer(); mpVertNormals = scene->getVertexNormalPointer(); mpTriangles = scene->getTrianglePointer(); mTriangleMask = triFlagMask; if(mpTriangles == NULL) { errFatal( "ntlTree Cons","no triangle list!\n",SIMWORLD_INITERROR); return; } if(mpTriangles->size() == 0) { warnMsg( "ntlTree::ntlTree","No triangles ("<< mpTriangles->size() <<")!\n"); mStart = mEnd = ntlVec3Gfx(0,0,0); return; } if(depth>=BSP_STACK_SIZE) { errFatal( "ntlTree::ntlTree","Depth to high ("<< mMaxDepth <<")!\n", SIMWORLD_INITERROR ); return; } /* check triangles (a bit inefficient, but we dont know which vertices belong to this tree), and generate bounding boxes */ mppTriangles = new vector<ntlTriangle *>; int noOfTriangles = mpTriangles->size(); mpTBB = new TriangleBBox[ noOfTriangles ]; int bbCount = 0; mStart = mEnd = (*mpVertices)[ mpTriangles->front().getPoints()[0] ]; //errMsg("TreeDebug","Start"); for (vector<ntlTriangle>::iterator iter = mpTriangles->begin(); iter != mpTriangles->end(); iter++ ) { //errorOut(" d "<< convertFlags2String((int)(*iter).getFlags()) <<" "<< convertFlags2String( (int)mTriangleMask)<<" add? "<<( ((int)(*iter).getFlags() & (int)mTriangleMask) != 0 ) ); // discard triangles that dont match mask if( ((int)(*iter).getFlags() & (int)mTriangleMask) == 0 ) { continue; } // test? TODO ntlVec3Gfx tnormal = (*mpVertNormals)[ (*iter).getPoints()[0] ]+ (*mpVertNormals)[ (*iter).getPoints()[1] ]+ (*mpVertNormals)[ (*iter).getPoints()[2] ]; ntlVec3Gfx triangleNormal = (*iter).getNormal(); if( equal(triangleNormal, ntlVec3Gfx(0.0)) ) continue; if( equal( tnormal, ntlVec3Gfx(0.0)) ) continue; // */ ntlVec3Gfx bbs, bbe; //errMsg("TreeDebug","Triangle"); for(int i=0;i<3;i++) { int index = (*iter).getPoints()[i]; ntlVec3Gfx tp = (*mpVertices)[ index ]; //errMsg("TreeDebug"," Point "<<i<<" = "<<tp<<" "); if(tp[0] < mStart[0]) mStart[0]= tp[0]; if(tp[0] > mEnd[0]) mEnd[0]= tp[0]; if(tp[1] < mStart[1]) mStart[1]= tp[1]; if(tp[1] > mEnd[1]) mEnd[1]= tp[1]; if(tp[2] < mStart[2]) mStart[2]= tp[2]; if(tp[2] > mEnd[2]) mEnd[2]= tp[2]; if(i==0) { bbs = bbe = tp; } else { if( tp[0] < bbs[0] ) bbs[0] = tp[0]; if( tp[0] > bbe[0] ) bbe[0] = tp[0]; if( tp[1] < bbs[1] ) bbs[1] = tp[1]; if( tp[1] > bbe[1] ) bbe[1] = tp[1]; if( tp[2] < bbs[2] ) bbs[2] = tp[2]; if( tp[2] > bbe[2] ) bbe[2] = tp[2]; } } mppTriangles->push_back( &(*iter) ); //errMsg("TreeDebug","Triangle "<<(*mpVertices)[(*iter).getPoints()[0]]<<" "<<(*mpVertices)[(*iter).getPoints()[1]]<<" "<<(*mpVertices)[(*iter).getPoints()[2]]<<" "); // add BB mpTBB[ bbCount ].start = bbs; mpTBB[ bbCount ].end = bbe; (*iter).setBBoxId( bbCount ); bbCount++; } /* slighlty enlarge bounding tolerance for tree to avoid problems with triangles paralell to slabs */ mStart -= ntlVec3Gfx( getVecEpsilon() ); mEnd += ntlVec3Gfx( getVecEpsilon() ); /* init root node and stack */ mpNodeStack = new BSPStack; mpRoot = new BSPNode; mpRoot->min = mStart; mpRoot->max = mEnd; mpRoot->axis = AXIS_X; mpRoot->members = mppTriangles; mpRoot->child[0] = mpRoot->child[1] = NULL; mpRoot->cloneVec = 0; globalSortingPoints = mpVertices; mpTriDist = new char[ mppTriangles->size() ]; mNumNodes = 1; mAbortSubdiv = 0; /* create tree */ debugOutInter( "Generating BSP Tree... (Nodes "<< mCurrentNodes << ", Depth "<<mCurrentDepth<< ") ", 2, 2000 ); subdivide(mpRoot, 0, AXIS_X); debMsgStd("ntlTree::ntlTree",DM_MSG,"Generated Tree: Nodes "<< mCurrentNodes << ", Depth "<<mCurrentDepth<< " with "<<noOfTriangles<<" triangles", 2 ); delete [] mpTriDist; delete [] mpTBB; mpTriDist = NULL; mpTBB = NULL; /* calculate some stats about tree */ int noLeafs = 0; gfxReal avgDepth = 0.0; gfxReal triPerLeaf = 0.0; int totalTris = 0; calcStats(mpRoot,0, noLeafs, avgDepth, triPerLeaf, totalTris); avgDepth /= (gfxReal)noLeafs; triPerLeaf /= (gfxReal)noLeafs; debMsgStd("ntlTree::ntlTree",DM_MSG,"Tree ("<<doSort<<","<<chooseAxis<<") Stats: Leafs:"<<noLeafs<<", avgDepth:"<<avgDepth<< ", triPerLeaf:"<<triPerLeaf<<", triDoubles:"<<mTriDoubles<<", totalTris:"<<totalTris <<" nodes:"<<mNumNodes //<<" T"<< (totalTris%3) // 0=ich, 1=f, 2=a , 2 ); if(mAbortSubdiv) { errMsg("ntlTree::ntlTree","Aborted... "<<mNumNodes); deleteNode(mpRoot); mpRoot = NULL; } }
RImageDock::RImageDock(OGLWidget* newOGLWidget, QWidget *parent) :QWidget(parent) { widgetTitle = QString(""); frameIndex = 0; this->oglWidget = newOGLWidget; matImage = newOGLWidget->matImageListRGB.at(frameIndex); naxis1 = matImage.cols; naxis2 = matImage.rows; bscale = newOGLWidget->rMatImageList.at(0).getBscale(); qDebug() << "RImageDock::matImage.channels()" << matImage.channels(); // Convert to gray before getting the Max and Min cvtColor(matImage, matImageGray, CV_RGB2GRAY); dataMin = 0; dataMax = 0; cv::minMaxLoc(matImageGray, &dataMin, &dataMax); dataRange = dataMax - dataMin; qDebug() << "rImageDock::dataMin =" << dataMin; qDebug() << "rImageDock::dataMax =" << dataMax; gamma = 1; // String number format parameters if (dataRange < 0.1) { format = 'g'; precision = 2; } else if (dataRange < 10) { format = 'f'; precision = 3; } else { format = 'f'; precision = 0; } newMin = dataMin; newMax = dataMax; // Set the slider steps // We need to differiente between scientific calibrated data values and // uncalibrated, unphysical values scaled only within [0-65535] // We know this from the bscale values. // We deal typically with uncalibrated 8 bits [0-256], 16 bits [0=65535] // or calibrated 32 bits data, whose unit will depend on bscale. // if bscale = 1, we stick to a 16 bits range. This includes the 8-bits case (maybe this will change) colorRange = 65536.0f; sliderMin = 1; sliderMax = sliderMin + colorRange -1; if (bscale == 1) { sliderScaleStep = 1.0f; qDebug() << "rImageDock:: sliderScaleStep =" << sliderScaleStep; // Set initial constrast stretching factors alpha = 1.0f / colorRange; beta = 0.0f; } else // Stretch the data into their physical range at 16-bits precision. { sliderScaleStep = dataRange/colorRange; // Set initial constrast stretching factors alpha = (float) (1.0f / dataRange); beta = (float) (-newMin / dataRange); } oglWidget->setAlpha(alpha); oglWidget->setBeta(beta); // Create the Sliders and Layout of the dock widget. //QLabels setup QLabel *labelHigh = new QLabel("High"); QLabel *labelLow = new QLabel("Low"); QLabel *labelGamma = new QLabel("Gamma"); //QSliders setup sliderHigh = new QSlider(Qt::Horizontal); sliderLow = new QSlider(Qt::Horizontal); sliderGamma = new QSlider(Qt::Horizontal); float gammaRange = 40; maxGamma = 2.1; minGamma = 0.1; sliderGammaStep = (maxGamma - minGamma)/gammaRange; // set sliders range sliderHigh->setRange((int)sliderMin, (int)sliderMax); sliderHigh->setSingleStep(1); sliderLow->setRange((int)sliderMin, (int)sliderMax); sliderLow->setSingleStep(1); sliderGamma->setRange(1, (int) gammaRange); sliderLow->setSingleStep(1); // set sliders value sliderHigh->setValue(sliderMax); sliderLow->setValue(sliderMin); sliderGamma->setValue(convertGammaToSlider(QString::number(gamma))); //QLineEdit setup valueHighLineEdit = new QLineEdit(QString::number(dataMax, format, precision)); valueLowLineEdit = new QLineEdit(QString::number(dataMin, format, precision)); valueGammaLineEdit = new QLineEdit(QString::number(gamma)); int editMinimumWidth = 20; int editMaximumWidth = 60; valueHighLineEdit->setMinimumWidth(editMinimumWidth); valueHighLineEdit->setMaximumWidth(editMaximumWidth); valueLowLineEdit->setMinimumWidth(editMinimumWidth); valueLowLineEdit->setMaximumWidth(editMaximumWidth); valueGammaLineEdit->setMinimumWidth(editMinimumWidth); valueGammaLineEdit->setMaximumWidth(editMaximumWidth); // QGridLayout setup QGridLayout *sliderLayout = new QGridLayout(); // Add the labels sliderLayout->addWidget(labelHigh, 0, 0); sliderLayout->addWidget(labelLow, 1, 0); sliderLayout->addWidget(labelGamma, 2, 0); // Add the sliders sliderLayout->addWidget(sliderHigh, 0, 1); sliderLayout->addWidget(sliderLow, 1, 1); sliderLayout->addWidget(sliderGamma, 2, 1); // Add the line edits. sliderLayout->addWidget(valueHighLineEdit, 0, 2); sliderLayout->addWidget(valueLowLineEdit, 1, 2); sliderLayout->addWidget(valueGammaLineEdit, 2, 2); // Define the minimum spacing between sliders. This may need some adjusting. int vSpacing = 0; int hSpacing = 10; //QMargins margins(10, 10, 5, 5); //sliderLayout->setContentsMargins(margins); sliderLayout->setVerticalSpacing(vSpacing); sliderLayout->setHorizontalSpacing(hSpacing); // Set the minimum column widths of the layout, int sliderWidth = 350; int lineEditWidth = 20; sliderLayout->setColumnMinimumWidth(1, sliderWidth); sliderLayout->setColumnMinimumWidth(2, lineEditWidth); sliderLayout->setMargin(0); QWidget *sliderWidget = new QWidget(); sliderWidget->setLayout(sliderLayout); sliderWidget->setMinimumHeight(60); // Calibration type QWidget *calibrationTypeWidget = new QWidget(); light = new QCheckBox(QString("Light")); bias = new QCheckBox(QString("Bias")); dark = new QCheckBox(QString("Dark")); flat = new QCheckBox(QString("Flat")); // Histrogram button QPushButton *histButton = new QPushButton("Histogram"); QGridLayout *grid = new QGridLayout(); grid->addWidget(light,0,0); grid->addWidget(bias,0,1); grid->addWidget(dark,1,0); grid->addWidget(flat,1,1); grid->addWidget(histButton, 2, 0, 1, 2); grid->setMargin(0); calibrationTypeWidget->setLayout(grid); calibrationTypeWidget->setMinimumHeight(60); QHBoxLayout *hBox = new QHBoxLayout(); hBox->addWidget(sliderWidget); hBox->addWidget(calibrationTypeWidget); // Set the above layout in this QWidget setLayout(hBox); setMinimumWidth(600); //setMaximumWidth(800); setMaximumHeight(80); // Connect the change of the slider position with the QLineEdit QObject::connect(sliderHigh, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(sliderLow, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(sliderGamma, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(valueHighLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); QObject::connect(valueLowLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); QObject::connect(valueGammaLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); //Connect the slider value changed with the Image display. QObject::connect(sliderHigh, SIGNAL(valueChanged(int)), this, SLOT(scaleImageSlot(int))); QObject::connect(sliderLow, SIGNAL(valueChanged(int)), this, SLOT(scaleImageSlot(int))); QObject::connect(sliderGamma, SIGNAL(valueChanged(int)), this, SLOT(gammaScaleImageSlot(int))); QObject::connect(histButton, SIGNAL(released()), this, SLOT(drawHist())); // Connect mouse events with OGLWidget QObject::connect(newOGLWidget, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater())); qRegisterMetaType<QVector<int> >("QVector<int>"); qRegisterMetaType<QVector<QString> >("QVector<QString>"); // Get initial tatistics calcStats(); autoScale(); }