forked from qt-creator/qt-creator
Remove special code path for QML examples
QML examples are now read like any other Qt example, but still get their
own dropdown box.
Advantages: Less code, proper naming, also loads the help if available
Disadvantage: Only contains a few examples, instead of all. We now
trust whoever made the selection for Qt Demo.
Reviewed-by: con
This commit is contained in:
@@ -129,7 +129,6 @@ GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent
|
|||||||
ui->prevFeatureBtn->setEnabled(false);
|
ui->prevFeatureBtn->setEnabled(false);
|
||||||
connect(ui->nextFeatureBtn, SIGNAL(clicked()), this, SLOT(slotNextFeature()));
|
connect(ui->nextFeatureBtn, SIGNAL(clicked()), this, SLOT(slotNextFeature()));
|
||||||
connect(ui->prevFeatureBtn, SIGNAL(clicked()), this, SLOT(slotPrevFeature()));
|
connect(ui->prevFeatureBtn, SIGNAL(clicked()), this, SLOT(slotPrevFeature()));
|
||||||
QTimer::singleShot(0, this, SLOT(slotSetPrivateQmlExamples()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GettingStartedWelcomePageWidget::~GettingStartedWelcomePageWidget()
|
GettingStartedWelcomePageWidget::~GettingStartedWelcomePageWidget()
|
||||||
@@ -140,28 +139,35 @@ GettingStartedWelcomePageWidget::~GettingStartedWelcomePageWidget()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GettingStartedWelcomePageWidget::slotSetPrivateQmlExamples()
|
|
||||||
{
|
|
||||||
if (!ui->qmlExamplesButton->menu()) {
|
|
||||||
const QString resPath = Core::ICore::instance()->resourcePath();
|
|
||||||
updateQmlExamples(resPath, resPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GettingStartedWelcomePageWidget::updateCppExamples(const QString &examplePath,
|
void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
|
||||||
const QString &sourcePath,
|
const QString &demosPath,
|
||||||
const QString &demoXml)
|
const QString &sourcePath)
|
||||||
{
|
{
|
||||||
|
QString demoXml = demosPath + "/qtdemo/xml/examples.xml";
|
||||||
|
if (!QFile::exists(demoXml)) {
|
||||||
|
demoXml = sourcePath + "/demos/qtdemo/xml/examples.xml";
|
||||||
|
if (!QFile::exists(demoXml))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QFile description(demoXml);
|
QFile description(demoXml);
|
||||||
if (!description.open(QFile::ReadOnly))
|
if (!description.open(QFile::ReadOnly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ui->cppExamplesButton->setEnabled(true);;
|
const QString dropDownLabel = tr("Choose an Example...");
|
||||||
ui->cppExamplesButton->setText(tr("Choose an Example..."));
|
|
||||||
|
|
||||||
QMenu *menu = new QMenu(ui->cppExamplesButton);
|
ui->qmlExamplesButton->setEnabled(true);
|
||||||
ui->cppExamplesButton->setMenu(menu);
|
ui->qmlExamplesButton->setText(dropDownLabel);
|
||||||
|
|
||||||
|
QMenu *qmlMenu = new QMenu(ui->qmlExamplesButton);
|
||||||
|
ui->qmlExamplesButton->setMenu(qmlMenu);
|
||||||
|
|
||||||
|
ui->cppExamplesButton->setEnabled(true);
|
||||||
|
ui->cppExamplesButton->setText(dropDownLabel);
|
||||||
|
|
||||||
|
QMenu *cppMenu = new QMenu(ui->cppExamplesButton);
|
||||||
|
ui->cppExamplesButton->setMenu(cppMenu);
|
||||||
|
|
||||||
QMenu *subMenu = 0;
|
QMenu *subMenu = 0;
|
||||||
bool inExamples = false;
|
bool inExamples = false;
|
||||||
@@ -170,104 +176,62 @@ void GettingStartedWelcomePageWidget::updateCppExamples(const QString &examplePa
|
|||||||
|
|
||||||
while (!reader.atEnd()) {
|
while (!reader.atEnd()) {
|
||||||
switch (reader.readNext()) {
|
switch (reader.readNext()) {
|
||||||
case QXmlStreamReader::StartElement:
|
case QXmlStreamReader::StartElement:
|
||||||
if (reader.name() == QLatin1String("category")) {
|
if (reader.name() == QLatin1String("category")) {
|
||||||
QString name = reader.attributes().value(QLatin1String("name")).toString();
|
QString name = reader.attributes().value(QLatin1String("name")).toString();
|
||||||
if (name.contains(QLatin1String("tutorial")))
|
if (name.contains(QLatin1String("tutorial")))
|
||||||
break;
|
break;
|
||||||
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
|
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
|
||||||
subMenu = menu->addMenu(name);
|
subMenu = new QMenu(name);
|
||||||
inExamples = true;
|
inExamples = true;
|
||||||
}
|
}
|
||||||
if (inExamples && reader.name() == QLatin1String("example")) {
|
if (inExamples && reader.name() == QLatin1String("example")) {
|
||||||
const QChar slash = QLatin1Char('/');
|
const QChar slash = QLatin1Char('/');
|
||||||
const QString name = reader.attributes().value(QLatin1String("name")).toString();
|
const QString name = reader.attributes().value(QLatin1String("name")).toString();
|
||||||
|
const bool isQml = reader.attributes().value(QLatin1String("qml")).toString() == "true";
|
||||||
const QString fn = reader.attributes().value(QLatin1String("filename")).toString();
|
const QString fn = reader.attributes().value(QLatin1String("filename")).toString();
|
||||||
const QString relativeProPath = slash + dirName + slash + fn + slash + fn + QLatin1String(".pro");
|
const QString extension = isQml ? QLatin1String(".qmlproject") : QLatin1String(".pro");
|
||||||
|
const QString relativeProPath = slash + dirName + slash + fn + slash + fn + extension;
|
||||||
|
|
||||||
QString fileName = examplePath + relativeProPath;
|
QString fileName = examplePath + relativeProPath;
|
||||||
if (!QFile::exists(fileName))
|
if (!QFile::exists(fileName))
|
||||||
fileName = sourcePath + QLatin1String("/examples") + relativeProPath;
|
fileName = sourcePath + QLatin1String("/examples") + relativeProPath;
|
||||||
|
|
||||||
QString dirName1 = dirName;
|
QString dirName1 = dirName;
|
||||||
dirName1.replace(slash, QLatin1Char('-'));
|
dirName1.replace(slash, QLatin1Char('-'));
|
||||||
QString helpPath = QLatin1String("qthelp://com.trolltech.qt/qdoc/") +
|
QString helpPath = QLatin1String("qthelp://com.trolltech.qt/qdoc/") +
|
||||||
dirName1 +
|
dirName1 +
|
||||||
QLatin1Char('-') + fn + QLatin1String(".html");
|
QLatin1Char('-') + fn + QLatin1String(".html");
|
||||||
|
|
||||||
|
QAction *exampleAction;
|
||||||
|
if (isQml)
|
||||||
|
exampleAction = qmlMenu->addAction(name);
|
||||||
|
else
|
||||||
|
exampleAction = subMenu->addAction(name);
|
||||||
|
|
||||||
QAction *exampleAction = subMenu->addAction(name);
|
|
||||||
connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample()));
|
connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample()));
|
||||||
|
|
||||||
exampleAction->setProperty(ExamplePathPropertyName, fileName);
|
exampleAction->setProperty(ExamplePathPropertyName, fileName);
|
||||||
exampleAction->setProperty(HelpPathPropertyName, helpPath);
|
exampleAction->setProperty(HelpPathPropertyName, helpPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
if (reader.name() == QLatin1String("category"))
|
if (reader.name() == QLatin1String("category")) {
|
||||||
|
if (subMenu->actions().isEmpty())
|
||||||
|
delete subMenu;
|
||||||
|
else
|
||||||
|
cppMenu->addMenu(subMenu);
|
||||||
|
|
||||||
inExamples = false;
|
inExamples = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GettingStartedWelcomePageWidget::updateQmlExamples(const QString &examplePath,
|
|
||||||
const QString &sourcePath)
|
|
||||||
{
|
|
||||||
ui->qmlExamplesButton->setText(tr("Choose an Example..."));
|
|
||||||
|
|
||||||
QStringList roots;
|
|
||||||
roots << (examplePath + QLatin1String("/declarative"))
|
|
||||||
<< (sourcePath + QLatin1String("/examples/declarative"));
|
|
||||||
QMap<QString, QString> exampleProjects;
|
|
||||||
|
|
||||||
foreach (const QString &root, roots) {
|
|
||||||
QList<QFileInfo> examples = QDir(root).entryInfoList(QStringList(), QDir::AllDirs|QDir::NoDotAndDotDot, QDir::Name);
|
|
||||||
foreach(const QFileInfo &example, examples) {
|
|
||||||
const QString fileName = example.fileName();
|
|
||||||
if (exampleProjects.contains(fileName))
|
|
||||||
continue;
|
|
||||||
const QString exampleProject = example.absoluteFilePath()
|
|
||||||
+ QLatin1Char('/') + fileName
|
|
||||||
+ QLatin1String(".qmlproject");
|
|
||||||
if (!QFile::exists(exampleProject))
|
|
||||||
continue;
|
|
||||||
exampleProjects.insert(fileName, exampleProject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exampleProjects.isEmpty()) {
|
|
||||||
QMenu *menu = new QMenu(ui->qmlExamplesButton);
|
|
||||||
ui->qmlExamplesButton->setMenu(menu);
|
|
||||||
|
|
||||||
QMapIterator<QString, QString> it(exampleProjects);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
QAction *exampleAction = menu->addAction(it.key());
|
|
||||||
connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample()));
|
|
||||||
exampleAction->setProperty(ExamplePathPropertyName, it.value());
|
|
||||||
// FIXME once we have help for QML examples
|
|
||||||
// exampleAction->setProperty(HelpPathPropertyName, helpPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->qmlExamplesButton->setEnabled(!exampleProjects.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
|
|
||||||
const QString &demosPath,
|
|
||||||
const QString &sourcePath)
|
|
||||||
{
|
|
||||||
QString demoxml = demosPath + "/qtdemo/xml/examples.xml";
|
|
||||||
if (!QFile::exists(demoxml)) {
|
|
||||||
demoxml = sourcePath + "/demos/qtdemo/xml/examples.xml";
|
|
||||||
if (!QFile::exists(demoxml))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
updateCppExamples(examplePath, sourcePath, demoxml);
|
|
||||||
updateQmlExamples(examplePath, sourcePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void copyRecursive(const QDir& from, const QDir& to, const QString& dir)
|
void copyRecursive(const QDir& from, const QDir& to, const QString& dir)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ private slots:
|
|||||||
void slotNextFeature();
|
void slotNextFeature();
|
||||||
void slotPrevFeature();
|
void slotPrevFeature();
|
||||||
void slotCreateNewProject();
|
void slotCreateNewProject();
|
||||||
void slotSetPrivateQmlExamples();
|
|
||||||
void addToFeatures(const RssItem&);
|
void addToFeatures(const RssItem&);
|
||||||
void showFeature(int feature = -1);
|
void showFeature(int feature = -1);
|
||||||
|
|
||||||
@@ -103,11 +102,6 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList tipsOfTheDay();
|
QStringList tipsOfTheDay();
|
||||||
void updateCppExamples(const QString &examplePath,
|
|
||||||
const QString &sourcePath,
|
|
||||||
const QString &demoXml);
|
|
||||||
void updateQmlExamples(const QString &examplePath,
|
|
||||||
const QString &sourcePath);
|
|
||||||
Ui::GettingStartedWelcomePageWidget *ui;
|
Ui::GettingStartedWelcomePageWidget *ui;
|
||||||
int m_currentTip;
|
int m_currentTip;
|
||||||
int m_currentFeature;
|
int m_currentFeature;
|
||||||
|
|||||||
Reference in New Issue
Block a user