Beispiel #1
0
void toProject::saveProject(void)
{
    toTreeWidgetItem *item = Project->selectedItem();
    if (item)
    {
        toProjectTemplateItem *oi = ItemMap[item];
        if (oi)
        {
            if (!oi->project())
                oi = dynamic_cast<toProjectTemplateItem *>(oi->parent());
            if (oi)
            {
                QFileInfo file(oi->filename());
                QString fn = oi->filename();
                fn = toSaveFilename(file.dir().path(), QString::fromLatin1("*.tpr"), this);
                if (!fn.isEmpty())
                {
                    QString data;
                    for (toTreeWidgetItem *item = oi->firstChild(); item; item = item->nextSibling())
                    {
                        toProjectTemplateItem * projitem = dynamic_cast<toProjectTemplateItem *>(item);
                        data += projitem->filename() + QString::fromLatin1("\n");
                    }
                    // write file, encoded according to locale settings
                    if (toWriteFile(fn, data))
                        oi->setFilename(fn);
                }
            }
        }
    }
}
/* Purpose: calls external static code test tool and display it's results
   TODO: call only selected part of code (if something is selected)
*/
void toPLSQLEditor::checkCode(void)
{
    if (currentEditor()->editor()->text().isEmpty())
    {
        // do nothing if code text is empty
        return;
    }

    QTemporaryFile tf;
    if (tf.open())
    {
        if (!toWriteFile(tf.fileName(), currentEditor()->editor()->text()))
        {
#ifdef DEBUG
            qDebug() << "Unable to write file (" + tf.fileName() + ")";
#endif
            return;
        }
        else
        {
#ifdef DEBUG
            qDebug() << "Success!!! Temporary file " + tf.fileName();
#endif
        }
    }

    QString program = toConfigurationSingle::Instance().staticChecker().arg(tf.fileName());
#ifdef DEBUG
    qDebug() << "program to be executed: " + program;
#endif
    QProcess staticCheck(qApp);

    staticCheck.setProcessChannelMode(QProcess::MergedChannels);
    staticCheck.start(program);
    staticCheck.waitForFinished(); // default timeout - 30000 miliseconds

    int exit_code = staticCheck.exitStatus();
    if (exit_code != 0)
    {
#ifdef DEBUG
        qDebug() << "Error executing static check. Exit code = " << exit_code;
        int run_error = staticCheck.error();
        // error values taken from Qt4.6 documentation for QProcess
        switch (run_error)
        {
        case 0:
            qDebug() << "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.";
            break;
        case 1:
            qDebug() << "The process crashed some time after starting successfully.";
            break;
        case 5:
            qDebug() << "An unknown error occurred.";
            break;
        default:
            qDebug() << "Error code: " << run_error << "--" << staticCheck.errorString();
        } // switch
#endif
        return;
    }
    QString qq = staticCheck.readAllStandardOutput();
#ifdef DEBUG
    qDebug() << "stdout" << qq;
#endif

    QMultiMap<int, QString> Observations;
    parseResults(qq, Observations);
    currentEditor()->editor()->setErrors(Observations, false);
    currentEditor()->applyResult("STATIC", Observations);
    currentEditor()->resizeResults();
} // checkCode