Beispiel #1
0
void PgxEditor::executeText()
{
    if(toPlainText().simplified().isEmpty())
        return;
    if(textCursor().selectedText().isEmpty())
            emit showQueryView(database, toPlainText().replace(QChar::ParagraphSeparator,"\n"));
    else
        emit showQueryView(database, textCursor().selectedText().replace(QChar::ParagraphSeparator,"\n"));
}
Beispiel #2
0
void PgxConsole::showView(QString cmd)
{
    if(cmd.isEmpty()) {
        if(!textCursor().atEnd()) {
            QTextCursor cursor = textCursor();
            cursor.movePosition(QTextCursor::End);
            setTextCursor(cursor);
        }
        QTextBlock block = document()->end();
        if(!block.isValid())
            block = block.previous();
        cmd = block.text().trimmed();
        for (block = block.previous(); block.text().endsWith("\\"); block = block.previous())
            cmd.insert(0, block.text().trimmed().replace(QLatin1String("\\"), QLatin1String(" ")));
        // Do nothing on whitespace input.
        if(cmd.trimmed().isEmpty()) {
            appendPlainText("");
            return;
        }
    }
    // Save the command into the command history and
    // reassign the history iterator.
    history << cmd;
    hit = history.size();

    // 'clear' command to clear the console keeping the
    // history intact.
    if(cmd.compare("clear", Qt::CaseInsensitive) == 0)
        clear();
    // 'clearh' command to clear the history alone. Console
    // is not cleared.
    else if(cmd.compare("clearh", Qt::CaseInsensitive) == 0) {
        history.clear();
        hit = 0;
        appendPlainText("");
    }
    // 'clearall' command to clear console and history
    else if(cmd.compare("clearall", Qt::CaseInsensitive) == 0) {
        history.clear();
        hit = 0;
        clear();
    }
    // 'quit' command to clear console and history
    else if(cmd.compare("quit", Qt::CaseInsensitive) == 0) {
        history.clear();
        hit = 0;
        clear();
        pgxconsole_mainwin->close();
        return;
    }
    // 'exit' command to clear console and history
    else if(cmd.compare("exit", Qt::CaseInsensitive) == 0) {
        history.clear();
        hit = 0;
        clear();
        pgxconsole_mainwin->close();
    }
    else {
        // Reduce all groups of whitespace characters
        // to a single space between words.
        cmd = cmd.simplified();
        // Start a timer to count the seconds taken to display the
        // required output (used for queries and tables only).
        QTime t;
        t.start();
        emit showQueryView(database, cmd);
        appendPlainText("");
    }
}