forked from qt-creator/qt-creator
JsonWizard: Replace Python class wizard with a JsonWizard
* Remove Qt4 support. * Remove some UI options that did not do anything in the original wizard Change-Id: I9647cbc6cd0958a02df5b2fe480b9c8069249521 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
43
share/qtcreator/templates/wizards/classes/python/file.py
Normal file
43
share/qtcreator/templates/wizards/classes/python/file.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
@if '%{Imports}'
|
||||
try:
|
||||
@if '%{ImportQtCore}'
|
||||
from PySide import QtCore
|
||||
@endif
|
||||
@if '%{ImportQtWidgets}'
|
||||
from PySide import QtWidgets
|
||||
@endif
|
||||
@if '%{ImportQtQuick}'
|
||||
from PySide import QtQuick
|
||||
@endif
|
||||
except:
|
||||
@if '%{ImportQtCore}'
|
||||
from PyQt5.QtCore import pyqtSlot as Slot
|
||||
from PyQt5 import QtCore
|
||||
@endif
|
||||
@if '%{ImportQtWidgets}'
|
||||
from PyQt5 import QtWidgets
|
||||
@endif
|
||||
@if '%{ImportQtQuick}'
|
||||
from PyQt5 import QtQuick
|
||||
@endif
|
||||
|
||||
|
||||
@endif
|
||||
@if '%{Base}'
|
||||
class %{Class}(%{Base}):
|
||||
@else
|
||||
class %{Class}:
|
||||
@endif
|
||||
def __init__(self):
|
||||
@if '%{Base}' === 'QWidget'
|
||||
QtWidgets.QWidget.__init__(self)
|
||||
@endif
|
||||
@if '%{Base}' === 'QMainWindow'
|
||||
QtWidgets.QMainWindow.__init__(self)
|
||||
@if '%{Base}' === 'QQuickItem'
|
||||
QtQuick.QQuickItem.__init__(self)
|
||||
@endif
|
||||
pass
|
||||
|
||||
139
share/qtcreator/templates/wizards/classes/python/wizard.json
Normal file
139
share/qtcreator/templates/wizards/classes/python/wizard.json
Normal file
@@ -0,0 +1,139 @@
|
||||
{
|
||||
"version": 1,
|
||||
"kind": "class",
|
||||
"id": "P.PyClass",
|
||||
"category": "U.Python",
|
||||
"trDescription": "Creates new Python class file.",
|
||||
"trDisplayName": "Python Class",
|
||||
"trDisplayCategory": "Python",
|
||||
"icon": "../../global/genericfilewizard.png",
|
||||
"featuresRequired": [ "Plugin.PythonEditor" ],
|
||||
|
||||
"options":
|
||||
[
|
||||
{ "key": "Base", "value":"%{JS: ( '%{BaseCB}' === '' ) ? '%{BaseEdit}' : '%{BaseCB}'}" },
|
||||
{ "key": "Imports", "value": "%{ImportQtCore}%{ImportQtWidgets}%{ImportQtDeclarative}"}
|
||||
],
|
||||
|
||||
"pages":
|
||||
[
|
||||
{
|
||||
"trDisplayName": "Define Class",
|
||||
"trShortTitle": "Details",
|
||||
"typeId": "Fields",
|
||||
"data" :
|
||||
[
|
||||
{
|
||||
"name": "Class",
|
||||
"trDisplayName": "Class name:",
|
||||
"mandatory": true,
|
||||
"type": "LineEdit",
|
||||
"data": { "validator": "^(?:[^\\d\\W]\\w*|)$" }
|
||||
},
|
||||
{
|
||||
"name": "BaseCB",
|
||||
"trDisplayName": "Base class:",
|
||||
"type": "ComboBox",
|
||||
"data":
|
||||
{
|
||||
"items": [ { "trKey": "<Custom>", "value": "" },
|
||||
"QObject", "QWidget", "QMainWindow", "QDeclarativeItem" ]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BaseEdit",
|
||||
"type": "LineEdit",
|
||||
"enabled": "%{JS: ( '%{BaseCB}' === '' ) ? 'yes' : ''}",
|
||||
"mandatory": false,
|
||||
"data": { "trText": "%{BaseCB}" }
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
"name": "Sp1",
|
||||
"type": "Spacer",
|
||||
"data": { "size": 6 }
|
||||
},
|
||||
{
|
||||
"name": "ImportQtCore",
|
||||
"trDisplayName": "Import QtCore",
|
||||
"type": "CheckBox",
|
||||
"data":
|
||||
{
|
||||
"checkedValue": "QtCore",
|
||||
"uncheckedValue": "",
|
||||
"checked": "%{JS: ('%{Base}' !== '' ) ? 'yes' : ''}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ImportQWidget",
|
||||
"trDisplayName": "Import QtWidgets",
|
||||
"type": "CheckBox",
|
||||
"data":
|
||||
{
|
||||
"checkedValue": "QtWidgets",
|
||||
"uncheckedValue": "",
|
||||
"checked": "%{JS: ('%{Base}' === 'QWidget') ? 'yes' : ''}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ImportQtQuick",
|
||||
"trDisplayName": "Import QtQuick",
|
||||
"type": "CheckBox",
|
||||
"data":
|
||||
{
|
||||
"checkedValue": "QtQuick",
|
||||
"uncheckedValue": "",
|
||||
"checked": "%{JS: ('%{Base}' === 'QQuickItem') ? 'yes' : ''}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Sp2",
|
||||
"type": "Spacer",
|
||||
"data": { "size": 12 }
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
"name": "FileName",
|
||||
"type": "LineEdit",
|
||||
"trDisplayName": "Source file:",
|
||||
"mandatory": true,
|
||||
"data": { "trText": "%{JS: Util.fileName('%{Class}', '%{JS: Util.preferredSuffix('text/x-python')}')}" }
|
||||
},
|
||||
{
|
||||
"name": "TargetPath",
|
||||
"type": "PathChooser",
|
||||
"trDisplayName": "Path:",
|
||||
"mandatory": true,
|
||||
"data":
|
||||
{
|
||||
"kind": "existingDirectory",
|
||||
"basePath": "%{InitialPath}",
|
||||
"path": "%{InitialPath}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"trDisplayName": "Project Management",
|
||||
"shortTitle": "Summary",
|
||||
"typeId": "Summary"
|
||||
}
|
||||
],
|
||||
|
||||
"generators":
|
||||
[
|
||||
{
|
||||
"typeId": "File",
|
||||
"data":
|
||||
{
|
||||
"source": "file.py",
|
||||
"target": "%{FileName}",
|
||||
"openInEditor": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -10,10 +10,6 @@ HEADERS += \
|
||||
pythoneditorplugin.h \
|
||||
pythoneditor.h \
|
||||
pythoneditorconstants.h \
|
||||
wizard/pythonclasswizard.h \
|
||||
wizard/pythonclassnamepage.h \
|
||||
wizard/pythonclasswizarddialog.h \
|
||||
wizard/pythonsourcegenerator.h \
|
||||
tools/pythonhighlighter.h \
|
||||
tools/pythonindenter.h \
|
||||
tools/lexical/pythonformattoken.h \
|
||||
@@ -23,10 +19,6 @@ HEADERS += \
|
||||
SOURCES += \
|
||||
pythoneditorplugin.cpp \
|
||||
pythoneditor.cpp \
|
||||
wizard/pythonclasswizarddialog.cpp \
|
||||
wizard/pythonclasswizard.cpp \
|
||||
wizard/pythonclassnamepage.cpp \
|
||||
wizard/pythonsourcegenerator.cpp \
|
||||
tools/pythonhighlighter.cpp \
|
||||
tools/pythonindenter.cpp \
|
||||
tools/lexical/pythonscanner.cpp
|
||||
|
||||
@@ -34,16 +34,4 @@ QtcPlugin {
|
||||
"pythonindenter.cpp", "pythonindenter.h"
|
||||
]
|
||||
}
|
||||
|
||||
Group {
|
||||
name: "Wizard"
|
||||
prefix: "wizard/"
|
||||
files: [
|
||||
"pythonclassnamepage.cpp", "pythonclassnamepage.h",
|
||||
"pythonclasswizard.h", "pythonclasswizard.cpp",
|
||||
"pythonclasswizarddialog.h", "pythonclasswizarddialog.cpp",
|
||||
"pythonsourcegenerator.h", "pythonsourcegenerator.cpp"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,25 +40,6 @@ const char C_PYTHONEDITOR_ID[] = "PythonEditor.PythonEditor";
|
||||
const char C_EDITOR_DISPLAY_NAME[] =
|
||||
QT_TRANSLATE_NOOP("OpenWith::Editors", "Python Editor");
|
||||
|
||||
/*******************************************************************************
|
||||
* File creation wizard
|
||||
******************************************************************************/
|
||||
const char C_PY_WIZARD_CATEGORY[] = "U.Python";
|
||||
const char C_PY_EXTENSION[] = ".py";
|
||||
const char C_PY_DISPLAY_CATEGORY[] = "Python";
|
||||
|
||||
// class
|
||||
const char C_PY_CLASS_WIZARD_ID[] = "P.PyClass";
|
||||
const char EN_PY_CLASS_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("PythonEditor::ClassWizard", "Python class");
|
||||
const char EN_PY_CLASS_DESCRIPTION[] =
|
||||
QT_TRANSLATE_NOOP("PythonEditor::ClassWizard", "Creates new Python class");
|
||||
|
||||
// For future: boost binding
|
||||
const char C_PY_CPPMODULE_WIZARD_ID[] = "F.PyCppModule";
|
||||
const char EN_PY_CPPMODULE_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("PythonEditor::ClassWizard", "C++ module for Python");
|
||||
const char EN_PY_CPPMODULE_DESCRIPTION[] =
|
||||
QT_TRANSLATE_NOOP("PythonEditor::ClassWizard", "Creates C++/Boost file with bindings for Python");
|
||||
|
||||
/*******************************************************************************
|
||||
* MIME type
|
||||
******************************************************************************/
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "pythoneditorplugin.h"
|
||||
#include "pythoneditor.h"
|
||||
#include "pythoneditorconstants.h"
|
||||
#include "wizard/pythonclasswizard.h"
|
||||
#include "tools/pythonhighlighter.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -222,9 +221,6 @@ bool PythonEditorPlugin::initialize(const QStringList &arguments, QString *error
|
||||
if (!icon.isNull())
|
||||
Core::FileIconProvider::registerIconOverlayForMimeType(icon, C_PY_MIMETYPE);
|
||||
|
||||
// Add Python files and classes creation dialogs
|
||||
addAutoReleasedObject(new ClassWizard);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "pythonclassnamepage.h"
|
||||
#include "../pythoneditorconstants.h"
|
||||
|
||||
#include <utils/wizard.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <utils/newclasswidget.h>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
ClassNamePage::ClassNamePage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
, m_isValid(false)
|
||||
{
|
||||
setTitle(tr("Enter Class Name"));
|
||||
setSubTitle(tr("The source file name will be derived from the class name"));
|
||||
|
||||
m_newClassWidget.reset(new Utils::NewClassWidget);
|
||||
// Order, set extensions first before suggested name is derived
|
||||
m_newClassWidget->setClassTypeComboVisible(true);
|
||||
m_newClassWidget->setBaseClassChoices(QStringList()
|
||||
<< QString()
|
||||
<< QLatin1String("QObject")
|
||||
<< QLatin1String("QWidget")
|
||||
<< QLatin1String("QMainWindow")
|
||||
<< QLatin1String("QDeclarativeItem"));
|
||||
|
||||
m_newClassWidget->setBaseClassEditable(true);
|
||||
m_newClassWidget->setFormInputVisible(false);
|
||||
m_newClassWidget->setHeaderInputVisible(false);
|
||||
m_newClassWidget->setNamespacesEnabled(true);
|
||||
m_newClassWidget->setBaseClassInputVisible(true);
|
||||
m_newClassWidget->setNamesDelimiter(QLatin1String("."));
|
||||
m_newClassWidget->setAllowDirectories(true);
|
||||
|
||||
connect(m_newClassWidget.data(), SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
|
||||
|
||||
QVBoxLayout *pageLayout = new QVBoxLayout(this);
|
||||
pageLayout->addWidget(m_newClassWidget.data());
|
||||
QSpacerItem *vSpacer = new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::Expanding);
|
||||
pageLayout->addItem(vSpacer);
|
||||
|
||||
initParameters();
|
||||
|
||||
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Details"));
|
||||
}
|
||||
|
||||
ClassNamePage::~ClassNamePage()
|
||||
{
|
||||
}
|
||||
|
||||
void ClassNamePage::initParameters()
|
||||
{
|
||||
m_newClassWidget->setSourceExtension(QLatin1String(Constants::C_PY_EXTENSION));
|
||||
}
|
||||
|
||||
void ClassNamePage::slotValidChanged()
|
||||
{
|
||||
const bool validNow = m_newClassWidget->isValid();
|
||||
if (m_isValid != validNow) {
|
||||
m_isValid = validNow;
|
||||
emit completeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
@@ -1,66 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PYTHONEDITOR_CLASSNAMEPAGE_H
|
||||
#define PYTHONEDITOR_CLASSNAMEPAGE_H
|
||||
|
||||
#include <QWizardPage>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Utils { class NewClassWidget; }
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
class ClassNamePage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClassNamePage(QWidget *parent = 0);
|
||||
virtual ~ClassNamePage();
|
||||
|
||||
bool isComplete() const { return m_isValid; }
|
||||
Utils::NewClassWidget *newClassWidget() const { return m_newClassWidget.data(); }
|
||||
|
||||
private slots:
|
||||
void slotValidChanged();
|
||||
|
||||
private:
|
||||
void initParameters();
|
||||
|
||||
QScopedPointer<Utils::NewClassWidget> m_newClassWidget;
|
||||
bool m_isValid;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
|
||||
#endif // PYTHONEDITOR_CLASSNAMEPAGE_H
|
||||
@@ -1,116 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "pythonclasswizard.h"
|
||||
#include "pythonclasswizarddialog.h"
|
||||
#include "pythonclassnamepage.h"
|
||||
#include "pythonsourcegenerator.h"
|
||||
#include "../pythoneditorconstants.h"
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
ClassWizard::ClassWizard()
|
||||
{
|
||||
setWizardKind(Core::IWizardFactory::FileWizard);
|
||||
setId(QLatin1String(Constants::C_PY_CLASS_WIZARD_ID));
|
||||
setCategory(QLatin1String(Constants::C_PY_WIZARD_CATEGORY));
|
||||
setDisplayCategory(QLatin1String(Constants::C_PY_DISPLAY_CATEGORY));
|
||||
setDisplayName(ClassWizard::tr(Constants::EN_PY_CLASS_DISPLAY_NAME));
|
||||
setDescription(ClassWizard::tr(Constants::EN_PY_CLASS_DESCRIPTION));
|
||||
}
|
||||
|
||||
Core::BaseFileWizard *ClassWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
||||
{
|
||||
ClassWizardDialog *wizard = new ClassWizardDialog(parent);
|
||||
foreach (QWizardPage *p, parameters.extensionPages())
|
||||
wizard->addPage(p);
|
||||
wizard->setPath(parameters.defaultPath());
|
||||
wizard->setExtraValues(parameters.extraValues());
|
||||
return wizard;
|
||||
}
|
||||
|
||||
Core::GeneratedFiles ClassWizard::generateFiles(const QWizard *w,
|
||||
QString *errorMessage) const
|
||||
{
|
||||
Q_UNUSED(errorMessage);
|
||||
|
||||
const ClassWizardDialog *wizard = qobject_cast<const ClassWizardDialog *>(w);
|
||||
const ClassWizardParameters params = wizard->parameters();
|
||||
|
||||
const QString fileName = Core::BaseFileWizardFactory::buildFileName(
|
||||
params.path, params.fileName, QLatin1String(Constants::C_PY_EXTENSION));
|
||||
Core::GeneratedFile sourceFile(fileName);
|
||||
|
||||
SourceGenerator generator;
|
||||
generator.setPythonQtBinding(SourceGenerator::PySide);
|
||||
Kit *kit = kitForWizard(wizard);
|
||||
if (kit) {
|
||||
QtSupport::BaseQtVersion *baseVersion = QtSupport::QtKitInformation::qtVersion(kit);
|
||||
if (baseVersion && baseVersion->qtVersion().majorVersion == 5)
|
||||
generator.setPythonQtVersion(SourceGenerator::Qt5);
|
||||
else
|
||||
generator.setPythonQtVersion(SourceGenerator::Qt4);
|
||||
}
|
||||
|
||||
QString sourceContent = generator.generateClass(
|
||||
params.className, params.baseClass, params.classType
|
||||
);
|
||||
|
||||
sourceFile.setContents(sourceContent);
|
||||
sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
||||
return Core::GeneratedFiles() << sourceFile;
|
||||
}
|
||||
|
||||
Kit *ClassWizard::kitForWizard(const ClassWizardDialog *wizard) const
|
||||
{
|
||||
const QString key = QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE);
|
||||
const QString nodePath = wizard->extraValues().value(key).toString();
|
||||
|
||||
// projectForFile doesn't find project if project file path passed
|
||||
Node *node = SessionManager::nodeForFile(nodePath);
|
||||
Project *proj = SessionManager::projectForNode(node);
|
||||
if (proj && proj->activeTarget())
|
||||
return proj->activeTarget()->kit();
|
||||
|
||||
return KitManager::defaultKit();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PYTHONEDITOR_CLASSWIZARD_H
|
||||
#define PYTHONEDITOR_CLASSWIZARD_H
|
||||
|
||||
#include <coreplugin/basefilewizardfactory.h>
|
||||
#include <utils/wizard.h>
|
||||
|
||||
namespace Utils { class NewClassWidget; }
|
||||
namespace ProjectExplorer { class Kit; }
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
class ClassWizardDialog;
|
||||
|
||||
class ClassWizard : public Core::BaseFileWizardFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClassWizard();
|
||||
|
||||
private:
|
||||
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const;
|
||||
|
||||
Core::GeneratedFiles generateFiles(const QWizard *w,
|
||||
QString *errorMessage) const;
|
||||
|
||||
ProjectExplorer::Kit *kitForWizard(const ClassWizardDialog *wizard) const;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
|
||||
#endif // PYTHONEDITOR_CLASSWIZARD_H
|
||||
@@ -1,80 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "pythonclasswizarddialog.h"
|
||||
#include "pythonclassnamepage.h"
|
||||
|
||||
#include <utils/newclasswidget.h>
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
ClassWizardDialog::ClassWizardDialog(QWidget *parent) :
|
||||
Core::BaseFileWizard(parent),
|
||||
m_classNamePage(new ClassNamePage(this))
|
||||
{
|
||||
setWindowTitle(tr("Python Class Wizard"));
|
||||
addPage(m_classNamePage.data());
|
||||
}
|
||||
|
||||
ClassWizardDialog::~ClassWizardDialog()
|
||||
{
|
||||
}
|
||||
|
||||
ClassWizardParameters ClassWizardDialog::parameters() const
|
||||
{
|
||||
ClassWizardParameters p;
|
||||
const Utils::NewClassWidget *ncw = m_classNamePage->newClassWidget();
|
||||
p.className = ncw->className();
|
||||
p.fileName = ncw->sourceFileName();
|
||||
p.baseClass = ncw->baseClassName();
|
||||
p.path = ncw->path();
|
||||
p.classType = ncw->classType();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void ClassWizardDialog::setExtraValues(const QVariantMap &extraValues)
|
||||
{
|
||||
m_extraValues = extraValues;
|
||||
}
|
||||
|
||||
const QVariantMap &ClassWizardDialog::extraValues() const
|
||||
{
|
||||
return m_extraValues;
|
||||
}
|
||||
|
||||
void ClassWizardDialog::setPath(const QString &path)
|
||||
{
|
||||
m_classNamePage->newClassWidget()->setPath(path);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
@@ -1,76 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PYTHONEDITOR_CLASSWIZARDDIALOG_H
|
||||
#define PYTHONEDITOR_CLASSWIZARDDIALOG_H
|
||||
|
||||
#include <coreplugin/basefilewizard.h>
|
||||
|
||||
#include <utils/newclasswidget.h>
|
||||
#include <QScopedPointer>
|
||||
#include <QVariantMap>
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
class ClassNamePage;
|
||||
|
||||
class ClassWizardParameters
|
||||
{
|
||||
public:
|
||||
QString className;
|
||||
QString fileName;
|
||||
QString path;
|
||||
QString baseClass;
|
||||
Utils::NewClassWidget::ClassType classType;
|
||||
};
|
||||
|
||||
class ClassWizardDialog : public Core::BaseFileWizard
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClassWizardDialog(QWidget *parent = 0);
|
||||
virtual ~ClassWizardDialog();
|
||||
|
||||
void setPath(const QString &path);
|
||||
ClassWizardParameters parameters() const;
|
||||
|
||||
void setExtraValues(const QVariantMap &extraValues);
|
||||
const QVariantMap &extraValues() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<ClassNamePage> m_classNamePage;
|
||||
QVariantMap m_extraValues;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
|
||||
#endif // PYTHONEDITOR_CLASSWIZARDDIALOG_H
|
||||
@@ -1,213 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "pythonsourcegenerator.h"
|
||||
#include <QSet>
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
static const char BASH_RUN_HEADER[] = "#!/usr/bin/env python\n";
|
||||
static const char ENCODING_HEADER[] = "# -*- coding: utf-8 -*-\n";
|
||||
|
||||
SourceGenerator::SourceGenerator()
|
||||
: m_pythonQtBinding(PySide)
|
||||
, m_pythonQtVersion(Qt4)
|
||||
{
|
||||
}
|
||||
|
||||
SourceGenerator::~SourceGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
void SourceGenerator::setPythonQtBinding(QtBinding binding)
|
||||
{
|
||||
m_pythonQtBinding = binding;
|
||||
}
|
||||
|
||||
void SourceGenerator::setPythonQtVersion(SourceGenerator::QtVersion version)
|
||||
{
|
||||
m_pythonQtVersion = version;
|
||||
}
|
||||
|
||||
QString SourceGenerator::generateClass(const QString &className,
|
||||
const QString &baseClass,
|
||||
Utils::NewClassWidget::ClassType classType) const
|
||||
{
|
||||
QSet<QString> modules;
|
||||
bool hasUserBaseClass = !baseClass.isEmpty();
|
||||
// heuristic
|
||||
bool wasInheritedFromQt = hasUserBaseClass && (baseClass.at(0) == QLatin1Char('Q'));
|
||||
|
||||
QString actualBase = baseClass;
|
||||
|
||||
switch (classType) {
|
||||
case Utils::NewClassWidget::NoClassType:
|
||||
break;
|
||||
case Utils::NewClassWidget::SharedDataClass:
|
||||
case Utils::NewClassWidget::ClassInheritsQQuickItem:
|
||||
break;
|
||||
case Utils::NewClassWidget::ClassInheritsQObject:
|
||||
wasInheritedFromQt = true;
|
||||
modules.insert(QLatin1String("QtCore"));
|
||||
if (!hasUserBaseClass)
|
||||
actualBase = QLatin1String("QtCore.QObject");
|
||||
break;
|
||||
|
||||
case Utils::NewClassWidget::ClassInheritsQWidget:
|
||||
wasInheritedFromQt = true;
|
||||
modules.insert(QLatin1String("QtCore"));
|
||||
modules.insert(moduleForQWidget());
|
||||
if (!hasUserBaseClass)
|
||||
actualBase = moduleForQWidget() + QLatin1String(".QWidget");
|
||||
break;
|
||||
|
||||
case Utils::NewClassWidget::ClassInheritsQDeclarativeItem:
|
||||
wasInheritedFromQt = true;
|
||||
modules.insert(QLatin1String("QtCore"));
|
||||
modules.insert(QLatin1String("QtDeclarative"));
|
||||
if (!hasUserBaseClass)
|
||||
actualBase = QLatin1String("QtDeclarative.QDeclarativeItem");
|
||||
break;
|
||||
}
|
||||
|
||||
QString nonQtModule; // empty
|
||||
if (hasUserBaseClass) {
|
||||
int dotIndex = baseClass.lastIndexOf(QLatin1Char('.'));
|
||||
if (dotIndex != -1) {
|
||||
if (wasInheritedFromQt)
|
||||
modules.insert(baseClass.left(dotIndex));
|
||||
else
|
||||
nonQtModule = baseClass.left(dotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
QString ret;
|
||||
ret.reserve(1024);
|
||||
ret += QLatin1String(ENCODING_HEADER);
|
||||
ret += QLatin1Char('\n');
|
||||
|
||||
if (!modules.isEmpty()) {
|
||||
ret += qtModulesImport(modules);
|
||||
ret += QLatin1Char('\n');
|
||||
}
|
||||
|
||||
if (!nonQtModule.isEmpty())
|
||||
ret += QString::fromLatin1("import %1\n\n").arg(nonQtModule);
|
||||
|
||||
if (actualBase.isEmpty())
|
||||
ret += QString::fromLatin1("class %1:\n").arg(className);
|
||||
else
|
||||
ret += QString::fromLatin1("class %1(%2):\n").arg(className).arg(actualBase);
|
||||
|
||||
ret += QLatin1String(" def __init__(self):\n");
|
||||
if (wasInheritedFromQt)
|
||||
ret += QString::fromLatin1(" %1.__init__(self)\n").arg(actualBase);
|
||||
ret += QLatin1String(" pass\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates main file of PyQt/PySide application
|
||||
*
|
||||
* Class MainWindow should be defined in 'mainwindow' module.
|
||||
* @param windowTitle Title for created window instance
|
||||
*/
|
||||
QString SourceGenerator::generateQtMain(const QString &windowTitle) const
|
||||
{
|
||||
QSet<QString> qtModules;
|
||||
qtModules.insert(QLatin1String("QtCore"));
|
||||
qtModules.insert(moduleForQWidget());
|
||||
|
||||
QString ret;
|
||||
ret.reserve(1024);
|
||||
ret += QLatin1String(BASH_RUN_HEADER);
|
||||
ret += QLatin1String(ENCODING_HEADER);
|
||||
ret += QLatin1Char('\n');
|
||||
ret += QLatin1String("import sys\n");
|
||||
ret += qtModulesImport(qtModules);
|
||||
ret += QLatin1String("from mainwindow import MainWindow\n");
|
||||
ret += QLatin1Char('\n');
|
||||
|
||||
ret += QString::fromLatin1(
|
||||
"if __name__ == \'__main__\':\n"
|
||||
" app = %1.QApplication(sys.argv)\n"
|
||||
" win = MainWindow()\n"
|
||||
" win.setWindowTitle(u\'%2\')\n"
|
||||
" win.show()\n"
|
||||
" app.exec_()\n"
|
||||
).arg(moduleForQWidget()).arg(windowTitle);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString SourceGenerator::qtModulesImport(const QSet<QString> &modules) const
|
||||
{
|
||||
QString slotsImport;
|
||||
if (modules.contains(QLatin1String("QtCore")))
|
||||
slotsImport = QLatin1String(" from PyQt4.QtCore import pyqtSlot as Slot\n");
|
||||
|
||||
QLatin1String defaultBinding("PySide");
|
||||
QLatin1String fallbackBinding("PyQt4");
|
||||
if (m_pythonQtBinding == PyQt)
|
||||
qSwap(defaultBinding, fallbackBinding);
|
||||
|
||||
QString ret;
|
||||
ret.reserve(256);
|
||||
ret += QLatin1String("try:\n");
|
||||
if (m_pythonQtBinding == PyQt)
|
||||
ret += slotsImport;
|
||||
foreach (const QString &name, modules)
|
||||
ret += QString::fromLatin1(" from %1 import %2\n")
|
||||
.arg(defaultBinding)
|
||||
.arg(name);
|
||||
|
||||
ret += QLatin1String("except:\n");
|
||||
if (m_pythonQtBinding != PyQt)
|
||||
ret += slotsImport;
|
||||
foreach (const QString &name, modules)
|
||||
ret += QString::fromLatin1(" from %1 import %2\n")
|
||||
.arg(fallbackBinding)
|
||||
.arg(name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString SourceGenerator::moduleForQWidget() const
|
||||
{
|
||||
if (m_pythonQtVersion == Qt4)
|
||||
return QLatin1String("QtGui");
|
||||
else
|
||||
return QLatin1String("QtWidgets");
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
@@ -1,77 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PYTHON_SOURCEGENERATOR_H
|
||||
#define PYTHON_SOURCEGENERATOR_H
|
||||
|
||||
#include <utils/newclasswidget.h>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
class SourceGenerator
|
||||
{
|
||||
public:
|
||||
enum QtBinding {
|
||||
PySide,
|
||||
PyQt
|
||||
};
|
||||
|
||||
enum QtVersion {
|
||||
Qt4,
|
||||
Qt5
|
||||
};
|
||||
|
||||
SourceGenerator();
|
||||
~SourceGenerator();
|
||||
|
||||
void setPythonQtBinding(QtBinding binding);
|
||||
void setPythonQtVersion(QtVersion version);
|
||||
|
||||
QString generateClass(const QString &className,
|
||||
const QString &baseClass,
|
||||
Utils::NewClassWidget::ClassType classType) const;
|
||||
|
||||
QString generateQtMain(const QString &windowTitle) const;
|
||||
|
||||
private:
|
||||
QString qtModulesImport(const QSet<QString> &modules) const;
|
||||
QString moduleForQWidget() const;
|
||||
|
||||
QtBinding m_pythonQtBinding;
|
||||
QtVersion m_pythonQtVersion;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace PythonEditor
|
||||
|
||||
#endif // PYTHON_SOURCEGENERATOR_H
|
||||
Reference in New Issue
Block a user