Commit 024b548e authored by Friedemann Kleint's avatar Friedemann Kleint

Added a wizard for Qt Designer custom widgets and collections.

Add the wizard. Modify basefilewizard to use be able to handle binary
data. Add some properties to path chooser (filters).

Task-number: 251982
Initial-patch-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent 3d9c65f2
......@@ -88,6 +88,7 @@ struct PathChooserPrivate
PathValidatingLineEdit *m_lineEdit;
PathChooser::Kind m_acceptingKind;
QString m_dialogTitleOverride;
QString m_dialogFilter;
QString m_initialBrowsePathOverride;
};
......@@ -171,7 +172,8 @@ void PathChooser::slotBrowse()
case PathChooser::File: // fall through
case PathChooser::Command:
newPath = QFileDialog::getOpenFileName(this,
makeDialogTitle(tr("Choose a file")), predefined);
makeDialogTitle(tr("Choose a file")), predefined,
m_d->m_dialogFilter);
break;
default:
......@@ -278,11 +280,31 @@ void PathChooser::setExpectedKind(Kind expected)
m_d->m_acceptingKind = expected;
}
PathChooser::Kind PathChooser::expectedKind() const
{
return m_d->m_acceptingKind;
}
void PathChooser::setPromptDialogTitle(const QString &title)
{
m_d->m_dialogTitleOverride = title;
}
QString PathChooser::promptDialogTitle() const
{
return m_d->m_dialogTitleOverride;
}
void PathChooser::setPromptDialogFilter(const QString &filter)
{
m_d->m_dialogFilter = filter;
}
QString PathChooser::promptDialogFilter() const
{
return m_d->m_dialogFilter;
}
void PathChooser::setInitialBrowsePathBackup(const QString &path)
{
m_d->m_initialBrowsePathOverride = path;
......
......@@ -47,7 +47,10 @@ class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
{
Q_DISABLE_COPY(PathChooser)
Q_OBJECT
Q_ENUMS(Kind)
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
public:
static const char * const browseButtonLabel;
......@@ -64,8 +67,13 @@ public:
// Default is <Directory>
void setExpectedKind(Kind expected);
Kind expectedKind() const;
void setPromptDialogTitle(const QString &title);
QString promptDialogTitle() const;
void setPromptDialogFilter(const QString &filter);
QString promptDialogFilter() const;
void setInitialBrowsePathBackup(const QString &path);
......
......@@ -58,15 +58,17 @@ namespace Core {
class GeneratedFilePrivate : public QSharedData
{
public:
GeneratedFilePrivate() {}
GeneratedFilePrivate() : binary(false) {}
explicit GeneratedFilePrivate(const QString &p);
QString path;
QString contents;
QByteArray contents;
QString editorKind;
bool binary;
};
GeneratedFilePrivate::GeneratedFilePrivate(const QString &p) :
path(p)
path(p),
binary(false)
{
}
......@@ -108,14 +110,34 @@ void GeneratedFile::setPath(const QString &p)
QString GeneratedFile::contents() const
{
return m_d->contents;
return QString::fromUtf8(m_d->contents);
}
void GeneratedFile::setContents(const QString &c)
{
m_d->contents = c.toUtf8();
}
QByteArray GeneratedFile::binaryContents() const
{
return m_d->contents;
}
void GeneratedFile::setBinaryContents(const QByteArray &c)
{
m_d->contents = c;
}
bool GeneratedFile::isBinary() const
{
return m_d->binary;
}
void GeneratedFile::setBinary(bool b)
{
m_d->binary = b;
}
QString GeneratedFile::editorKind() const
{
return m_d->editorKind;
......@@ -139,11 +161,16 @@ bool GeneratedFile::write(QString *errorMessage) const
}
// Write out
QFile file(m_d->path);
if (!file.open(QIODevice::WriteOnly|QIODevice::Text)) {
QIODevice::OpenMode flags = QIODevice::WriteOnly|QIODevice::Truncate;
if (!isBinary())
flags |= QIODevice::Text;
if (!file.open(flags)) {
*errorMessage = BaseFileWizard::tr("Unable to open %1 for writing: %2").arg(m_d->path, file.errorString());
return false;
}
if (file.write(m_d->contents.toUtf8()) == -1) {
if (file.write(m_d->contents) == -1) {
*errorMessage = BaseFileWizard::tr("Error while writing to %1: %2").arg(m_d->path, file.errorString());
return false;
}
......
......@@ -71,10 +71,17 @@ public:
QString path() const;
void setPath(const QString &p);
// Contents of the file
// Contents of the file (UTF8)
QString contents() const;
void setContents(const QString &c);
QByteArray binaryContents() const;
void setBinaryContents(const QByteArray &c);
// Defaults to false (Text file).
bool isBinary() const;
void setBinary(bool b);
// Kind of editor to open the file with
QString editorKind() const;
void setEditorKind(const QString &k);
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "classdefinition.h"
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
namespace Qt4ProjectManager {
namespace Internal {
ClassDefinition::ClassDefinition(QWidget *parent) :
QTabWidget(parent),
m_domXmlChanged(false)
{
setupUi(this);
iconPathChooser->setExpectedKind(Core::Utils::PathChooser::File);
iconPathChooser->setPromptDialogTitle(tr("Select Icon"));
iconPathChooser->setPromptDialogFilter(tr("Icon files (*.png *.ico *.jpg *.xpm *.tif *.svg)"));
}
void ClassDefinition::on_libraryRadio_toggled()
{
const bool enLib = libraryRadio->isChecked();
widgetLibraryLabel->setEnabled(enLib);
widgetLibraryEdit->setEnabled(enLib);
const bool enSrc = skeletonCheck->isChecked();
widgetSourceLabel->setEnabled(enSrc);
widgetSourceEdit->setEnabled(enSrc);
widgetBaseClassLabel->setEnabled(enSrc);
widgetBaseClassEdit->setEnabled(enSrc);
const bool enPrj = !enLib || enSrc;
widgetProjectLabel->setEnabled(enPrj);
widgetProjectEdit->setEnabled(enPrj);
widgetProjectEdit->setText(
QFileInfo(widgetProjectEdit->text()).completeBaseName() +
(libraryRadio->isChecked() ? QLatin1String(".pro") : QLatin1String(".pri")));
}
void ClassDefinition::on_skeletonCheck_toggled()
{
on_libraryRadio_toggled();
}
static inline QString xmlFromClassName(const QString &name)
{
QString rc = QLatin1String("<widget class=\"");
rc += name;
rc += QLatin1String("\" name=\"");
if (!name.isEmpty()) {
rc += name.left(1).toLower();
if (name.size() > 1)
rc += name.mid(1);
}
rc += QLatin1String("\">\n</widget>\n");
return rc;
}
void ClassDefinition::setClassName(const QString &name)
{
widgetLibraryEdit->setText(name.toLower());
widgetHeaderEdit->setText(m_fileNamingParameters.headerFileName(name));
pluginClassEdit->setText(name + QLatin1String("Plugin"));
if (!m_domXmlChanged) {
domXmlEdit->setText(xmlFromClassName(name));
m_domXmlChanged = false;
}
}
void ClassDefinition::on_widgetLibraryEdit_textChanged()
{
widgetProjectEdit->setText(
widgetLibraryEdit->text() +
(libraryRadio->isChecked() ? QLatin1String(".pro") : QLatin1String(".pri")));
}
void ClassDefinition::on_widgetHeaderEdit_textChanged()
{
widgetSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(widgetHeaderEdit->text()));
}
void ClassDefinition::on_pluginClassEdit_textChanged()
{
pluginHeaderEdit->setText(m_fileNamingParameters.headerFileName(pluginClassEdit->text()));
}
void ClassDefinition::on_pluginHeaderEdit_textChanged()
{
pluginSourceEdit->setText(m_fileNamingParameters.headerToSourceFileName(pluginHeaderEdit->text()));
}
void ClassDefinition::on_domXmlEdit_textChanged()
{
m_domXmlChanged = true;
}
PluginOptions::WidgetOptions ClassDefinition::widgetOptions(const QString &className) const
{
PluginOptions::WidgetOptions wo;
wo.createSkeleton = skeletonCheck->isChecked();
wo.sourceType =
libraryRadio->isChecked() ?
PluginOptions::WidgetOptions::LinkLibrary :
PluginOptions::WidgetOptions::IncludeProject;
wo.widgetLibrary = widgetLibraryEdit->text();
wo.widgetProjectFile = widgetProjectEdit->text();
wo.widgetClassName = className;
wo.widgetHeaderFile = widgetHeaderEdit->text();
wo.widgetSourceFile = widgetSourceEdit->text();
wo.widgetBaseClassName = widgetBaseClassEdit->text();
wo.pluginClassName = pluginClassEdit->text();
wo.pluginHeaderFile = pluginHeaderEdit->text();
wo.pluginSourceFile = pluginSourceEdit->text();
wo.iconFile = iconPathChooser->path();
wo.group = groupEdit->text();
wo.toolTip = tooltipEdit->text();
wo.whatsThis = whatsthisEdit->toPlainText();
wo.isContainer = containerCheck->isChecked();
wo.domXml = domXmlEdit->toPlainText();
return wo;
}
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef CLASSDEFINITION_H
#define CLASSDEFINITION_H
#include "ui_classdefinition.h"
#include "filenamingparameters.h"
#include "pluginoptions.h"
#include <QtGui/QTabWidget>
namespace Qt4ProjectManager {
namespace Internal {
class ClassDefinition : public QTabWidget, private Ui::ClassDefinition
{
Q_OBJECT
public:
ClassDefinition(QWidget *parent);
void setClassName(const QString &name);
FileNamingParameters fileNamingParameters() const { return m_fileNamingParameters; }
void setFileNamingParameters(const FileNamingParameters &fnp) { m_fileNamingParameters = fnp; }
PluginOptions::WidgetOptions widgetOptions(const QString &className) const;
public Q_SLOTS:
void on_libraryRadio_toggled();
void on_skeletonCheck_toggled();
void on_widgetLibraryEdit_textChanged();
void on_widgetHeaderEdit_textChanged();
void on_pluginClassEdit_textChanged();
void on_pluginHeaderEdit_textChanged();
void on_domXmlEdit_textChanged();
private:
FileNamingParameters m_fileNamingParameters;
bool m_domXmlChanged;
};
}
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qt4ProjectManager::Internal::ClassDefinition</class>
<widget class="QTabWidget" name="Qt4ProjectManager::Internal::ClassDefinition">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>649</width>
<height>427</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="whatsThis">
<string>The header file</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="sourceTab">
<attribute name="title">
<string>&amp;Sources</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="widgetLibraryLabel">
<property name="text">
<string>Widget librar&amp;y:</string>
</property>
<property name="buddy">
<cstring>widgetLibraryEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="widgetLibraryEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="widgetProjectLabel">
<property name="text">
<string>Widget project &amp;file:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>widgetProjectEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="widgetProjectEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="widgetHeaderLabel">
<property name="text">
<string>Widget h&amp;eader file:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>widgetHeaderEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="widgetHeaderEdit">
<property name="whatsThis">
<string>The header file as to be specified i source code. </string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="widgetSourceLabel">
<property name="text">
<string>Widge&amp;t source file:</string>
</property>
<property name="buddy">
<cstring>widgetSourceEdit</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="widgetSourceEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="widgetBaseClassLabel">
<property name="text">
<string>Widget &amp;base class:</string>
</property>
<property name="buddy">
<cstring>widgetBaseClassEdit</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="widgetBaseClassEdit">
<property name="text">
<string>QWidget</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="pluginClassLabel">
<property name="text">
<string>Plugin class &amp;name:</string>
</property>
<property name="buddy">
<cstring>pluginClassEdit</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="pluginClassEdit"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="pluginHeaderLabel">
<property name="text">
<string>Plugin &amp;header file:</string>
</property>
<property name="buddy">
<cstring>pluginHeaderEdit</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="pluginHeaderEdit"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="pluginSourceLabel">
<property name="text">
<string>Plugin sou&amp;rce file:</string>
</property>
<property name="buddy">
<cstring>pluginSourceEdit</cstring>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="pluginSourceEdit"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="iconLabel">
<property name="text">
<string>Icon file:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="Core::Utils::PathChooser" name="iconPathChooser"/>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="libraryRadio">
<property name="text">
<string>&amp;Link library</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<widget class="QCheckBox" name="skeletonCheck">
<property name="text">
<string>Create s&amp;keleton</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="includeRadio">