string Tree::procurafinal(string codificacao){ unsigned char buffer; string aux_s; aux_s.clear(); ofstream write; const char* aux_ch = filename.c_str(); write.open(aux_ch, ios::out | ios::binary | ios::app); if(write.is_open()){ QStack<Node*>* StackdeCodigo = new QStack<Node*>(); StackdeCodigo->push(root); for(int i = 0; i < codificacao.length();i++){ Node* temp = new Node(); if(codificacao[i] == '0'){ temp = StackdeCodigo->top()->getLeftChild(); if(temp->isLeaf() == false){ StackdeCodigo->push(temp); } else{ buffer = temp->getContent(); StackdeCodigo->clear(); StackdeCodigo->push(root); write << buffer; } } else if(codificacao[i] == '1'){ temp = StackdeCodigo->top()->getRightChild(); if(temp->isLeaf() == false){ StackdeCodigo->push(temp); } else{ buffer = temp->getContent(); StackdeCodigo->clear(); StackdeCodigo->push(root); write << buffer; } } } } else { cout << "TRASH!" << endl; } write.close(); return aux_s; }
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd) { QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); return false; } yyDefaultContext = cd.m_defaultContext; yyInPos = -1; yyFileName = filename; yyPackage.clear(); yyScope.clear(); yyTok = -1; yyParenDepth = 0; yyCurLineNo = 0; yyParenLineNo = 1; QTextStream ts(&file); ts.setCodec(QTextCodec::codecForName(cd.m_sourceIsUtf16 ? "UTF-16" : "UTF-8")); ts.setAutoDetectUnicode(true); yyInStr = ts.readAll(); yyInPos = 0; yyFileName = filename; yyCurLineNo = 1; yyParenLineNo = 1; parse(&translator); return true; }
void Browser::test() { BrowserItem *item = NULL; BrowserLevel *currentLevel = NULL; QStack <BrowserLevel *> testStack; testStack.clear(); rootLevel->reset(); testStack.push(rootLevel); while (!testStack.isEmpty()) { currentLevel = testStack.pop(); item = currentLevel->getCurrentItem(); currentLevel->next(); if (item != NULL) { qDebug() << "item:" << item->getPresentationData(); if (item->hasAction()) { qDebug() << "has action:" << item->getActionModule() << ":" << item->getActionName(); } else if (item->hasLevelBelow()) { qDebug() << "has one level below, going down"; testStack.push(currentLevel); currentLevel = item->getLevelBelow(); currentLevel->reset(); } } testStack.push(currentLevel); if (currentLevel->atEnd()) { if (!testStack.isEmpty()) { currentLevel = testStack.pop(); } } } }
void stackShow::Post2In(QStringList &phrase) { static QStack <QString> stack; QString r,r1,r2; QString l[4]={"+" , "-" , "*" , "/" }; for (int i=0; i<phrase.size(); i++) for (int j=0 ; j<4 ; j++) { if (phrase.at(i)!=l[j] && j==3) { stack.push(phrase.at(i)); ui->lneRes->insert(phrase.at(i) + " "); phrase.removeFirst(); r = phrase.join(" "); ui->lneExp->setText(r); return; } else if ( phrase.at(i)==l[j] ) { if (stack.size()<2) return ; QStringList t = stack.toList(); t.removeLast(); t.removeLast(); r = t.join(" "); r1=stack.pop(); r2=stack.pop(); stack.push( "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) "); ui->lneRes->setText( "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) "); ui->lneStack->setText( r + " " "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) "); phrase.removeFirst(); r = phrase.join(" "); ui->lneExp->setText(r); if (phrase.size()==0) stack.clear(); return; } } }
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd) { QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { cd.appendError(QString::fromLatin1("Cannot open %1: %2") .arg(filename, file.errorString())); return false; } yyDefaultContext = cd.m_defaultContext; yyInPos = -1; yyFileName = filename; yyPackage.clear(); yyScope.clear(); yyTok = -1; yyParenDepth = 0; yyCurLineNo = 0; yyParenLineNo = 1; QTextStream ts(&file); QByteArray codecName; if (!cd.m_codecForSource.isEmpty()) codecName = cd.m_codecForSource; else codecName = translator.codecName(); // Just because it should be latin1 already ts.setCodec(QTextCodec::codecForName(codecName)); ts.setAutoDetectUnicode(true); yyInStr = ts.readAll(); yyInPos = 0; yyFileName = filename; yyCurLineNo = 1; yyParenLineNo = 1; parse(&translator); // Java uses UTF-16 internally and Jambi makes UTF-8 for tr() purposes of it. translator.setCodecName("UTF-8"); return true; }
static void startTokenizer( const char *fileName, int (*getCharFunc)(), int (*peekCharFunc)(), QTextCodec *codecForTr, QTextCodec *codecForSource ) { yyInPos = 0; buf = rawbuf = -1; getChar = getCharFunc; peekChar = peekCharFunc; yyFileName = fileName; yyCh = getChar(); yySavedParenDepth.clear(); yyParenDepth = 0; yyCurLineNo = 1; yyParenLineNo = 1; yyCodecForTr = codecForTr; if (!yyCodecForTr) yyCodecForTr = QTextCodec::codecForName("ISO-8859-1"); Q_ASSERT(yyCodecForTr); yyCodecForSource = codecForSource; yyParsingUtf8 = false; }
void Seeker::powerSeek( QString path ) { this->flag = false ; this->result.clear() ; Node* node = this->seek( path ) ; if ( node ) { if ( node->record.count() ) { //qDebug() << "get" << path ; this->result.append( node ) ; this->flag = true ; } else { //qDebug() << "power seek" ; QStack<Node*> current; QStack<Node*> deeper; current.push( this->current ) ; while( current.count() > 0 && this->result.count() < 1 ) { while( current.count() > 0 ) { node = current.pop() ; //qDebug() << QString( node->code ) ; if ( node->record.count() ) this->result.append( node ) ; else { if ( this->result.count() < 1 ) { for ( int i = 0; i < node->child.count(); i++ ) { deeper.append( node->child[i] ) ; } } } } current = deeper ; deeper.clear() ; } } } //return this->result ; }
bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage) { QMimeTypePrivate data; int priority = 50; QStack<QMimeMagicRule *> currentRules; // stack for the nesting of rules QList<QMimeMagicRule> rules; // toplevel rules QXmlStreamReader reader(dev); ParseState ps = ParseBeginning; QXmlStreamAttributes atts; while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::StartElement: ps = nextState(ps, reader.name()); atts = reader.attributes(); switch (ps) { case ParseMimeType: { // start parsing a MIME type name const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (name.isEmpty()) { reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC))); } else { data.name = name; } } break; case ParseGenericIcon: data.genericIconName = atts.value(QLatin1String(nameAttributeC)).toString(); break; case ParseIcon: data.iconName = atts.value(QLatin1String(nameAttributeC)).toString(); break; case ParseGlobPattern: { const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString(); unsigned weight = atts.value(QLatin1String(weightAttributeC)).toString().toInt(); const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)).toString() == QLatin1String("true"); if (weight == 0) weight = QMimeGlobPattern::DefaultWeight; Q_ASSERT(!data.name.isEmpty()); const QMimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); if (!process(glob, errorMessage)) // for actual glob matching return false; data.addGlobPattern(pattern); // just for QMimeType::globPatterns() } break; case ParseSubClass: { const QString inheritsFrom = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (!inheritsFrom.isEmpty()) processParent(data.name, inheritsFrom); } break; case ParseComment: { // comments have locale attributes. We want the default, English one QString locale = atts.value(QLatin1String(localeAttributeC)).toString(); const QString comment = reader.readElementText(); if (locale.isEmpty()) locale = QString::fromLatin1("en_US"); data.localeComments.insert(locale, comment); } break; case ParseAlias: { const QString alias = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); if (!alias.isEmpty()) processAlias(alias, data.name); } break; case ParseMagic: { priority = 50; const QString priorityS = atts.value(QLatin1String(priorityAttributeC)).toString(); if (!priorityS.isEmpty()) { if (!parseNumber(priorityS, &priority, errorMessage)) return false; } currentRules.clear(); //qDebug() << "MAGIC start for mimetype" << data.name; } break; case ParseMagicMatchRule: { QMimeMagicRule *rule = 0; if (!createMagicMatchRule(atts, errorMessage, rule)) return false; QList<QMimeMagicRule> *ruleList; if (currentRules.isEmpty()) ruleList = &rules; else // nest this rule into the proper parent ruleList = ¤tRules.top()->m_subMatches; ruleList->append(*rule); //qDebug() << " MATCH added. Stack size was" << currentRules.size(); currentRules.push(&ruleList->last()); delete rule; break; } case ParseError: reader.raiseError(QString::fromLatin1("Unexpected element <%1>"). arg(reader.name().toString())); break; default: break; } break; // continue switch QXmlStreamReader::Token... case QXmlStreamReader::EndElement: // Finished element { const QStringRef elementName = reader.name(); if (elementName == QLatin1String(mimeTypeTagC)) { if (!process(QMimeType(data), errorMessage)) return false; data.clear(); } else if (elementName == QLatin1String(matchTagC)) { // Closing a <match> tag, pop stack currentRules.pop(); //qDebug() << " MATCH closed. Stack size is now" << currentRules.size(); } else if (elementName == QLatin1String(magicTagC)) { //qDebug() << "MAGIC ended, we got" << rules.count() << "rules, with prio" << priority; // Finished a <magic> sequence QMimeMagicRuleMatcher ruleMatcher(data.name, priority); ruleMatcher.addRules(rules); processMagicMatcher(ruleMatcher); rules.clear(); } break; } default: break; } } if (reader.hasError()) { if (errorMessage) *errorMessage = QString::fromLatin1("An error has been encountered at line %1 of %2: %3:").arg(reader.lineNumber()).arg(fileName, reader.errorString()); return false; } return true; }
void pTreeComboBox::calculPopupGeometry() { if ( !mView ) { return; } QStyle * const style = this->style(); // set current item and select it view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); QFrame* container = mFrame; QStyleOptionComboBox opt; initStyleOption( &opt ); QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) ); QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) ); QPoint below = mapToGlobal( listRect.bottomLeft() ); int belowHeight = screen.bottom() -below.y(); QPoint above = mapToGlobal( listRect.topLeft() ); int aboveHeight = above.y() -screen.y(); bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen ); listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) ); listRect.setSize( QSize( qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() ) , qMax( view()->viewport()->height(), mFrame->height() ) ) ); const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ); { int listHeight = 0; int count = 0; QStack<QModelIndex> toCheck; toCheck.push( view()->rootIndex() ); #ifndef QT_NO_TREEVIEW QTreeView* treeView = qobject_cast<QTreeView*>( view() ); if ( treeView && treeView->header() && !treeView->header()->isHidden() ) listHeight += treeView->header()->height(); #endif while ( !toCheck.isEmpty() ) { QModelIndex parent = toCheck.pop(); for ( int i = 0; i < model()->rowCount( parent ); ++i ) { QModelIndex idx = model()->index( i, mModelColumn, parent ); if ( !idx.isValid() ) continue; listHeight += view()->visualRect( idx ).height(); #ifndef QT_NO_TREEVIEW if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) ) toCheck.push( idx ); #endif ++count; if ( !usePopup && count > mMaxVisibleItems ) { toCheck.clear(); break; } } } listRect.setHeight( listHeight ); } { // add the spacing for the grid on the top and the bottom; int heightMargin = 0; // add the frame of the container int marginTop, marginBottom; container->getContentsMargins( 0, &marginTop, 0, &marginBottom ); heightMargin += marginTop +marginBottom; //add the frame of the view view()->getContentsMargins( 0, &marginTop, 0, &marginBottom ); marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/; marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/; heightMargin += marginTop +marginBottom; listRect.setHeight( listRect.height() +heightMargin ); } // Add space for margin at top and bottom if the style wants it. if ( usePopup ) listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 ); // Make sure the popup is wide enough to display its contents. if ( usePopup ) { const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width(); if ( diff > 0 ) listRect.setWidth( listRect.width() +diff ); } //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show container->layout()->activate(); //takes account of the minimum/maximum size of the container listRect.setSize( listRect.size().expandedTo(container->minimumSize()) .boundedTo(container->maximumSize())); // make sure the widget fits on screen if (boundToScreen) { if (listRect.width() > screen.width() ) listRect.setWidth(screen.width()); if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) { below.setX(screen.x() + screen.width() - listRect.width()); above.setX(screen.x() + screen.width() - listRect.width()); } if (/*mapToGlobal(*/listRect/*.topLeft())*/.x() < screen.x() ) { below.setX(screen.x()); above.setX(screen.x()); } } if ( usePopup ) { // Position horizontally. listRect.moveLeft( above.x() ); // Position vertically so the curently selected item lines up // with the combo box. /*const QRect currentItemRect = view()->visualRect( view()->currentIndex() ); const int offset = listRect.top() -currentItemRect.top(); listRect.moveTop( above.y() +offset -listRect.top() );*/ // Clamp the listRect height and vertical position so we don't expand outside the // available screen geometry.This may override the vertical position, but it is more // important to show as much as possible of the popup. const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height()); listRect.setHeight(height); if (boundToScreen) { if (listRect.top() < screen.top()) listRect.moveTop(screen.top()); if (listRect.bottom() > screen.bottom()) listRect.moveBottom(screen.bottom()); } } else if (!boundToScreen || listRect.height() <= belowHeight) { listRect.moveTopLeft(below); } else if (listRect.height() <= aboveHeight) { listRect.moveBottomLeft(above); } else if (belowHeight >= aboveHeight) { listRect.setHeight(belowHeight); listRect.moveTopLeft(below); } else { listRect.setHeight(aboveHeight); listRect.moveBottomLeft(above); } #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #ifndef QT_NO_IM if ( QInputContext *qic = inputContext() ) qic->reset(); #endif #endif QScrollBar* sb = view()->horizontalScrollBar(); Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy(); bool needHorizontalScrollBar = ( policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn ) && sb->minimum() < sb->maximum(); if ( needHorizontalScrollBar ) { listRect.adjust( 0, 0, 0, sb->height() ); } container->setGeometry( listRect ); #ifndef Q_WS_MAC const bool updatesEnabled = container->updatesEnabled(); #endif #if defined( Q_WS_WIN ) && !defined( QT_NO_EFFECTS ) // FIXME Fix me ASAP /*bool scrollDown = ( listRect.topLeft() == below ); if ( QApplication::isEffectEnabled( Qt::UI_AnimateCombo ) && !style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) && !window()->testAttribute( Qt::WA_DontShowOnScreen ) ) qScrollEffect( container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150 );*/ #endif // Don't disable updates on Mac OS X. Windows are displayed immediately on this platform, // which means that the window will be visible before the call to container->show() returns. // If updates are disabled at this point we'll miss our chance at painting the popup // menu before it's shown, causing flicker since the window then displays the standard gray // background. #ifndef Q_WS_MAC container->setUpdatesEnabled( false ); #endif container->raise(); container->show(); //container->updateScrollers(); view()->setFocus(); view()->scrollTo( view()->currentIndex(), style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible ); #ifndef Q_WS_MAC container->setUpdatesEnabled( updatesEnabled ); #endif container->update(); #ifdef QT_KEYPAD_NAVIGATION if ( QApplication::keypadNavigationEnabled() ) view()->setEditFocus( true ); #endif }
// ------------------------------------------------------------------------- void ctkTreeComboBox::resizePopup() { // copied from QComboBox.cpp Q_D(ctkTreeComboBox); QStyle * const style = this->style(); QWidget* container = qobject_cast<QWidget*>(this->view()->parent()); QStyleOptionComboBox opt; this->initStyleOption(&opt); QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this)); QRect screen = QApplication::desktop()->availableGeometry( QApplication::desktop()->screenNumber(this)); QPoint below = this->mapToGlobal(listRect.bottomLeft()); int belowHeight = screen.bottom() - below.y(); QPoint above = this->mapToGlobal(listRect.topLeft()); int aboveHeight = above.y() - screen.y(); bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen); const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this); { int listHeight = 0; int count = 0; QStack<QModelIndex> toCheck; toCheck.push(this->view()->rootIndex()); #ifndef QT_NO_TREEVIEW QTreeView *treeView = qobject_cast<QTreeView*>(this->view()); if (treeView && treeView->header() && !treeView->header()->isHidden()) listHeight += treeView->header()->height(); #endif while (!toCheck.isEmpty()) { QModelIndex parent = toCheck.pop(); for (int i = 0; i < this->model()->rowCount(parent); ++i) { QModelIndex idx = this->model()->index(i, this->modelColumn(), parent); if (!idx.isValid()) { continue; } listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */; #ifndef QT_NO_TREEVIEW if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx)) { toCheck.push(idx); } #endif ++count; if (!usePopup && count > this->maxVisibleItems()) { toCheck.clear(); break; } } } listRect.setHeight(listHeight); } { // add the spacing for the grid on the top and the bottom; int heightMargin = 0;//2*container->spacing(); // add the frame of the container int marginTop, marginBottom; container->getContentsMargins(0, &marginTop, 0, &marginBottom); heightMargin += marginTop + marginBottom; //add the frame of the view this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom); //marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top; //marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom; heightMargin += marginTop + marginBottom; listRect.setHeight(listRect.height() + heightMargin); } // Add space for margin at top and bottom if the style wants it. if (usePopup) { listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2); } // Make sure the popup is wide enough to display its contents. if (usePopup) { const int diff = d->computeWidthHint() - this->width(); if (diff > 0) { listRect.setWidth(listRect.width() + diff); } } //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show container->layout()->activate(); //takes account of the minimum/maximum size of the container listRect.setSize( listRect.size().expandedTo(container->minimumSize()) .boundedTo(container->maximumSize())); // make sure the widget fits on screen if (boundToScreen) { if (listRect.width() > screen.width() ) { listRect.setWidth(screen.width()); } if (this->mapToGlobal(listRect.bottomRight()).x() > screen.right()) { below.setX(screen.x() + screen.width() - listRect.width()); above.setX(screen.x() + screen.width() - listRect.width()); } if (this->mapToGlobal(listRect.topLeft()).x() < screen.x() ) { below.setX(screen.x()); above.setX(screen.x()); } } if (usePopup) { // Position horizontally. listRect.moveLeft(above.x()); #ifndef Q_WS_S60 // Position vertically so the curently selected item lines up // with the combo box. const QRect currentItemRect = this->view()->visualRect(this->view()->currentIndex()); const int offset = listRect.top() - currentItemRect.top(); listRect.moveTop(above.y() + offset - listRect.top()); #endif // Clamp the listRect height and vertical position so we don't expand outside the // available screen geometry.This may override the vertical position, but it is more // important to show as much as possible of the popup. const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height()); #ifdef Q_WS_S60 //popup needs to be stretched with screen minimum dimension listRect.setHeight(qMin(screen.height(), screen.width())); #else listRect.setHeight(height); #endif if (boundToScreen) { if (listRect.top() < screen.top()) { listRect.moveTop(screen.top()); } if (listRect.bottom() > screen.bottom()) { listRect.moveBottom(screen.bottom()); } } #ifdef Q_WS_S60 if (screen.width() < screen.height()) { // in portait, menu should be positioned above softkeys listRect.moveBottom(screen.bottom()); } else { TRect staConTopRect = TRect(); AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect); listRect.setWidth(listRect.height()); //by default popup is centered on screen in landscape listRect.moveCenter(screen.center()); if (staConTopRect.IsEmpty()) { // landscape without stacon, menu should be at the right (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) : listRect.setLeft(screen.left()); } } #endif } else if (!boundToScreen || listRect.height() <= belowHeight) { listRect.moveTopLeft(below); } else if (listRect.height() <= aboveHeight) { listRect.moveBottomLeft(above); } else if (belowHeight >= aboveHeight) { listRect.setHeight(belowHeight); listRect.moveTopLeft(below); } else { listRect.setHeight(aboveHeight); listRect.moveBottomLeft(above); } #if QT_VERSION < QT_VERSION_CHECK(5,0,0) && !defined QT_NO_IM if (QInputContext *qic = this->inputContext()) { qic->reset(); } #endif QScrollBar *sb = this->view()->horizontalScrollBar(); Qt::ScrollBarPolicy policy = this->view()->horizontalScrollBarPolicy(); bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn) && sb->minimum() < sb->maximum(); if (needHorizontalScrollBar) { listRect.adjust(0, 0, 0, sb->height()); } container->setGeometry(listRect); }
void PreprocessContext::reset() { m_sectionStack.clear(); // Add a default, enabled section. m_sectionStack.push(PreprocessStackEntry(OtherSection, true, true)); }
void Volume::findConnectedRegion(int mind, int maxd, int minw, int maxw, int minh, int maxh, QList<int> pos, bool sliceOnly) { m_connectedbitmask.fill(false); uchar *lut = Global::lut(); QStack<int> stack; uchar *vslice; uchar v0, g0; int d = pos[0]; int w = pos[1]; int h = pos[2]; vslice = m_pvlFileManager.rawValue(d, w, h); v0 = vslice[0]; // vslice = m_gradFileManager.rawValue(d, w, h); // g0 = vslice[0]; g0 = 0; // put the seeds in for(int pi=0; pi<pos.size()/3; pi++) { int d = pos[3*pi]; int w = pos[3*pi+1]; int h = pos[3*pi+2]; if (d >= mind && d <= maxd && w >= minw && w <= maxw && h >= minh && h <= maxh) { qint64 idx = d*m_width*m_height + w*m_height + h; if (m_bitmask.testBit(idx)) { m_connectedbitmask.setBit(idx); stack.push(d); stack.push(w); stack.push(h); } } } if (sliceOnly) stack.clear(); int pv = 0; int progv = 0; while(!stack.isEmpty()) { progv++; if (progv == 1000) { progv = 0; pv = (++pv % 100); emit progressChanged(pv); } int h = stack.pop(); int w = stack.pop(); int d = stack.pop(); qint64 idx = d*m_width*m_height + w*m_height + h; if (m_bitmask.testBit(idx)) { int d0 = qMax(d-1, 0); int d1 = qMin(d+1, m_depth-1); int w0 = qMax(w-1, 0); int w1 = qMin(w+1, m_width-1); int h0 = qMax(h-1, 0); int h1 = qMin(h+1, m_height-1); for(int d2=d0; d2<=d1; d2++) for(int w2=w0; w2<=w1; w2++) for(int h2=h0; h2<=h1; h2++) { if (d2 >= mind && d2 <= maxd && w2 >= minw && w2 <= maxw && h2 >= minh && h2 <= maxh) { qint64 idx = d2*m_width*m_height + w2*m_height + h2; if ( m_bitmask.testBit(idx) && !m_connectedbitmask.testBit(idx) ) { // uchar v, g; // vslice = m_pvlFileManager.rawValue(d2, w2, h2); // v = vslice[0]; // vslice = m_gradFileManager.rawValue(d2, w2, h2); // g = vslice[0]; // // if (qAbs(v-v0) < Global::deltaV() && // g < Global::deltaG()) { m_connectedbitmask.setBit(idx); stack.push(d2); stack.push(w2); stack.push(h2); } } } } } } // end find connected //------------------------------------------------------ emit progressReset(); }
void TraceLoader::parseTrace() { QList<ApiTraceFrame*> frames; ApiTraceFrame *currentFrame = 0; int frameCount = 0; QStack<ApiTraceCall*> groups; QVector<ApiTraceCall*> topLevelItems; QVector<ApiTraceCall*> allCalls; quint64 binaryDataSize = 0; int lastPercentReport = 0; trace::Call *call = m_parser.parse_call(); while (call) { //std::cout << *call; if (!currentFrame) { currentFrame = new ApiTraceFrame(); currentFrame->number = frameCount; ++frameCount; } ApiTraceCall *apiCall = apiCallFromTraceCall(call, m_helpHash, currentFrame, groups.isEmpty() ? 0 : groups.top(), this); allCalls.append(apiCall); if (groups.count() == 0) { topLevelItems.append(apiCall); } if (call->flags & trace::CALL_FLAG_MARKER_PUSH) { groups.push(apiCall); } else if (call->flags & trace::CALL_FLAG_MARKER_POP) { groups.top()->finishedAddingChildren(); groups.pop(); } if (!groups.isEmpty()) { groups.top()->addChild(apiCall); } if (apiCall->hasBinaryData()) { QByteArray data = apiCall->arguments()[apiCall->binaryDataIndex()].toByteArray(); binaryDataSize += data.size(); } if (call->flags & trace::CALL_FLAG_END_FRAME) { allCalls.squeeze(); topLevelItems.squeeze(); if (topLevelItems.count() == allCalls.count()) { currentFrame->setCalls(allCalls, allCalls, binaryDataSize); } else { currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize); } allCalls.clear(); groups.clear(); topLevelItems.clear(); frames.append(currentFrame); currentFrame = 0; binaryDataSize = 0; if (frames.count() >= FRAMES_TO_CACHE) { emit framesLoaded(frames); frames.clear(); } if (m_parser.percentRead() - lastPercentReport >= 5) { emit parsed(m_parser.percentRead()); lastPercentReport = m_parser.percentRead(); } } delete call; call = m_parser.parse_call(); } //last frames won't have markers // it's just a bunch of Delete calls for every object // after the last SwapBuffers if (currentFrame) { allCalls.squeeze(); if (topLevelItems.count() == allCalls.count()) { currentFrame->setCalls(allCalls, allCalls, binaryDataSize); } else { currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize); } frames.append(currentFrame); currentFrame = 0; } if (frames.count()) { emit framesLoaded(frames); } }