void GettingStartedWelcomePageWidget::slotOpenExample()
{
    QAction *action = qobject_cast<QAction*>(sender());
    if (!action)
        return;

    QString helpFile = action->property(HelpPathPropertyName).toString();
    QString proFile = action->property(ExamplePathPropertyName).toString();
    QString qmlMainFileName;
    bool isQmlProject = false;
    if (action->dynamicPropertyNames().contains(QmlMainFileName)) {
        qmlMainFileName = action->property(QmlMainFileName).toString();
        isQmlProject = true;
    }
    QStringList files;

    QFileInfo proFileInfo(proFile);
    // If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
    if (!proFileInfo.isWritable())
    {
        QDialog d;
        QGridLayout *lay = new QGridLayout(&d);
        QLabel *descrLbl = new QLabel;
        d.setWindowTitle(tr("Copy Project to writable Location?"));
        descrLbl->setTextFormat(Qt::RichText);
        descrLbl->setWordWrap(true);
        descrLbl->setText(tr("<p>The project you are about to open is located in the "
                             "write-protected location:</p><blockquote>%1</blockquote>"
                             "<p>Please select a writable location below and click \"Copy Project and Open\" "
                             "to open a modifiable copy of the project or click \"Keep Project and Open\" "
                             "to open the project in location.</p><p><b>Note:</b> You will not "
                             "be able to alter or compile your project in the current location.</p>")
                          .arg(QDir::toNativeSeparators(proFileInfo.dir().absolutePath())));
        lay->addWidget(descrLbl, 0, 0, 1, 2);
        QLabel *txt = new QLabel(tr("&Location:"));
        Utils::PathChooser *chooser = new Utils::PathChooser;
        txt->setBuddy(chooser);
        chooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
        QSettings *settings = Core::ICore::instance()->settings();
        chooser->setPath(settings->value(
                QString::fromLatin1("General/ProjectsFallbackRoot"), QDir::homePath()).toString());
        lay->addWidget(txt, 1, 0);
        lay->addWidget(chooser, 1, 1);
        QDialogButtonBox *bb = new QDialogButtonBox;
        connect(bb, SIGNAL(accepted()), &d, SLOT(accept()));
        connect(bb, SIGNAL(rejected()), &d, SLOT(reject()));
        QPushButton *copyBtn = bb->addButton(tr("&Copy Project and Open"), QDialogButtonBox::AcceptRole);
        copyBtn->setDefault(true);
        bb->addButton(tr("&Keep Project and Open"), QDialogButtonBox::RejectRole);
        lay->addWidget(bb, 2, 0, 1, 2);
        connect(chooser, SIGNAL(validChanged(bool)), copyBtn, SLOT(setEnabled(bool)));
        if (d.exec() == QDialog::Accepted) {
            QString exampleDirName = proFileInfo.dir().dirName();
            QString toDir = chooser->path();
            settings->setValue(QString::fromLatin1("General/ProjectsFallbackRoot"), toDir);
            QDir toDirWithExamplesDir(toDir);
            if (toDirWithExamplesDir.cd(exampleDirName)) {
                toDirWithExamplesDir.cdUp(); // step out, just to not be in the way
                QMessageBox::warning(topLevelWidget(), tr("Warning"),
                                     tr("The specified location already exists. "
                                        "Please specify a valid location."),
                                     QMessageBox::Ok, QMessageBox::NoButton);
                return;
            } else {
                QDir from = proFileInfo.dir();
                from.cdUp();
                copyRecursive(from, toDir, exampleDirName);
                // set vars to new location
                proFileInfo = QFileInfo(toDir + '/'+ exampleDirName + '/' + proFileInfo.fileName());
                proFile = proFileInfo.absoluteFilePath();
            }
        }
    }

    QString tryFile;
    files << proFile;
    if (isQmlProject) {
        tryFile = proFileInfo.path() + '/' + "/main.qml";
        if(!QFile::exists(tryFile))
            tryFile = proFileInfo.path() + "/qml/" + qmlMainFileName + ".qml";
        // legacy qmlproject case
        if(!QFile::exists(tryFile))
            tryFile = proFileInfo.path() + '/' + qmlMainFileName + ".qml";
        if(QFile::exists(tryFile))
            files << tryFile;
    } else {
        tryFile = proFileInfo.path() + "/main.cpp";
        if(!QFile::exists(tryFile))
            tryFile = proFileInfo.path() + '/' + proFileInfo.baseName() + ".cpp";
    }
    Core::ICore::instance()->openFiles(files, static_cast<Core::ICore::OpenFilesFlags>(Core::ICore::SwitchMode | Core::ICore::StopOnLoadFail));
    if (!tryFile.isEmpty() && Core::EditorManager::instance()->hasEditor(tryFile) && !helpFile.isEmpty())
        slotOpenContextHelpPage(helpFile);
}
Пример #2
0
//开始编译
void FMainWidgt::sartCompling()
{
    qDebug() << ">>>>> Current ComplingIndex>>> " << m_nCurrentComplingIndex;
    if(m_nCurrentComplingIndex == m_pSourceProFileModel->rowCount())
    {
        setErrorStatusTip(eCompli_Completed);

        if(m_nCurrentErrorCount > 0)
        {
            ui->logTabWgt->setCurrentWidget(ui->errorLogTab);
        }

        return ;
    }

    //判断当前编译是否已经成功,如果成功跳转下一行,
    int nCompileStatus = m_pSourceProFileModel->data(m_pSourceProFileModel->index(m_nCurrentComplingIndex,
                                                              eCol_CompilingStatus),
                                            Qt::UserRole+1).toInt();

    while(nCompileStatus == eCompile_Succeed)
    {
        if(m_nCurrentComplingIndex + 1 >= m_pSourceProFileModel->rowCount())
        {
            setErrorStatusTip(eCompli_Completed);
            return ;
        }

        m_nCurrentComplingIndex++;

        nCompileStatus = m_pSourceProFileModel->data(m_pSourceProFileModel->index(m_nCurrentComplingIndex,
                                                                      eCol_CompilingStatus),
                                                    Qt::UserRole+1).toInt();
    }

    QString sProFileName = m_pSourceProFileModel->data(m_pSourceProFileModel->index(m_nCurrentComplingIndex,
                                                          eCol_FileName),
                                        Qt::UserRole+1).toString();

    QFileInfo proFileInfo(sProFileName);

    qDebug() << proFileInfo.baseName();

    QString sBuildPath = ui->compiledPathLdt->text()+ "/" +
                            proFileInfo.baseName() + "_build";

    QDir buildDir;
    buildDir.setPath(sBuildPath);

    if(!buildDir.exists())
    {
        buildDir.mkpath(sBuildPath);
    }

    QDir::setCurrent(sBuildPath);

    QStringList lArguments;
    lArguments << sProFileName;

    m_nProcessFlg = eCreateMakeFile_Process;
    m_pCurrProcess->start(ui->qmakePathLndt->text(), lArguments);
}