Example #1
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    // Store the current entry
    if (!fileEngineIterators.isEmpty())
        currentFilePath = fileEngineIterators.top()->currentFilePath();

    // Advance to the next entry
    if (followNextDir) {
        // Start by navigating into the current directory.
        followNextDir = false;

        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        QString subDir = it->currentFilePath();
#ifdef Q_OS_WIN
        if (currentFileInfo.isSymLink())
            subDir = currentFileInfo.canonicalFilePath();
#endif
        pushSubDirectory(subDir, it->nameFilters(), it->filters());
    }

    while (!fileEngineIterators.isEmpty()) {
        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        // Find the next valid iterator that matches the filters.
        bool foundDirectory = false;
        while (it->hasNext()) {
            it->next();
            if (matchesFilters(it)) {
                currentFileInfo = nextFileInfo;
                nextFileInfo = it->currentFileInfo();
                // Signal that we want to follow this entry.
                followNextDir = shouldFollowDirectory(nextFileInfo);
                //We found a matching entry.
                return;

            } else if (iteratorFlags & QDirIterator::Subdirectories) {
                QFileInfo fileInfo = it->currentFileInfo();

                if (!shouldFollowDirectory(fileInfo))
                    continue;
                QString subDir = it->currentFilePath();
#ifdef Q_OS_WIN
                if (fileInfo.isSymLink())
                    subDir = fileInfo.canonicalFilePath();
#endif
                pushSubDirectory(subDir, it->nameFilters(), it->filters());
                
                foundDirectory = true;
                break;
            }
        }
        if (!foundDirectory)
            delete fileEngineIterators.pop();
    }
    currentFileInfo = nextFileInfo;
    done = true;
}
Example #2
0
File: main.cpp Project: jonwd7/bae
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
	QStack<QString> files;

	// Command Line setup
	QCommandLineParser parser;
	// Process options
	parser.process( a );

	int incorrectFiles = 0;
	// Files were passed
	for ( const QString & arg : parser.positionalArguments() ) {
		QFileInfo finfo( arg );

		QRegularExpression ext( "^(bsa|ba2)$", QRegularExpression::CaseInsensitiveOption );
		if ( finfo.exists() && finfo.suffix().contains( ext ) ) {
			files.push( arg );
		} else {
			incorrectFiles++;
		}
	}

    MainWindow w;

	a.setApplicationName( "Bethesda Archive Extractor" );
	a.setApplicationDisplayName( "B.A.E." );

	QDir::setCurrent( qApp->applicationDirPath() );

    w.show();

	if ( files.count() && !incorrectFiles ) {
		w.openFile( files.pop() );

		while ( !files.isEmpty()  ) {
			w.appendFile( files.pop() );
		}
	} else if ( incorrectFiles ) {
		// Incorrect files passed
		return 0;
	}

    return a.exec();
}
Example #3
0
void runCleanupFunctions()
{
    //PySide::DestroyListener::instance()->destroy();
    while (!cleanupFunctionList.isEmpty()) {
        CleanupFunction f = cleanupFunctionList.pop();
        f();
    }
    PySide::DestroyListener::destroy();
}
Example #4
0
void Tree::rebuildTree(string maestro){
    QStack<Node*>* arranjador = new QStack<Node*>();
    arranjador->push(root);

    for(int i = 0; i < maestro.length(); i++){

        if(maestro[i] == '$'){
            i++;
            if(arranjador->top()->getqFilhos() == false){
                Node* temp = new Node(0,true,maestro[i]);
                arranjador->top()->setLeftChild(temp);
                arranjador->top()->setqFilhos(true);
            }
            else if(arranjador->top()->getqFilhos() == true){
                Node* temp = new Node(0,true,maestro[i]);
                arranjador->top()->setRightChild(temp);
                arranjador->top()->setqFilhos(false);
            }
        }
        else{
            if(maestro[i] == '('){
                if(arranjador->top()->getqFilhos() == false){
                    Node* temp = new Node(i,false);
                    arranjador->top()->setLeftChild(temp);

                    arranjador->top()->setqFilhos(true);
                    arranjador->push(temp);
                }
                else if(arranjador->top()->getqFilhos() == true){
                    Node* temp = new Node(i,false);
                    arranjador->top()->setRightChild(temp);
                    arranjador->top()->setqFilhos(false);
                    arranjador->push(temp);
                }
            }
            else if(maestro[i] == ')'){
                arranjador->pop();
            }
            else{
                if(arranjador->top()->getqFilhos() == false){
                    Node* temp = new Node(0,true,maestro[i]);
                    arranjador->top()->setLeftChild(temp);
                    arranjador->top()->setqFilhos(true);
                }
                else if(arranjador->top()->getqFilhos() == true){
                    Node* temp = new Node(0,true,maestro[i]);
                    arranjador->top()->setRightChild(temp);
                    arranjador->top()->setqFilhos(false);
                }
            }
        }
    }

    if(arranjador->size()!= 1){
        cout << "TRASH! arvore desequilibrada" << endl;
    }
}
Example #5
0
/**
 * \copydoc REntityData::getLinetypeId
 */
RLinetype::Id REntity::getLinetypeId(bool resolve,
    const QStack<RBlockReferenceEntity*>& blockRefStack) const {

    QStack<RBlockReferenceEntity*> newBlockRefStack = blockRefStack;
    if (!newBlockRefStack.isEmpty() && this==(REntity*)newBlockRefStack.top()) {
        newBlockRefStack.pop();
    }
    return getData().getLinetypeId(resolve, newBlockRefStack);
}
void xRenderPopTarget()
{
    s_scene_offscreenTargetStack.pop();
    --s_renderOffscreen;
    if (s_renderOffscreen < 0) {
        s_renderOffscreen = 0;
        qWarning("*** SOMETHING IS MESSED UP WITH YOUR xRenderPopTarget() USAGE ***");
    }
}
Example #7
0
QList<ListDigraph::Node> ProcessModel::topolSortReachableFrom(const QList<ListDigraph::Node>& s) {
	ListDigraph::NodeMap<bool > nodevisited(graph, false);
	QList<ListDigraph::Node> res;
	QStack<ListDigraph::Node> stack;
	ListDigraph::Node curnode;
	ListDigraph::Node pnode;
	ListDigraph::Node snode;
	QList<ListDigraph::Node> reachable = reachableFrom(s);

	// Reserve memory
	res.reserve(countNodes(graph));
	stack.reserve(countNodes(graph));

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != INVALID) {
			stack.push(s[i]);
		}
	}

	bool psched;
	while (!stack.empty()) {
		curnode = stack.pop();

		if (!nodevisited[curnode]) { // This node has not been visited yet

			// Check whether all predecessors in reachable are scheduled
			psched = true;
			for (ListDigraph::InArcIt iait(graph, curnode); iait != INVALID; ++iait) {
				pnode = graph.source(iait);
				if (reachable.contains(pnode)) { // Consider only nodes which can be reached from s
					if (!nodevisited[pnode]) {
						psched = false;
						break;
					}
				}
			}

			if (psched) { // All predecessors have been visited
				res.append(curnode);
				nodevisited[curnode] = true;

				// Push the succeeding nodes
				for (ListDigraph::OutArcIt oait(graph, curnode); oait != INVALID; ++oait) {
					snode = graph.target(oait);
					if (!nodevisited[snode]) {
						stack.push(snode);
					}
				}
			} else {
				stack.prepend(curnode);
			}

		} // Else ignore the visited node
	}

	return res;
}
Example #8
0
/**
 * \copydoc REntityData::getColor
 */
RColor REntity::getColor(bool resolve, const QStack<REntity*>& blockRefStack) {

    QStack<REntity*> newBlockRefStack = blockRefStack;
    if (!newBlockRefStack.isEmpty() && this==(REntity*)newBlockRefStack.top()) {
        newBlockRefStack.pop();
    }

    return getData().getColor(resolve, newBlockRefStack);
}
Example #9
0
QString Stringify::JO(Object *o)
{
    if (stack.contains(o)) {
        ctx->throwTypeError();
        return QString();
    }

    Scope scope(ctx);

    QString result;
    stack.push(o);
    QString stepback = indent;
    indent += gap;

    QStringList partial;
    if (propertyList.isEmpty()) {
        ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
        ScopedValue name(scope);

        ScopedValue val(scope);
        while (1) {
            name = it.nextPropertyNameAsString(val);
            if (name->isNull())
                break;
            QString key = name->toQString();
            QString member = makeMember(key, val);
            if (!member.isEmpty())
                partial += member;
        }
    } else {
        ScopedString s(scope);
        for (int i = 0; i < propertyList.size(); ++i) {
            bool exists;
            s = propertyList.at(i);
            ScopedValue v(scope, o->get(s.getPointer(), &exists));
            if (!exists)
                continue;
            QString member = makeMember(s->toQString(), v);
            if (!member.isEmpty())
                partial += member;
        }
    }

    if (partial.isEmpty()) {
        result = QStringLiteral("{}");
    } else if (gap.isEmpty()) {
        result = QStringLiteral("{") + partial.join(QLatin1Char(',')) + QStringLiteral("}");
    } else {
        QString separator = QStringLiteral(",\n") + indent;
        result = QStringLiteral("{\n") + indent + partial.join(separator) + QStringLiteral("\n") + stepback + QStringLiteral("}");
    }

    indent = stepback;
    stack.pop();
    return result;
}
Example #10
0
/**
 * \copydoc REntityData::getLineweight
 */
RLineweight::Lineweight REntity::getLineweight(bool resolve,
    const QStack<REntity*>& blockRefStack) const {

    QStack<REntity*> newBlockRefStack = blockRefStack;
    if (!newBlockRefStack.isEmpty() && this==(REntity*)newBlockRefStack.top()) {
        newBlockRefStack.pop();
    }

    return getData().getLineweight(resolve, newBlockRefStack);
}
Example #11
0
int main(int argc, char *argv[])
{
//! [0]
    QStack<int> stack;
    stack.push(1);
    stack.push(2);
    stack.push(3);
    while (!stack.isEmpty())
        cout << stack.pop() << endl;
//! [0]
}
Example #12
0
int main ()
{

  QStack<int> first;    
  first.push(1);
  assert(first.top() == 1);
  first.pop();
  first.push(2);
  assert(first.top() == 2);

  return 0;
}
void
BookmarkModel::setBookmarks(const QByteArray &bookmarks)
{
    beginResetModel();

    delete rootItem;
    folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon);
    bookmarkIcon = QIcon(QLatin1String(":/trolltech/assistant/images/bookmark.png"));

    rootItem = new BookmarkItem(DataVector() << tr("Name") << tr("Address")
        << true);

    QStack<BookmarkItem*> parents;
    QDataStream stream(bookmarks);

    qint32 version;
    stream >> version;
    if (version < VERSION) {
        stream.device()->seek(0);
        BookmarkItem* toolbar = new BookmarkItem(DataVector() << tr("Toolbar Menu")
            << QLatin1String("Folder") << true);
        rootItem->addChild(toolbar);

        BookmarkItem* menu = new BookmarkItem(DataVector() << tr("Bookmarks Menu")
            << QLatin1String("Folder") << true);
        rootItem->addChild(menu);
        parents.push(menu);
    } else {
        parents.push(rootItem);
    }

    qint32 depth;
    bool expanded;
    QString name, url;
    while (!stream.atEnd()) {
        stream >> depth >> name >> url >> expanded;
        while ((parents.count() - 1) != depth)
            parents.pop();

        BookmarkItem *item = new BookmarkItem(DataVector() << name << url << expanded);
        if (url == QLatin1String("Folder")) {
            parents.top()->addChild(item);
            parents.push(item);
        } else {
            parents.top()->addChild(item);
        }
    }

    cache.clear();
    setupCache(index(0,0, QModelIndex().parent()));
    endResetModel();
}
/** depth first search of widgets hierarchy, from application topLevelWidgets
 */
static QWidget *search_widget(std::function<bool(QWidget* w)> match) {
    foreach (auto widget, QApplication::topLevelWidgets()) {
        QStack<QObject*> s;
        s.push(widget);
        while (!s.isEmpty()) {
            auto p = qobject_cast<QWidget*>(s.pop());
            if (match(p))
                return p;
            foreach (auto c, p->children())
                if (c->isWidgetType())
                    s.push(c);
        }
    }
Example #15
0
void Scanner::scanRecursive(QDir &d, ReleaseFileList &r, QStack<QString> &dirname)
{
    QDirIterator it(d);
    static QString pathDelim="/";

    while (it.hasNext()) {
        it.next();

        QFileInfo info = it.fileInfo();
        if (info.isDir()) {
            if (info.fileName()[0]=='.') {
                continue;
            }
            QDir nd(info.filePath());
            dirname.push(info.fileName());
            scanRecursive(nd, r,dirname);
            dirname.pop();
        } else {
            QFile file(info.filePath());
            ReleaseFile rf;

            if (file.open(QIODevice::ReadOnly) <0) {
                throw 2;
            }

            rf.sha = hashFile(file);

            

            dirname.push( info.fileName() );
            rf.name = qstackJoin( dirname, pathDelim);
            rf.size = info.size();
            rf.exec = info.isExecutable();
            r.push_back(rf);
            dirname.pop();
            file.close();
        }
    }
}
quint64 RecursiveDirJobHelper::calculateDirSize(const QString & dir)
{
    QDir currentDir(dir);
    if ( !currentDir.exists() ) {
        emit errorOccured(Error(Error::NoSuchFileOrDirectory, dir));
        return 0;
    }

    QFileInfoList currentList = currentDir.entryInfoList(dirFilters);
    QFileInfo currentItem;
    QStack<QFileInfoList> stack;
    quint64 totalSize = 0;
    int refreshCounter = 0;

    if ( m_reportProgress ) {
        //show busy waiting indicator
        emit setMaximum(0);
        emit setValue(0);
    }

    while(1){
        if ( !currentList.isEmpty() ){
            currentItem = currentList.takeFirst();
            totalSize += stat_size(currentItem.absoluteFilePath());

            if ( currentItem.isDir() && !currentItem.isSymLink() ) {
                if ( !currentDir.cd(currentItem.fileName()) ) {
                    emit errorOccured(Error(Error::AccessDenied, currentItem.absoluteFilePath()));
                } else {
                    stack.push(currentList);
                    currentList = currentDir.entryInfoList(dirFilters);
                }
            }

            if ( m_reportProgress && (++refreshCounter % 100 == 0) )
                emit setLabelText( tr("Calculating the size of \"%1\"... %2")
                                    .arg(dir).arg(DirOperations::bytesToString(totalSize)) );

        } else { // list is empty
            if ( !stack.isEmpty() ){
                currentList = stack.pop();
                currentDir.cdUp();
            } else
                break;
        }
    }

    totalSize += stat_size(dir);
    qDebug() << "calculateDirSize" << dir << totalSize;
    return totalSize;
}
void StandardTreeModel::load(const QString &filename)
{
    if (!filename.isEmpty())
        m_filename = filename;
    if (m_filename.isEmpty())
        throw AQP::Error(tr("no filename specified"));
    QFile file(m_filename);
    if (!file.open(QIODevice::ReadOnly))
        throw AQP::Error(file.errorString());

    clear();

    QStack<QStandardItem*> stack;
    stack.push(invisibleRootItem());
    QXmlStreamReader reader(&file);
    while (!reader.atEnd()) {
        reader.readNext();
        if (reader.isStartElement()) {
            if (reader.name() == TaskTag) {
                const QString name = reader.attributes()
                        .value(NameAttribute).toString();
                bool done = reader.attributes().value(DoneAttribute)
                            == "1";
                StandardItem *nameItem = createNewTask(stack.top(),
                                                       name, done);
                stack.push(nameItem);
            }
            else if (reader.name() == WhenTag) {
                const QDateTime start = QDateTime::fromString(
                        reader.attributes().value(StartAttribute)
                            .toString(), Qt::ISODate);
                const QDateTime end = QDateTime::fromString(
                        reader.attributes().value(EndAttribute)
                            .toString(), Qt::ISODate);
                StandardItem *nameItem = static_cast<StandardItem*>(
                        stack.top());
                nameItem->addDateTime(start, end);
            }
        }
        else if (reader.isEndElement()) {
            if (reader.name() == TaskTag)
                stack.pop();
        }
    }
    if (reader.hasError())
        throw AQP::Error(reader.errorString());
    if (stack.count() != 1 || stack.top() != invisibleRootItem())
        throw AQP::Error(tr("loading error: possibly corrupt file"));

    calculateTotalsFor(invisibleRootItem());
}
Example #18
0
int ScCodeEditor::indentationLevel(const QTextCursor & cursor)
{
    QTextDocument *doc = QPlainTextEdit::document();
    int startBlockNum = doc->findBlock(cursor.selectionStart()).blockNumber();

    QStack<int> stack;
    int level = 0;
    int blockNum = 0;
    QTextBlock block = QPlainTextEdit::document()->begin();
    while (block.isValid()) {
        if (level > 0) {
            stack.push(level);
            level = 0;
        }

        TextBlockData *data = static_cast<TextBlockData*>(block.userData());
        if (data) {
            int count = data->tokens.size();
            for (int idx = 0; idx < count; ++idx) {
                const Token & token = data->tokens[idx];
                switch (token.type) {
                case Token::OpeningBracket:
                    if (token.character != '(' || stack.size() || token.positionInBlock)
                        level += 1;
                    break;

                case Token::ClosingBracket:
                    if (level)
                        level -= 1;
                    else if(!stack.isEmpty()) {
                        stack.top() -= 1;
                        if (stack.top() <= 0)
                            stack.pop();
                    }
                    break;

                default:
                    ;
                }
            }
        }

        if (blockNum == startBlockNum)
            return stack.size();

        block = block.next();
        ++blockNum;
    }

    return -1;
}
Example #19
0
File: fight.cpp Project: q4a/attal
void Fight::moveUnit( FightCell * cell )
{
	GenericFightCell * current;
	QStack<GenericFightCell> path = _map->computePath( _activeUnit, cell );

	while( ! path.isEmpty() ) {
		current = path.pop();
		_socket->sendFightUnitMove( giveClass( _activeUnit ), giveNum( _activeUnit ), current );
	}

	_socket->sendFightUnitEndMove();
	_activeUnit->setActive( false );
	_map->clearPath();
}
Example #20
0
void HandleObject::reset()
{
    QStack<const QMetaObject *> aMetaObjects;

    const QMetaObject *aMetaObject=mObject->metaObject();

    while (aMetaObject)
    {
        aMetaObjects.push(aMetaObject);
        aMetaObject=aMetaObject->superClass();
    }

    clear();

    while (!aMetaObjects.isEmpty())
    {
        aMetaObject=aMetaObjects.pop();

        QString aClassName=aMetaObject->className();

        if (!mController->filterClass(aClassName))
        {
            continue;
        }

        PropertyGroup *aPropertyGroup=new PropertyGroup(aMetaObject, aClassName);

        mClassProperties.append(aPropertyGroup);

        for (int j=aMetaObject->propertyOffset(); j<aMetaObject->propertyCount(); ++j)
        {
            QMetaProperty aProperty=aMetaObject->property(j);

            if (
                !aProperty.isReadable()
                ||
                !mController->filterProperty(aMetaObject, aProperty.name())
               )
            {
                continue;
            }

            Property *aNewProperty=new Property(aMetaObject, aProperty, mController);
            QObject::connect(aNewProperty, SIGNAL(valueChanged(QVariant)), mController, SLOT(valueChangedSlot(QVariant)));
            aPropertyGroup->addProperty(aNewProperty);

            mController->propertyAdded(aNewProperty, aMetaObject, aProperty.name());
        }
    }
}
Example #21
0
QBrush RExporter::getBrush(const RPainterPath& path) {
    if (path.isFixedBrushColor()) {
        // brush is fixed color (text color given):
        QBrush brush = currentBrush;
        QColor color = path.getBrush().color();
        // color fixed to "by layer":
        if (color==RColor::CompatByLayer) {
            if (currentLayer!=NULL) {
                color = currentLayer->getColor();
            }
            else {
                qWarning("color by layer but current layer is NULL");
                Q_ASSERT(false);
            }
        }
        // color fixed to "by block" (which really means by block reference):
        if (color==RColor::CompatByBlock) {
            if (!blockRefStack.isEmpty()) {
                QStack<REntity*> newBlockRefStack;
                newBlockRefStack = blockRefStack;
                newBlockRefStack.pop();
                color = blockRefStack.top()->getColor(true, newBlockRefStack);
            }
            else {
                // this can happen (by block at top level):
                color = RColor(Qt::white);
                //qWarning("color by block but current block reference is NULL");
                //Q_ASSERT(false);
            }
        }
        REntity* e=getEntity();
        if (e!=NULL && e->isSelected()) {
            brush.setColor(RSettings::getSelectionColor());
        }
        else {
            brush.setColor(color);
        }
        return brush;
    }
    else {
        // brush is current brush or no brush:
        if (path.getBrush().style()!=Qt::NoBrush) {
            // brush is current brush:
            return currentBrush;
        }
        else {
            return path.getBrush();
        }
    }
}
Example #22
0
void MainWindow::on_pushButton_clicked()
{
    QStack<QString> stk;
    QString str = ui->textEdit->toPlainText(), str2=str;
    bool f=false;
    bool Pr=false, f2=true,f3=true;

    for(int i=0; i<str.count();i++)
        if ((str.at(i)=='0')||(str.at(i)=='1'))
              Pr= true;
    else
            Pr = false;


//        if(str.count("0")!=str.count("1"))
//            f3=false;

    if(str.isEmpty()||(Pr==false))//||(f3=false))
    {
        ui->textEdit_2->insertPlainText("Error");
    }
        else
        {
         for(int i=0;i<str.count();i++)
            {
             if (str.at(i)=='0')
             {
                 stk.push("0");
                 f=true;

             }
             if ((str.at(i)=='1'))
                 if(!stk.empty())
                 stk.pop();
                 else
                 {
                 ui->textEdit_2->insertPlainText("Error");
                 f2=false;
                 break;
                 }


       }
    }


    if ((f==true)&&(stk.isEmpty())&&(f2))
        ui->textEdit_2->insertPlainText("Right");
}
void ShareDirModel::beginExpanding(){
    for (const QString &f : checked){
        QStack<QModelIndex> stack;
        QModelIndex i = index(f);

        while (i.isValid()){
            stack.push(i);

            i = i.parent();
        }

        while (!stack.isEmpty())
            emit expandMe(stack.pop());
    }
}
void ScriptDebuggerPrivate::functionExit(qint64 scriptId,
                                         const QScriptValue &/*returnValue*/)
{
    if (scriptId != -1) {
        QScriptContext *ctx = engine()->currentContext();
        QStack<qint64> ids = m_contextProgramIds.value(ctx);
        Q_ASSERT(!ids.isEmpty());
        Q_ASSERT(ids.top() == scriptId);
        ids.pop();
        m_contextProgramIds.insert(ctx, ids);
    }

    if (mode() == StepOver)
        --m_stepDepth;
}
Example #25
0
void DetailsWidget::fixUpLayout()
{
    if (!m_widget)
        return;
    QWidget *parent = m_widget;
    QStack<QWidget *> widgets;
    while((parent = parent->parentWidget()) && parent && parent->layout()) {
        widgets.push(parent);
        parent->layout()->update();
    }

    while(!widgets.isEmpty()) {
        widgets.pop()->layout()->activate();
    }
}
Example #26
0
void Graph::dfs(int s) {
  QStack<int> stack;
  stack.push(s);

  while (!stack.isEmpty()) {
    int s = stack.pop();
    visited_[s] = true;

    for (auto e : r_edges_[s].keys()) {
      if (!visited_[e] && qAbs(r_edges_[s][e])>Float::epsilon()) {
        stack.push(e);
      }
    }
  }
}
Example #27
0
bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
{
    const QString resolvedParent = provider()->resolveAlias(parent);
    //Q_ASSERT(provider()->resolveAlias(mime) == mime);
    QStack<QString> toCheck;
    toCheck.push(mime);
    while (!toCheck.isEmpty()) {
        const QString current = toCheck.pop();
        if (current == resolvedParent)
            return true;
        foreach (const QString &par, provider()->parents(current))
            toCheck.push(par);
    }
    return false;
}
Example #28
0
bool CacheReader::parse( const QString& file )
{
  mText.clear();
  mRanges.clear();

  if ( !readAll( file, &mText ) ) {
    return false;
  }
  const int length = mText.length();

  static const QString patternStart = QStringLiteral( "<FILENAME filename=\"" );
  static const QString patternEnd = QStringLiteral( "</FILENAME>" );

  QStack<QString> stack;

  int index = 0;
  while ( index < length ) {
    int start = mText.indexOf( patternStart, index );
    int end = mText.indexOf( patternEnd, index );

    if ( start >= 0 && start < end ) {
      // new document
      const int quote = mText.indexOf( '"', start + patternStart.length() );
      const QString name = mText.mid( start + patternStart.length(), quote - ( start + patternStart.length() ) );
      if ( stack.isEmpty() ) {
      } else {
        if ( start > index ) {
          mRanges.insert( stack.top(), qMakePair( index, start - 1 ) );
        }
      }
      index = quote + 2;
      stack.push( name );
    } else if ( end >= 0 ) {
      // end of current document
      Q_ASSERT( !stack.isEmpty() );
      mRanges.insert( stack.top(), qMakePair( index, end - 1 ) );
      index = end + patternEnd.length();
      stack.pop();
    } else {
      break;
    }
  }

  Q_ASSERT( stack.isEmpty() );

  return true;
}
Example #29
0
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;
            }
        }
}
Example #30
0
const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
{
    if ( m_docSynopsis )
        return m_docSynopsis;

    m_docSynopsis = new Okular::DocumentSynopsis();

    userMutex()->lock();

    QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();

    userMutex()->unlock();

    if ( prebookmarks.isEmpty() ) 
        return m_docSynopsis;

    QStack<QDomElement> stack;

    QVector<PreBookmark>::ConstIterator it = prebookmarks.constBegin();
    QVector<PreBookmark>::ConstIterator itEnd = prebookmarks.constEnd();
    for( ; it != itEnd; ++it ) 
    {
        QDomElement domel = m_docSynopsis->createElement( (*it).title );
        Anchor a = m_dviRenderer->findAnchor((*it).anchorName);
        if ( a.isValid() )
        {
            Okular::DocumentViewport vp;
 
            const Okular::Page *p = document()->page( a.page - 1 );

            fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height() );
            domel.setAttribute( "Viewport", vp.toString() );
        }
        if ( stack.isEmpty() )
            m_docSynopsis->appendChild( domel );
        else 
        {
            stack.top().appendChild( domel );
            stack.pop();
        }
        for ( int i = 0; i < (*it).noOfChildren; ++i )
            stack.push( domel );
    }

    return m_docSynopsis;
}