CMake generator: Make only some files selected by default

Task-number: QDS-5561
Change-Id: I1a76385f55681ba60bdb43eafdede6697893598f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tapani Mattila
2021-11-22 13:41:20 +02:00
parent 590e19acb7
commit f8f7f47ec3
9 changed files with 277 additions and 116 deletions

View File

@@ -30,6 +30,8 @@ add_qtc_plugin(QmlDesigner
cmakegeneratordialog.h cmakegeneratordialog.cpp
generateresource.cpp generateresource.h
generatecmakelists.cpp generatecmakelists.h
generatecmakelistsconstants.h
checkablefilelistmodel.cpp checkablefilelistmodel.h
openuiqmlfiledialog.cpp openuiqmlfiledialog.h openuiqmlfiledialog.ui
qmldesignerconstants.h
qmldesignericons.h

View File

@@ -0,0 +1,111 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Tooling
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "checkablefilelistmodel.h"
using namespace Utils;
namespace QmlDesigner {
CheckableFileListModel::CheckableFileListModel(const FilePath &rootDir, const FilePaths &files, bool checkedByDefault, QObject *parent)
:QStandardItemModel(parent),
rootDir(rootDir)
{
for (const FilePath &file: files) {
appendRow(new CheckableStandardItem(file.toString(), checkedByDefault));
}
}
QList<CheckableStandardItem*> CheckableFileListModel::checkedItems() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QList<QStandardItem*> allItems = findItems("*", Qt::MatchWildcard);
#else
QList<QStandardItem*> allItems = findItems(".*", Qt::MatchRegularExpression);
#endif
QList<CheckableStandardItem*> checkedItems;
for (QStandardItem *standardItem : allItems) {
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(standardItem);
if (item->isChecked())
checkedItems.append(item);
}
return checkedItems;
}
QVariant CheckableFileListModel::data(const QModelIndex &index, int role) const
{
if (index.isValid()) {
if (role == Qt::CheckStateRole) {
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(QStandardItemModel::item(index.row()));
return item->isChecked() ? Qt::Checked : Qt::Unchecked;
}
else if (role == Qt::DisplayRole) {
QVariant data = QStandardItemModel::data(index, role);
FilePath fullPath = FilePath::fromString(data.toString());
FilePath relativePath = fullPath.relativeChildPath(rootDir);
return QVariant(relativePath.toString());
}
}
return QStandardItemModel::data(index, role);
}
bool CheckableFileListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::CheckStateRole)
{
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(QStandardItemModel::item(index.row()));
item->setChecked(value.value<bool>());
return true;
}
return QStandardItemModel::setData(index, value, role);
}
CheckableStandardItem::CheckableStandardItem(const QString &text, bool checked)
:QStandardItem(text),
checked(checked)
{
setFlags(flags() |= Qt::ItemIsUserCheckable);
}
void CheckableStandardItem::setChecked(bool checked)
{
this->checked = checked;
}
bool CheckableStandardItem::isChecked() const
{
return this->checked;
}
int CheckableStandardItem::type() const
{
return QStandardItem::UserType + 0x74d4f1;
}
} //QmlDesigner

View File

@@ -0,0 +1,65 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Tooling
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef CHECKABLEFILELISTMODEL_H
#define CHECKABLEFILELISTMODEL_H
#include <utils/fileutils.h>
#include <QStandardItemModel>
namespace QmlDesigner {
class CheckableStandardItem : public QStandardItem
{
public:
explicit CheckableStandardItem(const QString &text = QString(), bool checked = false);
bool isChecked() const;
void setChecked(bool checked);
int type() const;
private:
bool checked;
};
class CheckableFileListModel : public QStandardItemModel
{
public:
CheckableFileListModel(const Utils::FilePath &rootDir,
const Utils::FilePaths &files,
bool checkedByDefault = false,
QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QList<CheckableStandardItem*> checkedItems() const;
protected:
Utils::FilePath rootDir;
};
} //QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::CheckableStandardItem)
#endif // CHECKABLEFILELISTMODEL_H

View File

@@ -23,8 +23,8 @@
**
****************************************************************************/
#include "cmakegeneratordialog.h"
#include "generatecmakelistsconstants.h"
#include <QDialogButtonBox>
#include <QPushButton>
@@ -51,7 +51,7 @@ CmakeGeneratorDialog::CmakeGeneratorDialog(const FilePath &rootDir, const FilePa
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
model = new CheckableFileListModel(rootDir, files, this);
model = new CMakeGeneratorDialogModel(rootDir, files, this);
QListView *list = new QListView(this);
list->setModel(model);
@@ -72,82 +72,35 @@ FilePaths CmakeGeneratorDialog::getFilePaths()
return paths;
}
CheckableFileListModel::CheckableFileListModel(const FilePath &rootDir, const FilePaths &files, QObject *parent)
:QStandardItemModel(parent),
rootDir(rootDir)
CMakeGeneratorDialogModel::CMakeGeneratorDialogModel(const Utils::FilePath &rootDir, const Utils::FilePaths &files, QObject *parent)
:CheckableFileListModel(rootDir, files, parent)
{
for (const FilePath &file: files) {
appendRow(new CheckableStandardItem(file.toString(), true));
for (int i=0; i<rowCount(); i++) {
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(QStandardItemModel::item(i));
item->setChecked(CMakeGeneratorDialogModel::checkedByDefault(FilePath::fromString(item->text())));
}
}
QList<CheckableStandardItem*> CheckableFileListModel::checkedItems() const
bool CMakeGeneratorDialogModel::checkedByDefault(const FilePath &path) const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QList<QStandardItem*> allItems = findItems("*", Qt::MatchWildcard);
#else
QList<QStandardItem*> allItems = findItems(".*", Qt::MatchRegularExpression);
#endif
QList<CheckableStandardItem*> checkedItems;
for (QStandardItem *standardItem : allItems) {
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(standardItem);
if (item->isChecked())
checkedItems.append(item);
}
return checkedItems;
}
CheckableStandardItem::CheckableStandardItem(const QString &text, bool checked)
:QStandardItem(text),
checked(checked)
{
setFlags(flags() |= Qt::ItemIsUserCheckable);
}
void CheckableStandardItem::setChecked(bool checked)
{
this->checked = checked;
}
bool CheckableStandardItem::isChecked() const
{
return this->checked;
}
int CheckableStandardItem::type() const
{
return QStandardItem::UserType + 0x74d4f1;
}
QVariant CheckableFileListModel::data(const QModelIndex &index, int role) const
{
if (index.isValid()) {
if (role == Qt::CheckStateRole) {
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(QStandardItemModel::item(index.row()));
return item->isChecked() ? Qt::Checked : Qt::Unchecked;
}
else if (role == Qt::DisplayRole) {
QVariant data = QStandardItemModel::data(index, role);
QString relativePath = data.toString().remove(rootDir.toString());
return QVariant(relativePath);
}
}
return QStandardItemModel::data(index, role);
}
bool CheckableFileListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::CheckStateRole)
{
CheckableStandardItem *item = static_cast<CheckableStandardItem*>(QStandardItemModel::item(index.row()));
item->setChecked(value.value<bool>());
if (path.exists()) {
QString relativePath = path.relativeChildPath(rootDir).toString();
if (relativePath.compare(QmlDesigner::GenerateCmake::Constants::FILENAME_CMAKELISTS) == 0)
return false;
if (relativePath.endsWith(QmlDesigner::GenerateCmake::Constants::FILENAME_CMAKELISTS)
&& relativePath.length() > QString(QmlDesigner::GenerateCmake::Constants::FILENAME_CMAKELISTS).length())
return true;
if (relativePath.compare(QmlDesigner::GenerateCmake::Constants::FILENAME_MODULES) == 0)
return true;
if (relativePath.compare(
FilePath::fromString(QmlDesigner::GenerateCmake::Constants::DIRNAME_CPP)
.pathAppended(QmlDesigner::GenerateCmake::Constants::FILENAME_MAINCPP_HEADER)
.toString())
== 0)
return true;
}
return QStandardItemModel::setData(index, value, role);
return !path.exists();
}
}

View File

@@ -27,36 +27,22 @@
#ifndef CMAKEGENERATORDIALOG_H
#define CMAKEGENERATORDIALOG_H
#include "checkablefilelistmodel.h"
#include <utils/fileutils.h>
#include <QDialog>
#include <QStandardItemModel>
namespace QmlDesigner {
namespace GenerateCmake {
class CheckableStandardItem : public QStandardItem
class CMakeGeneratorDialogModel : public CheckableFileListModel
{
public:
explicit CheckableStandardItem(const QString &text = QString(), bool checked = false);
bool isChecked() const;
void setChecked(bool checked);
int type() const;
private:
bool checked;
};
class CheckableFileListModel : public QStandardItemModel
{
public:
CheckableFileListModel(const Utils::FilePath &rootDir, const Utils::FilePaths &files, QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QList<CheckableStandardItem*> checkedItems() const;
private:
Utils::FilePath rootDir;
CMakeGeneratorDialogModel(const Utils::FilePath &rootDir, const Utils::FilePaths &files, QObject *parent = nullptr);
protected:
virtual bool checkedByDefault(const Utils::FilePath &file) const;
};
class CmakeGeneratorDialog : public QDialog
@@ -72,6 +58,4 @@ private:
}
}
Q_DECLARE_METATYPE(QmlDesigner::GenerateCmake::CheckableStandardItem)
#endif // CMAKEGENERATORDIALOG_H

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "generatecmakelists.h"
#include "generatecmakelistsconstants.h"
#include "cmakegeneratordialog.h"
#include <coreplugin/actionmanager/actionmanager.h>
@@ -47,6 +48,7 @@
#include <QTextStream>
using namespace Utils;
using namespace QmlDesigner::GenerateCmake::Constants;
namespace QmlDesigner {
@@ -118,17 +120,6 @@ bool isErrorFatal(int error)
return false;
}
const char DIRNAME_CONTENT[] = "content";
const char DIRNAME_IMPORT[] = "imports";
const char DIRNAME_CPP[] = "src";
const char FILENAME_CMAKELISTS[] = "CMakeLists.txt";
const char FILENAME_APPMAINQML[] = "App.qml";
const char FILENAME_MAINQML[] = "main.qml";
const char FILENAME_MAINCPP[] = "main.cpp";
const char FILENAME_MAINCPP_HEADER[] = "import_qml_plugins.h";
const char FILENAME_MODULES[] = "qmlmodules";
int isProjectCorrectlyFormed(const FilePath &rootDir)
{
int errors = NoError;
@@ -292,8 +283,6 @@ QStringList moduleNames;
const QDir::Filters FILES_ONLY = QDir::Files;
const QDir::Filters DIRS_ONLY = QDir::Dirs|QDir::Readable|QDir::NoDotAndDotDot;
const char QMLDIRFILENAME[] = "qmldir";
const char MAIN_CMAKEFILE_TEMPLATE_PATH[] = ":/boilerplatetemplates/qmlprojectmaincmakelists.tpl";
const char QMLMODULES_FILE_TEMPLATE_PATH[] = ":/boilerplatetemplates/qmlprojectmodules.tpl";
@@ -325,7 +314,7 @@ void generateMainCmake(const FilePath &rootDir)
modulesAsPlugins.append(" " + moduleName + "plugin\n");
QString moduleFileContent = GenerateCmake::readTemplate(QMLMODULES_FILE_TEMPLATE_PATH).arg(appName).arg(modulesAsPlugins);
GenerateCmake::queueFile(rootDir.pathAppended(GenerateCmake::FILENAME_MODULES), moduleFileContent);
GenerateCmake::queueFile(rootDir.pathAppended(FILENAME_MODULES), moduleFileContent);
}
const char DO_NOT_EDIT_FILE_COMMENT[] = "### This file is automatically generated by Qt Design Studio.\n### Do not change\n\n";
@@ -353,7 +342,7 @@ const char MODULEFILE_TEMPLATE_PATH[] = ":/boilerplatetemplates/qmlprojectmodule
void generateModuleCmake(const FilePath &dir)
{
QString fileTemplate = GenerateCmake::readTemplate(MODULEFILE_TEMPLATE_PATH);
const QStringList qmldirFilesOnly(QMLDIRFILENAME);
const QStringList qmldirFilesOnly(FILENAME_QMLDIR);
QString singletonContent;
FilePaths qmldirFileList = dir.dirEntries(qmldirFilesOnly, FILES_ONLY);
@@ -467,14 +456,14 @@ QStringList getDirectoryTreeResources(const FilePath &dir)
void queueCmakeFile(const FilePath &dir, const QString &content)
{
FilePath filePath = dir.pathAppended(GenerateCmake::FILENAME_CMAKELISTS);
FilePath filePath = dir.pathAppended(FILENAME_CMAKELISTS);
GenerateCmake::queueFile(filePath, content);
}
bool isFileBlacklisted(const QString &fileName)
{
return (!fileName.compare(QMLDIRFILENAME) ||
!fileName.compare(GenerateCmake::FILENAME_CMAKELISTS));
return (!fileName.compare(FILENAME_QMLDIR) ||
!fileName.compare(FILENAME_CMAKELISTS));
}
}
@@ -494,10 +483,10 @@ const char MAIN_CPPFILE_HEADER_PLUGIN_LINE[] = "Q_IMPORT_QML_PLUGIN(%1)\n";
bool generateMainCpp(const FilePath &dir)
{
FilePath srcDir = dir.pathAppended(GenerateCmake::DIRNAME_CPP);
FilePath srcDir = dir.pathAppended(DIRNAME_CPP);
QString cppContent = GenerateCmake::readTemplate(MAIN_CPPFILE_TEMPLATE_PATH);
FilePath cppFilePath = srcDir.pathAppended(GenerateCmake::FILENAME_MAINCPP);
FilePath cppFilePath = srcDir.pathAppended(FILENAME_MAINCPP);
bool cppOk = GenerateCmake::queueFile(cppFilePath, cppContent);
QString modulesAsPlugins;
@@ -507,7 +496,7 @@ bool generateMainCpp(const FilePath &dir)
QString headerContent = GenerateCmake::readTemplate(MAIN_CPPFILE_HEADER_TEMPLATE_PATH)
.arg(modulesAsPlugins);
FilePath headerFilePath = srcDir.pathAppended(GenerateCmake::FILENAME_MAINCPP_HEADER);
FilePath headerFilePath = srcDir.pathAppended(FILENAME_MAINCPP_HEADER);
bool headerOk = GenerateCmake::queueFile(headerFilePath, headerContent);
return cppOk && headerOk;
@@ -518,7 +507,7 @@ const char MAIN_QMLFILE_TEMPLATE_PATH[] = ":/boilerplatetemplates/qmlprojectmain
bool generateMainQml(const FilePath &dir)
{
QString content = GenerateCmake::readTemplate(MAIN_QMLFILE_TEMPLATE_PATH);
FilePath filePath = dir.pathAppended(GenerateCmake::FILENAME_MAINQML);
FilePath filePath = dir.pathAppended(FILENAME_MAINQML);
return GenerateCmake::queueFile(filePath, content);
}

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Tooling
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef GENERATECMAKELISTSCONSTANTS_H
#define GENERATECMAKELISTSCONSTANTS_H
#pragma once
namespace QmlDesigner {
namespace GenerateCmake {
namespace Constants {
const char DIRNAME_CONTENT[] = "content";
const char DIRNAME_IMPORT[] = "imports";
const char DIRNAME_CPP[] = "src";
const char FILENAME_CMAKELISTS[] = "CMakeLists.txt";
const char FILENAME_APPMAINQML[] = "App.qml";
const char FILENAME_MAINQML[] = "main.qml";
const char FILENAME_MAINCPP[] = "main.cpp";
const char FILENAME_MAINCPP_HEADER[] = "import_qml_plugins.h";
const char FILENAME_MODULES[] = "qmlmodules";
const char FILENAME_QMLDIR[] = "qmldir";
} //Constants
} //GenerateCmake
} //QmlDesigner
#endif // GENERATECMAKELISTSCONSTANTS_H

View File

@@ -6,6 +6,8 @@ HEADERS += $$PWD/qmldesignerconstants.h \
$$PWD/editorproxy.h \
$$PWD/generateresource.h \
$$PWD/generatecmakelists.h \
$$PWD/generatecmakelistsconstants.h \
$$PWD/checkablefilelistmodel.h \
$$PWD/cmakegeneratordialog.h \
$$PWD/settingspage.h \
$$PWD/designmodecontext.h \
@@ -23,6 +25,7 @@ SOURCES += $$PWD/qmldesignerplugin.cpp \
$$PWD/editorproxy.cpp \
$$PWD/generateresource.cpp \
$$PWD/generatecmakelists.cpp \
$$PWD/checkablefilelistmodel.cpp \
$$PWD/cmakegeneratordialog.cpp \
$$PWD/settingspage.cpp \
$$PWD/designmodecontext.cpp \

View File

@@ -1011,6 +1011,9 @@ Project {
"generateresource.h",
"generatecmakelists.cpp",
"generatecmakelists.h",
"generatecmakelistsconstants.h",
"checkablefilelistmodel.cpp",
"checkablefilelistmodel.h",
"cmakegeneratordialog.cpp",
"cmakegeneratordialog.h",
"designersettings.cpp",