Example #1
0
void PGE_Menu::sort()
{
    if(_items.size()<=1) {
        autoOffset();    //Nothing to sort!
        return;
    }

    QStack<int> beg;
    QStack<int> end;
    PGE_Menuitem * piv;
    int i=0, L, R, swapv;
    beg.push_back(0);
    end.push_back(_items.size());
    while (i>=0)
    {
        L=beg[i];
        R=end[i]-1;
        if (L<R)
        {
            piv=_items[L];
            while (L<R)
            {
                while ((namefileMoreThan(_items[R], piv)) && (L<R)) R--;
                if (L<R) _items[L++]=_items[R];

                while ((namefileLessThan(_items[L], piv)) && (L<R)) L++;
                if (L<R) _items[R--]=_items[L];
            }
            _items[L]=piv;
            beg.push_back(L+1);
            end.push_back(end[i]);
            end[i++]=(L);
            if((end[i]-beg[i]) > (end[i-1]-beg[i-1]))
            {
                swapv=beg[i];
                beg[i]=beg[i-1];
                beg[i-1]=swapv;
                swapv=end[i];
                end[i]=end[i-1];
                end[i-1]=swapv;
            }
        }
        else
        {
            i--;
            beg.pop_back();
            end.pop_back();
        }
    }

    autoOffset();
}
Example #2
0
void KoTextWriter::Private::writeBlocks(QTextDocument *document, int from, int to, QHash<QTextList *, QString> &listStyles, QTextTable *currentTable, QTextList *currentList)
{
    pairedInlineObjectsStackStack.push(currentPairedInlineObjectsStack);
    currentPairedInlineObjectsStack = new QStack<KoInlineObject*>();
    QTextBlock block = document->findBlock(from);

    // Here we are going to detect all sections that
    // are positioned entirely inside selection.
    // They will stay untouched, and others will be omitted.

    // So we are using stack to detect them, by going through
    // the selection and finding open/close pairs.
    QSet<QString> entireWithinSectionNames;
    QStack<QString> sectionNamesStack;
    QTextCursor cur(document);
    cur.setPosition(from);
    while (to == -1 || cur.position() <= to) {
        if (cur.block().position() >= from) { // Begin of the block is inside selection.
            foreach (const KoSection *sec, KoSectionUtils::sectionStartings(cur.blockFormat())) {
                sectionNamesStack.push_back(sec->name());
            }
        }

        if (to == -1 || cur.block().position() + cur.block().length() - 1 <= to) { // End of the block is inside selection.
            foreach (const KoSectionEnd *sec, KoSectionUtils::sectionEndings(cur.blockFormat())) {
                if (!sectionNamesStack.empty() && sectionNamesStack.top() == sec->name()) {
                    sectionNamesStack.pop();
                    entireWithinSectionNames.insert(sec->name());
                }
            }
        }
Example #3
0
void PGE_LevelCamera::sortElements()
{
    if(objects_to_render.size()<=1) return; //Nothing to sort!
    QStack<int> beg;
    QStack<int> end;
    PGE_Phys_Object* piv;
    int i=0, L, R, swapv;
    beg.push_back(0);
    end.push_back(objects_to_render.size());
    while (i>=0)
    {
        L=beg[i]; R=end[i]-1;
        if (L<R)
        {
            piv=objects_to_render[L];
            while (L<R)
            {
                while ((objects_to_render[R]->zIndex()>=piv->zIndex()) && (L<R)) R--;
                if (L<R) objects_to_render[L++]=objects_to_render[R];

                while ((objects_to_render[L]->zIndex()<=piv->zIndex()) && (L<R)) L++;
                if (L<R) objects_to_render[R--]=objects_to_render[L];
            }
            objects_to_render[L]=piv; beg.push_back(L+1); end.push_back(end[i]); end[i++]=(L);
            if((end[i]-beg[i]) > (end[i-1]-beg[i-1]))
            {
                swapv=beg[i]; beg[i]=beg[i-1]; beg[i-1]=swapv;
                swapv=end[i]; end[i]=end[i-1]; end[i-1]=swapv;
            }
        }
        else
        {
            i--;
            beg.pop_back();
            end.pop_back();
        }
    }
}
Example #4
0
void XLIFFHandler::pushContext(XliffContext ctx)
{
    m_contextStack.push_back(ctx);
}
Example #5
0
void FileIndexThread::run()
{
    struct PathToIndex
    {
        QString path;
        bool    recursive;
        QStringList filter;
    };

#ifdef Q_OS_UNIX
    static const QList<PathToIndex> pathsToIndex = {
        { "/usr/share/applications", true, { "*.desktop" } },
        { QDir(QDir::homePath()).relativeFilePath(".local/share/applications"), true, { "*.desktop" } },
        { QDir(QDir::homePath()).relativeFilePath("Desktop"), true, { "*.desktop" } },
    };
#elif defined(Q_OS_WIN)
    QList<PathToIndex> pathsToIndex = {
        { QSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", QSettings::NativeFormat).value("Common Desktop").toString(), true, { "*.lnk" } },
        { QSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", QSettings::NativeFormat).value("Common Start Menu").toString(), true, { "*.lnk" } },
    };

    {
        // There are newer API functions for this; but they are only for Vista and newer
        WCHAR szPath[MAX_PATH];
        HRESULT hr = SHGetFolderPathW(0, CSIDL_STARTMENU, 0, 0, szPath);
        if (SUCCEEDED(hr))
            pathsToIndex.push_back({ QString::fromWCharArray(szPath), true, { "*.lnk" } });

        hr = SHGetFolderPathW(0, CSIDL_DESKTOPDIRECTORY, 0, 0, szPath);
        if (SUCCEEDED(hr))
            pathsToIndex.push_back({ QString::fromWCharArray(szPath), true, { "*.lnk" } });
    }
#else
#error "Not implemented for this operating system"
#endif

    for (const PathToIndex& pathInfo : pathsToIndex)
    {
        const QString pathString = expandEnvironmentPath(pathInfo.path);
        QStack<QString> dirstack;
        dirstack.push_back(expandEnvironmentPath(pathString));

        while (dirstack.empty() == false)
        {
            QDir path(dirstack.pop());
            path.setNameFilters(pathInfo.filter);

            for (const QString& filename : path.entryList())
            {
                int dot = filename.lastIndexOf('.');
                const QString basename = dot > 0 ? filename.left(dot) : filename;

                dbLock.lockForWrite();
                this->db.add(basename, basename, path.absoluteFilePath(filename), QStringList());
                dbLock.unlock();
            }

            // For now, no symlink traversal to avoid loops
            for (const QString& dirname : path.entryList(QStringList(), QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot))
            {
                dirstack.push_back(path.absoluteFilePath(dirname));
            }
        }
    }

#ifdef Q_OS_WIN
    const QString systemPath = getWindowsSystemPath();

    for (const QString& filename : QDir(systemPath).entryList({ "*.cpl" }))
    {
        readCpl(filename, this->db, this->dbLock);
    }
#endif

    emit indexDone();
}
Example #6
0
bool SimpleJsonParser::parse(const QByteArray& json)
{
	resetState();

	m_source = json;
	m_ptr = m_source.data();
	m_end = m_ptr + m_source.length();

	QStack<QString> stack;
	QVariantMap result;

	QVector<Token> expectedTokens;
	expectedTokens.push_back(Token_Begin);
	Token prevToken = Token_ERROR;

	QString lastStr;
	QString prefix;
	QString lastKey;

	for (;;) {
		Token token = nextToken();
		if (expectedTokens.indexOf(token) < 0) {
			DBGLOG(LOG_ERROR, 2, QString::fromUtf8("unexpected token %1").arg(token));
			return false;
		}
		switch (token) {
		case Token_ERROR:
			return false;
		case Token_EOF:
			if (!stack.empty()) {
				DBGLOG(LOG_ERROR, 2, QString::fromUtf8("unblanced { }, bad json!"));
				return false;
			}
			m_result = result;
			return true;
		case Token_Begin:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token BEGIN"));
			if (stack.empty()) {
				stack.push_back(QString::fromUtf8(""));
			} else {
				stack.push_back(prefix);
				prefix.append(lastKey);
				prefix.append(QChar::fromAscii('.'));
			}
			expectedTokens.clear();
			expectedTokens.push_back(Token_End);
			expectedTokens.push_back(Token_String);
			break;
		case Token_End:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token END"));
			prefix = stack.pop();
			if (!stack.empty()) {
				expectedTokens.clear();
				expectedTokens.push_back(Token_Comma);
				expectedTokens.push_back(Token_End);
			} else {
				expectedTokens.push_back(Token_EOF);
			}
			break;
		case Token_Comma:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token COMMA"));
			expectedTokens.clear();
			expectedTokens.push_back(Token_End);
			expectedTokens.push_back(Token_String);
			break;
		case Token_Colon:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token COLON"));
			expectedTokens.clear();
			expectedTokens.push_back(Token_Begin);
			expectedTokens.push_back(Token_String);
			expectedTokens.push_back(Token_Number);
			break;
		case Token_String:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token STRING [%1]").arg(QString::fromUtf8(m_str)));

			if (prevToken == Token_Colon) {
				DBGLOG(LOG_DEBUG, 12, QString::fromUtf8("submit '%3%1'='%2'").arg(lastKey).arg(QString::fromUtf8(m_str)).arg(prefix));
				result.insert(prefix + lastKey, QString::fromUtf8(m_str));
			} else {
				lastKey = QString::fromUtf8(m_str);
			}

			// TODO:
			expectedTokens.clear();
			expectedTokens.push_back(Token_End);
			expectedTokens.push_back(Token_Comma);
			expectedTokens.push_back(Token_Colon);
			break;
		case Token_Number:
			DBGLOG(LOG_DEBUG, 8, QString::fromUtf8("token NUMBER [%1]").arg(m_num));
			DBGLOG(LOG_DEBUG, 12, QString::fromUtf8("submit '%3%1'=%2").arg(lastKey).arg(m_num).arg(prefix));
			result.insert(prefix + lastKey, m_num);
			expectedTokens.clear();
			expectedTokens.push_back(Token_End);
			expectedTokens.push_back(Token_Comma);
			break;
		}

		prevToken = token;
	}

	return false;
}