void PathChooserDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(editor); if (!pathChooser) return; model->setData(index, pathChooser->path(), Qt::EditRole); }
void Qt4TargetSetupWidget::pathChanged() { if (m_ignoreChange) return; Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(sender()); if (!pathChooser) return; int index = m_pathChoosers.indexOf(pathChooser); if (index == -1) return; m_infoList[index].directory = pathChooser->path(); reportIssues(index); }
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); }