diff --git a/src/libs/utils/textfieldcheckbox.cpp b/src/libs/utils/textfieldcheckbox.cpp new file mode 100644 index 00000000000..0439644ecac --- /dev/null +++ b/src/libs/utils/textfieldcheckbox.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 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. +** +** 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 "textfieldcheckbox.h" + +namespace Utils { + +/*! + \class Utils::TextFieldCheckBox + \brief The TextFieldCheckBox class is a aheckbox that plays with + \c QWizard::registerField. + + Provides a settable 'text' property containing predefined strings for + \c true and \c false. +*/ + +TextFieldCheckBox::TextFieldCheckBox(const QString &text, QWidget *parent) : + QCheckBox(text, parent), + m_trueText(QLatin1String("true")), m_falseText(QLatin1String("false")) +{ + connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int))); +} + +QString TextFieldCheckBox::text() const +{ + return isChecked() ? m_trueText : m_falseText; +} + +void TextFieldCheckBox::setText(const QString &s) +{ + setChecked(s == m_trueText); +} + +void TextFieldCheckBox::slotStateChanged(int cs) +{ + emit textChanged(cs == Qt::Checked ? m_trueText : m_falseText); +} + +} // namespace Utils diff --git a/src/libs/utils/textfieldcheckbox.h b/src/libs/utils/textfieldcheckbox.h new file mode 100644 index 00000000000..74156b38342 --- /dev/null +++ b/src/libs/utils/textfieldcheckbox.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 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. +** +** 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 TEXTFIELDCHECKBOX_H +#define TEXTFIELDCHECKBOX_H + +#include "utils_global.h" + +#include + +namespace Utils { + +// Documentation inside. +class QTCREATOR_UTILS_EXPORT TextFieldCheckBox : public QCheckBox { + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(QString trueText READ trueText WRITE setTrueText) + Q_PROPERTY(QString falseText READ falseText WRITE setFalseText) + Q_OBJECT +public: + explicit TextFieldCheckBox(const QString &text, QWidget *parent = 0); + + QString text() const; + void setText(const QString &s); + + void setTrueText(const QString &t) { m_trueText = t; } + QString trueText() const { return m_trueText; } + void setFalseText(const QString &t) { m_falseText = t; } + QString falseText() const { return m_falseText; } + +signals: + void textChanged(const QString &); + +private slots: + void slotStateChanged(int); + +private: + QString m_trueText; + QString m_falseText; +}; + +} // namespace Utils + +#endif // TEXTFIELDCHECKBOX_H diff --git a/src/libs/utils/textfieldcombobox.cpp b/src/libs/utils/textfieldcombobox.cpp new file mode 100644 index 00000000000..453b5426b7e --- /dev/null +++ b/src/libs/utils/textfieldcombobox.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 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. +** +** 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 "textfieldcombobox.h" + +#include "qtcassert.h" + +namespace Utils { + +/*! + \class Utils::TextFieldComboBox + \brief The TextFieldComboBox class is a non-editable combo box for text + editing purposes that plays with \c QWizard::registerField (providing a + settable 'text' property). + + Allows for a separation of values to be used for wizard fields replacement + and display texts. +*/ + +TextFieldComboBox::TextFieldComboBox(QWidget *parent) : + QComboBox(parent) +{ + setEditable(false); + connect(this, SIGNAL(currentIndexChanged(int)), + this, SLOT(slotCurrentIndexChanged(int))); +} + +QString TextFieldComboBox::text() const +{ + return valueAt(currentIndex()); +} + +void TextFieldComboBox::setText(const QString &s) +{ + const int index = findData(QVariant(s), Qt::UserRole); + if (index != -1 && index != currentIndex()) + setCurrentIndex(index); +} + +void TextFieldComboBox::slotCurrentIndexChanged(int i) +{ + emit text4Changed(valueAt(i)); +} + +void TextFieldComboBox::setItems(const QStringList &displayTexts, + const QStringList &values) +{ + QTC_ASSERT(displayTexts.size() == values.size(), return); + clear(); + addItems(displayTexts); + const int count = values.count(); + for (int i = 0; i < count; i++) + setItemData(i, QVariant(values.at(i)), Qt::UserRole); +} + +QString TextFieldComboBox::valueAt(int i) const +{ + return i >= 0 && i < count() ? itemData(i, Qt::UserRole).toString() : QString(); +} + +} // namespace Utils diff --git a/src/libs/utils/textfieldcombobox.h b/src/libs/utils/textfieldcombobox.h new file mode 100644 index 00000000000..63aa95ca5a6 --- /dev/null +++ b/src/libs/utils/textfieldcombobox.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 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. +** +** 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 TEXTFIELDCOMBOBOX_H +#define TEXTFIELDCOMBOBOX_H + +#include "utils_global.h" + +#include + +namespace Utils { + +// Documentation inside. +class QTCREATOR_UTILS_EXPORT TextFieldComboBox : public QComboBox { + Q_PROPERTY(QString text READ text WRITE setText) + Q_OBJECT +public: + explicit TextFieldComboBox(QWidget *parent = 0); + + QString text() const; + void setText(const QString &s); + + void setItems(const QStringList &displayTexts, const QStringList &values); + +signals: + void text4Changed(const QString &); // Do not conflict with Qt 3 compat signal. + +private slots: + void slotCurrentIndexChanged(int); + +private: + inline QString valueAt(int) const; +}; + +} // namespace Utils + +#endif // TEXTFIELDCOMBOBOX_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index ca6da2708b2..be12d23f981 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -19,6 +19,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/reloadpromptutils.cpp \ $$PWD/settingsselector.cpp \ $$PWD/stringutils.cpp \ + $$PWD/textfieldcheckbox.cpp \ + $$PWD/textfieldcombobox.cpp \ $$PWD/filesearch.cpp \ $$PWD/pathchooser.cpp \ $$PWD/pathlisteditor.cpp \ @@ -100,6 +102,8 @@ HEADERS += \ $$PWD/reloadpromptutils.h \ $$PWD/settingsselector.h \ $$PWD/stringutils.h \ + $$PWD/textfieldcheckbox.h \ + $$PWD/textfieldcombobox.h \ $$PWD/filesearch.h \ $$PWD/listutils.h \ $$PWD/pathchooser.h \ diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp index 9836a5893cb..e765fa8c619 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include @@ -51,97 +53,11 @@ enum { debug = 0 }; +using namespace Utils; + namespace ProjectExplorer { namespace Internal { -// ----------- TextFieldComboBox - -/*! - \class ProjectExplorer::Internal::TextFieldComboBox - \brief The TextFieldComboBox class is a non-editable combo box for text - editing purposes that plays with \c QWizard::registerField (providing a - settable 'text' property). - - Allows for a separation of values to be used for wizard fields replacement - and display texts. - - \sa ProjectExplorer::Internal::CustomWizardFieldPage, ProjectExplorer::CustomWizard -*/ - -TextFieldComboBox::TextFieldComboBox(QWidget *parent) : - QComboBox(parent) -{ - setEditable(false); - connect(this, SIGNAL(currentIndexChanged(int)), - this, SLOT(slotCurrentIndexChanged(int))); -} - -QString TextFieldComboBox::text() const -{ - return valueAt(currentIndex()); -} - -void TextFieldComboBox::setText(const QString &s) -{ - const int index = findData(QVariant(s), Qt::UserRole); - if (index != -1 && index != currentIndex()) - setCurrentIndex(index); -} - -void TextFieldComboBox::slotCurrentIndexChanged(int i) -{ - emit text4Changed(valueAt(i)); -} - -void TextFieldComboBox::setItems(const QStringList &displayTexts, - const QStringList &values) -{ - QTC_ASSERT(displayTexts.size() == values.size(), return); - clear(); - addItems(displayTexts); - const int count = values.count(); - for (int i = 0; i < count; i++) - setItemData(i, QVariant(values.at(i)), Qt::UserRole); -} - -QString TextFieldComboBox::valueAt(int i) const -{ - return i >= 0 && i < count() ? itemData(i, Qt::UserRole).toString() : QString(); -} - -/*! - \class ProjectExplorer::Internal::TextFieldCheckBox - \brief The TextFieldCheckBox class is a aheckbox that plays with - \c QWizard::registerField. - - Provides a settable 'text' property containing predefined strings for - \c true and \c false. - - \sa ProjectExplorer::Internal::CustomWizardFieldPage, ProjectExplorer::CustomWizard -*/ - -TextFieldCheckBox::TextFieldCheckBox(const QString &text, QWidget *parent) : - QCheckBox(text, parent), - m_trueText(QLatin1String("true")), m_falseText(QLatin1String("false")) -{ - connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int))); -} - -QString TextFieldCheckBox::text() const -{ - return isChecked() ? m_trueText : m_falseText; -} - -void TextFieldCheckBox::setText(const QString &s) -{ - setChecked(s == m_trueText); -} - -void TextFieldCheckBox::slotStateChanged(int cs) -{ - emit textChanged(cs == Qt::Checked ? m_trueText : m_falseText); -} - /*! \class ProjectExplorer::Internal::CustomWizardFieldPage \brief The CustomWizardFieldPage class is a simple custom wizard page @@ -167,7 +83,7 @@ CustomWizardFieldPage::TextEditData::TextEditData(QTextEdit* le, const QString & { } -CustomWizardFieldPage::PathChooserData::PathChooserData(Utils::PathChooser* pe, const QString &defText) : +CustomWizardFieldPage::PathChooserData::PathChooserData(PathChooser* pe, const QString &defText) : pathChooser(pe), defaultText(defText) { } @@ -324,20 +240,20 @@ QWidget *CustomWizardFieldPage::registerTextEdit(const QString &fieldName, QWidget *CustomWizardFieldPage::registerPathChooser(const QString &fieldName, const CustomWizardField &field) { - Utils::PathChooser *pathChooser = new Utils::PathChooser; + PathChooser *pathChooser = new PathChooser; const QString expectedKind = field.controlAttributes.value(QLatin1String("expectedkind")).toLower(); if (expectedKind == QLatin1String("existingdirectory")) - pathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory); + pathChooser->setExpectedKind(PathChooser::ExistingDirectory); else if (expectedKind == QLatin1String("directory")) - pathChooser->setExpectedKind(Utils::PathChooser::Directory); + pathChooser->setExpectedKind(PathChooser::Directory); else if (expectedKind == QLatin1String("file")) - pathChooser->setExpectedKind(Utils::PathChooser::File); + pathChooser->setExpectedKind(PathChooser::File); else if (expectedKind == QLatin1String("existingcommand")) - pathChooser->setExpectedKind(Utils::PathChooser::ExistingCommand); + pathChooser->setExpectedKind(PathChooser::ExistingCommand); else if (expectedKind == QLatin1String("command")) - pathChooser->setExpectedKind(Utils::PathChooser::Command); + pathChooser->setExpectedKind(PathChooser::Command); else if (expectedKind == QLatin1String("any")) - pathChooser->setExpectedKind(Utils::PathChooser::Any); + pathChooser->setExpectedKind(PathChooser::Any); pathChooser->setHistoryCompleter(QString::fromLatin1("PE.Custom.") + m_parameters->id + QLatin1Char('.') + field.name); registerField(fieldName, pathChooser, "path", SIGNAL(changed(QString))); @@ -518,7 +434,7 @@ CustomWizardPage::CustomWizardPage(const QSharedPointer &ct const QSharedPointer ¶meters, QWidget *parent) : CustomWizardFieldPage(ctx, parameters, parent), - m_pathChooser(new Utils::PathChooser) + m_pathChooser(new PathChooser) { m_pathChooser->setHistoryCompleter(QLatin1String("PE.ProjectDir.History")); addRow(tr("Path:"), m_pathChooser); diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.h b/src/plugins/projectexplorer/customwizard/customwizardpage.h index a48b5afee81..1c7ad4d3127 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.h +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.h @@ -51,56 +51,6 @@ class CustomWizardField; class CustomWizardParameters; class CustomWizardContext; -// Documentation inside. -class TextFieldComboBox : public QComboBox { - Q_PROPERTY(QString text READ text WRITE setText) - Q_OBJECT -public: - explicit TextFieldComboBox(QWidget *parent = 0); - - QString text() const; - void setText(const QString &s); - - void setItems(const QStringList &displayTexts, const QStringList &values); - -signals: - void text4Changed(const QString &); // Do not conflict with Qt 3 compat signal. - -private slots: - void slotCurrentIndexChanged(int); - -private: - inline QString valueAt(int) const; -}; - -// Documentation inside. -class TextFieldCheckBox : public QCheckBox { - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QString trueText READ trueText WRITE setTrueText) - Q_PROPERTY(QString falseText READ falseText WRITE setFalseText) - Q_OBJECT -public: - explicit TextFieldCheckBox(const QString &text, QWidget *parent = 0); - - QString text() const; - void setText(const QString &s); - - void setTrueText(const QString &t) { m_trueText = t; } - QString trueText() const { return m_trueText; } - void setFalseText(const QString &t) { m_falseText = t; } - QString falseText() const { return m_falseText; } - -signals: - void textChanged(const QString &); - -private slots: - void slotStateChanged(int); - -private: - QString m_trueText; - QString m_falseText; -}; - // Documentation inside. class CustomWizardFieldPage : public QWizardPage { Q_OBJECT