summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@nokia.com>2011-11-16 09:17:21 +0000
committerTobias Hunger <tobias.hunger@nokia.com>2011-11-16 13:52:32 +0100
commitc56d6587d662985938be0244c2c3c5bb71f2764b (patch)
tree2f50622186a41938a50556380d97165bc8070d54
parentcad3bb8085a1aa5e8454a467991f207682a98908 (diff)
downloadqt-creator-c56d6587d662985938be0244c2c3c5bb71f2764b.tar.gz
Add a widget for the typical selection of settings
This will be used to unify handling of the build/run/deplop configuration selection and is useful e.g. in the remote linux plugin as well. Change-Id: I3fdf5c4b98128e6406853f47ed7524311bd43df6 Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
-rw-r--r--src/libs/utils/settingsselector.cpp187
-rw-r--r--src/libs/utils/settingsselector.h92
-rw-r--r--src/libs/utils/utils-lib.pri2
3 files changed, 281 insertions, 0 deletions
diff --git a/src/libs/utils/settingsselector.cpp b/src/libs/utils/settingsselector.cpp
new file mode 100644
index 0000000000..fb4d1a06ed
--- /dev/null
+++ b/src/libs/utils/settingsselector.cpp
@@ -0,0 +1,187 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "settingsselector.h"
+
+#include <QtCore/QAbstractItemModel>
+#include <QtCore/QVariant>
+
+#include <QtGui/QAction>
+#include <QtGui/QComboBox>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QInputDialog>
+#include <QtGui/QLabel>
+#include <QtGui/QMenu>
+#include <QtGui/QMessageBox>
+#include <QtGui/QPushButton>
+#include <QtGui/QSpacerItem>
+
+namespace Utils {
+
+// --------------------------------------------------------------------------
+// SettingsSelector
+// --------------------------------------------------------------------------
+
+SettingsSelector::SettingsSelector(QWidget *parent) :
+ QWidget(parent)
+{
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(6);
+
+ m_configurationCombo = new QComboBox(this);
+ m_configurationCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ m_configurationCombo->setMinimumContentsLength(80);
+
+ m_addButton = new QPushButton(tr("Add"), this);
+ m_removeButton = new QPushButton(tr("Remove"), this);
+ m_renameButton = new QPushButton(tr("Rename"), this);
+
+ m_label = new QLabel(this);
+ m_label->setMinimumWidth(200);
+ m_label->setBuddy(m_configurationCombo);
+
+ layout->addWidget(m_label);
+ layout->addWidget(m_configurationCombo);
+ layout->addWidget(m_addButton);
+ layout->addWidget(m_removeButton);
+ layout->addWidget(m_renameButton);
+
+ layout->addSpacerItem(new QSpacerItem(0, 0));
+
+ updateButtonState();
+
+ connect(m_addButton, SIGNAL(clicked()), this, SIGNAL(add()));
+ connect(m_removeButton, SIGNAL(clicked()), this, SLOT(removeButtonClicked()));
+ connect(m_renameButton, SIGNAL(clicked()), this, SLOT(renameButtonClicked()));
+ connect(m_configurationCombo, SIGNAL(currentIndexChanged(int)),
+ this, SIGNAL(currentChanged(int)));
+}
+
+SettingsSelector::~SettingsSelector()
+{ }
+
+void SettingsSelector::setConfigurationModel(QAbstractItemModel *model)
+{
+ if (m_configurationCombo->model()) {
+ disconnect(m_configurationCombo->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateButtonState()));
+ disconnect(m_configurationCombo->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(updateButtonState()));
+ }
+ m_configurationCombo->setModel(model);
+ connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateButtonState()));
+ connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(updateButtonState()));
+
+ updateButtonState();
+}
+
+QAbstractItemModel *SettingsSelector::configurationModel() const
+{
+ return m_configurationCombo->model();
+}
+
+void SettingsSelector::setLabelText(const QString &text)
+{
+ m_label->setText(text);
+}
+
+QString SettingsSelector::labelText() const
+{
+ return m_label->text();
+}
+
+void SettingsSelector::setCurrentIndex(int index)
+{
+ m_configurationCombo->setCurrentIndex(index);
+}
+
+void SettingsSelector::setAddMenu(QMenu *menu)
+{
+ m_addButton->setMenu(menu);
+}
+
+QMenu *SettingsSelector::addMenu() const
+{
+ return m_addButton->menu();
+}
+
+void SettingsSelector::removeButtonClicked()
+{
+ int pos = m_configurationCombo->currentIndex();
+ if (pos < 0)
+ return;
+ const QString title = m_kindOfDisplayName.isEmpty() ? tr("Remove") :
+ tr("Remove %1").arg(m_kindOfDisplayName);
+ const QString message = m_kindOfDisplayName.isEmpty() ?
+ tr("Do you really want to delete the configuration <b>%1</b>?")
+ .arg(m_configurationCombo->currentText()) :
+ tr("Do you really want to delete the %1 <b>%2</b>?")
+ .arg(m_kindOfDisplayName)
+ .arg(m_configurationCombo->currentText());
+ QMessageBox msgBox(QMessageBox::Question, title, message, QMessageBox::Yes|QMessageBox::No, this);
+ msgBox.setDefaultButton(QMessageBox::No);
+ msgBox.setEscapeButton(QMessageBox::No);
+ if (msgBox.exec() == QMessageBox::No)
+ return;
+
+ emit remove(pos);
+}
+
+void SettingsSelector::renameButtonClicked()
+{
+ int pos = m_configurationCombo->currentIndex();
+ if (pos < 0)
+ return;
+
+ bool ok;
+ const QString &message = m_kindOfDisplayName.isEmpty() ?
+ tr("New name for configuration <b>%1</b>:")
+ .arg(m_configurationCombo->currentText()) :
+ tr("New name for %1: <b>%2</b>:")
+ .arg(m_kindOfDisplayName).arg(m_configurationCombo->currentText());
+
+ QString name = QInputDialog::getText(this, tr("Rename..."), message,
+ QLineEdit::Normal, m_configurationCombo->currentText(), &ok);
+ if (!ok)
+ return;
+
+ emit rename(pos, name);
+}
+
+void SettingsSelector::updateButtonState()
+{
+ bool haveItems = m_configurationCombo->count() > 0;
+ m_addButton->setEnabled(true);
+ m_removeButton->setEnabled(haveItems);
+ m_renameButton->setEnabled(haveItems);
+}
+
+} // namespace Utils
diff --git a/src/libs/utils/settingsselector.h b/src/libs/utils/settingsselector.h
new file mode 100644
index 0000000000..6e68ac5494
--- /dev/null
+++ b/src/libs/utils/settingsselector.h
@@ -0,0 +1,92 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef SETTINGSSELECTORWIDGET_H
+#define SETTINGSSELECTORWIDGET_H
+
+#include "utils_global.h"
+
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QLabel;
+class QMenu;
+class QPushButton;
+class QString;
+class QVariant;
+QT_END_NAMESPACE
+
+namespace Utils {
+
+class QTCREATOR_UTILS_EXPORT SettingsSelector : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit SettingsSelector(QWidget *parent = 0);
+ ~SettingsSelector();
+
+ void setConfigurationModel(QAbstractItemModel *model);
+ QAbstractItemModel *configurationModel() const;
+
+ void setLabelText(const QString &text);
+ QString labelText() const;
+ void setCurrentIndex(int index);
+
+ void setAddMenu(QMenu *);
+ QMenu *addMenu() const;
+
+signals:
+ void add();
+ void remove(int index);
+ void rename(int index, const QString &newName);
+ void currentChanged(int index);
+
+private slots:
+ void removeButtonClicked();
+ void renameButtonClicked();
+ void updateButtonState();
+
+private:
+ QLabel *m_label;
+ QString m_kindOfDisplayName;
+ QComboBox *m_configurationCombo;
+ QPushButton *m_addButton;
+ QPushButton *m_removeButton;
+ QPushButton *m_renameButton;
+};
+
+} // namespace Utils
+
+#endif // SETTINGSSELECTORWIDGET_H
diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri
index 187f0ba852..3e70a1340a 100644
--- a/src/libs/utils/utils-lib.pri
+++ b/src/libs/utils/utils-lib.pri
@@ -17,6 +17,7 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/environmentmodel.cpp \
$$PWD/qtcprocess.cpp \
$$PWD/reloadpromptutils.cpp \
+ $$PWD/settingsselector.cpp \
$$PWD/stringutils.cpp \
$$PWD/filesearch.cpp \
$$PWD/pathchooser.cpp \
@@ -111,6 +112,7 @@ HEADERS += \
$$PWD/qtcprocess.h \
$$PWD/utils_global.h \
$$PWD/reloadpromptutils.h \
+ $$PWD/settingsselector.h \
$$PWD/stringutils.h \
$$PWD/filesearch.h \
$$PWD/listutils.h \