Commit bccf4a1f authored by Friedemann Kleint's avatar Friedemann Kleint

Fixes: Introduce a cpp settingspage containing file naming conventions (lower...

Fixes: Introduce a cpp settingspage containing file naming conventions (lower case and suffixes). Reorder VCS settings pages.

Task: 241959, 248085

RevBy: Optics/Naming checked by con
Details: Give IOptionPage an id() to differentiate from trName(). Make showOptionsDialog return a bool (applied) and give it an optional parent. Change Cpp and form class wizards, give them a Configure... button to change those settings.
parent 3b030572
...@@ -150,5 +150,10 @@ void BaseValidatingLineEdit::slotReturnPressed() ...@@ -150,5 +150,10 @@ void BaseValidatingLineEdit::slotReturnPressed()
emit validReturnPressed(); emit validReturnPressed();
} }
void BaseValidatingLineEdit::triggerChanged()
{
slotChanged(text());
}
} // namespace Utils } // namespace Utils
} // namespace Core } // namespace Core
...@@ -72,6 +72,9 @@ public: ...@@ -72,6 +72,9 @@ public:
QColor errorColor() const; QColor errorColor() const;
void setErrorColor(const QColor &); void setErrorColor(const QColor &);
// Trigger an update (after changing settings)
void triggerChanged();
static QColor textColor(const QWidget *w); static QColor textColor(const QWidget *w);
static void setTextColor(QWidget *w, const QColor &c); static void setTextColor(QWidget *w, const QColor &c);
......
...@@ -43,13 +43,15 @@ struct ClassNameValidatingLineEditPrivate { ...@@ -43,13 +43,15 @@ struct ClassNameValidatingLineEditPrivate {
const QRegExp m_nameRegexp; const QRegExp m_nameRegexp;
const QString m_namespaceDelimiter; const QString m_namespaceDelimiter;
bool m_namespacesEnabled; bool m_namespacesEnabled;
bool m_lowerCaseFileName;
}; };
// Match something like "Namespace1::Namespace2::ClassName". // Match something like "Namespace1::Namespace2::ClassName".
ClassNameValidatingLineEditPrivate:: ClassNameValidatingLineEditPrivate() : ClassNameValidatingLineEditPrivate:: ClassNameValidatingLineEditPrivate() :
m_nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*")), m_nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*")),
m_namespaceDelimiter(QLatin1String("::")), m_namespaceDelimiter(QLatin1String("::")),
m_namespacesEnabled(false) m_namespacesEnabled(false),
m_lowerCaseFileName(false)
{ {
QTC_ASSERT(m_nameRegexp.isValid(), return); QTC_ASSERT(m_nameRegexp.isValid(), return);
} }
...@@ -96,7 +98,7 @@ void ClassNameValidatingLineEdit::slotChanged(const QString &t) ...@@ -96,7 +98,7 @@ void ClassNameValidatingLineEdit::slotChanged(const QString &t)
Core::Utils::BaseValidatingLineEdit::slotChanged(t); Core::Utils::BaseValidatingLineEdit::slotChanged(t);
if (isValid()) { if (isValid()) {
// Suggest file names, strip namespaces // Suggest file names, strip namespaces
QString fileName = t.toLower(); QString fileName = m_d->m_lowerCaseFileName ? t.toLower() : t;
if (m_d->m_namespacesEnabled) { if (m_d->m_namespacesEnabled) {
const int namespaceIndex = fileName.lastIndexOf(m_d->m_namespaceDelimiter); const int namespaceIndex = fileName.lastIndexOf(m_d->m_namespaceDelimiter);
if (namespaceIndex != -1) if (namespaceIndex != -1)
...@@ -132,5 +134,15 @@ QString ClassNameValidatingLineEdit::createClassName(const QString &name) ...@@ -132,5 +134,15 @@ QString ClassNameValidatingLineEdit::createClassName(const QString &name)
return className; return className;
} }
bool ClassNameValidatingLineEdit::lowerCaseFileName() const
{
return m_d->m_lowerCaseFileName;
}
void ClassNameValidatingLineEdit::setLowerCaseFileName(bool v)
{
m_d->m_lowerCaseFileName = v;
}
} // namespace Utils } // namespace Utils
} // namespace Core } // namespace Core
...@@ -46,6 +46,7 @@ class QWORKBENCH_UTILS_EXPORT ClassNameValidatingLineEdit ...@@ -46,6 +46,7 @@ class QWORKBENCH_UTILS_EXPORT ClassNameValidatingLineEdit
{ {
Q_DISABLE_COPY(ClassNameValidatingLineEdit) Q_DISABLE_COPY(ClassNameValidatingLineEdit)
Q_PROPERTY(bool namespacesEnabled READ namespacesEnabled WRITE setNamespacesEnabled DESIGNABLE true) Q_PROPERTY(bool namespacesEnabled READ namespacesEnabled WRITE setNamespacesEnabled DESIGNABLE true)
Q_PROPERTY(bool lowerCaseFileName READ lowerCaseFileName WRITE setLowerCaseFileName)
Q_OBJECT Q_OBJECT
public: public:
...@@ -55,6 +56,9 @@ public: ...@@ -55,6 +56,9 @@ public:
bool namespacesEnabled() const; bool namespacesEnabled() const;
void setNamespacesEnabled(bool b); void setNamespacesEnabled(bool b);
bool lowerCaseFileName() const;
void setLowerCaseFileName(bool v);
// Clean an input string to get a valid class name. // Clean an input string to get a valid class name.
static QString createClassName(const QString &name); static QString createClassName(const QString &name);
......
...@@ -84,7 +84,7 @@ NewClassWidget::NewClassWidget(QWidget *parent) : ...@@ -84,7 +84,7 @@ NewClassWidget::NewClassWidget(QWidget *parent) :
m_d->m_ui.baseClassComboBox->setEditable(false); m_d->m_ui.baseClassComboBox->setEditable(false);
connect(m_d->m_ui.classLineEdit, SIGNAL(updateFileName(QString)), connect(m_d->m_ui.classLineEdit, SIGNAL(updateFileName(QString)),
this, SLOT(updateFileNames(QString))); this, SLOT(slotUpdateFileNames(QString)));
connect(m_d->m_ui.classLineEdit, SIGNAL(textEdited(QString)), connect(m_d->m_ui.classLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(classNameEdited())); this, SLOT(classNameEdited()));
connect(m_d->m_ui.baseClassComboBox, SIGNAL(currentIndexChanged(int)), connect(m_d->m_ui.baseClassComboBox, SIGNAL(currentIndexChanged(int)),
...@@ -357,6 +357,16 @@ void NewClassWidget::setAllowDirectories(bool v) ...@@ -357,6 +357,16 @@ void NewClassWidget::setAllowDirectories(bool v)
} }
} }
bool NewClassWidget::lowerCaseFiles() const
{
return m_d->m_ui.classLineEdit->lowerCaseFileName();
}
void NewClassWidget::setLowerCaseFiles(bool v)
{
m_d->m_ui.classLineEdit->setLowerCaseFileName(v);
}
void NewClassWidget::slotValidChanged() void NewClassWidget::slotValidChanged()
{ {
const bool newValid = isValid(); const bool newValid = isValid();
...@@ -415,7 +425,12 @@ bool NewClassWidget::isValid(QString *error) const ...@@ -415,7 +425,12 @@ bool NewClassWidget::isValid(QString *error) const
return true; return true;
} }
void NewClassWidget::updateFileNames(const QString &baseName) void NewClassWidget::triggerUpdateFileNames()
{
m_d->m_ui.classLineEdit->triggerChanged();
}
void NewClassWidget::slotUpdateFileNames(const QString &baseName)
{ {
if (debugNewClassWidget) if (debugNewClassWidget)
qDebug() << Q_FUNC_INFO << baseName << m_d->m_headerExtension << m_d->m_sourceExtension; qDebug() << Q_FUNC_INFO << baseName << m_d->m_headerExtension << m_d->m_sourceExtension;
......
...@@ -70,6 +70,7 @@ class QWORKBENCH_UTILS_EXPORT NewClassWidget : public QWidget ...@@ -70,6 +70,7 @@ class QWORKBENCH_UTILS_EXPORT NewClassWidget : public QWidget
Q_PROPERTY(bool formInputCheckable READ formInputCheckable WRITE setFormInputCheckable DESIGNABLE true) Q_PROPERTY(bool formInputCheckable READ formInputCheckable WRITE setFormInputCheckable DESIGNABLE true)
Q_PROPERTY(bool formInputChecked READ formInputChecked WRITE setFormInputChecked DESIGNABLE true) Q_PROPERTY(bool formInputChecked READ formInputChecked WRITE setFormInputChecked DESIGNABLE true)
Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories) Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories)
Q_PROPERTY(bool lowerCaseFiles READ lowerCaseFiles WRITE setLowerCaseFiles)
// Utility "USER" property for wizards containing file names. // Utility "USER" property for wizards containing file names.
Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true) Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true)
public: public:
...@@ -95,6 +96,7 @@ public: ...@@ -95,6 +96,7 @@ public:
QString headerExtension() const; QString headerExtension() const;
QString formExtension() const; QString formExtension() const;
bool allowDirectories() const; bool allowDirectories() const;
bool lowerCaseFiles() const;
bool isValid(QString *error = 0) const; bool isValid(QString *error = 0) const;
...@@ -123,19 +125,25 @@ public slots: ...@@ -123,19 +125,25 @@ public slots:
void setHeaderExtension(const QString &e); void setHeaderExtension(const QString &e);
void setFormExtension(const QString &e); void setFormExtension(const QString &e);
void setAllowDirectories(bool v); void setAllowDirectories(bool v);
void setLowerCaseFiles(bool v);
/* Suggest a class name from the base class by stripping the leading 'Q' /* Suggest a class name from the base class by stripping the leading 'Q'
* character. This will happen automagically if the base class combo * character. This will happen automagically if the base class combo
* changes until the class line edited is manually edited. */ * changes until the class line edited is manually edited. */
void suggestClassNameFromBase(); void suggestClassNameFromBase();
public slots:
// Trigger an update (after changing settings)
void triggerUpdateFileNames();
private slots: private slots:
void updateFileNames(const QString &t); void slotUpdateFileNames(const QString &t);
void slotValidChanged(); void slotValidChanged();
void slotActivated(); void slotActivated();
void classNameEdited(); void classNameEdited();
void slotFormInputChecked(); void slotFormInputChecked();
private: private:
void setFormInputCheckable(bool checkable, bool force); void setFormInputCheckable(bool checkable, bool force);
......
...@@ -234,15 +234,19 @@ QString CMakeSettingsPage::findCmakeExecutable() const ...@@ -234,15 +234,19 @@ QString CMakeSettingsPage::findCmakeExecutable() const
return env.searchInPath("cmake"); return env.searchInPath("cmake");
} }
QString CMakeSettingsPage::id() const
{
return QLatin1String("CMake");
}
QString CMakeSettingsPage::name() const QString CMakeSettingsPage::trName() const
{ {
return "CMake"; return tr("CMake");
} }
QString CMakeSettingsPage::category() const QString CMakeSettingsPage::category() const
{ {
return "CMake"; return QLatin1String("CMake");
} }
QString CMakeSettingsPage::trCategory() const QString CMakeSettingsPage::trCategory() const
......
...@@ -92,7 +92,8 @@ class CMakeSettingsPage : public Core::IOptionsPage ...@@ -92,7 +92,8 @@ class CMakeSettingsPage : public Core::IOptionsPage
public: public:
CMakeSettingsPage(); CMakeSettingsPage();
virtual ~CMakeSettingsPage(); virtual ~CMakeSettingsPage();
virtual QString name() const; virtual QString id() const;
virtual QString trName() const;
virtual QString category() const; virtual QString category() const;
virtual QString trCategory() const; virtual QString trCategory() const;
......
...@@ -64,9 +64,9 @@ QStringList CoreImpl::showNewItemDialog(const QString &title, ...@@ -64,9 +64,9 @@ QStringList CoreImpl::showNewItemDialog(const QString &title,
return m_mainwindow->showNewItemDialog(title, wizards, defaultLocation); return m_mainwindow->showNewItemDialog(title, wizards, defaultLocation);
} }
void CoreImpl::showOptionsDialog(const QString &group, const QString &page) bool CoreImpl::showOptionsDialog(const QString &group, const QString &page, QWidget *parent)
{ {
m_mainwindow->showOptionsDialog(group, page); return m_mainwindow->showOptionsDialog(group, page, parent);
} }
ActionManager *CoreImpl::actionManager() const ActionManager *CoreImpl::actionManager() const
......
...@@ -47,8 +47,9 @@ public: ...@@ -47,8 +47,9 @@ public:
QStringList showNewItemDialog(const QString &title, QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()); const QString &defaultLocation = QString());
void showOptionsDialog(const QString &group = QString(), bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString()); const QString &page = QString(),
QWidget *parent = 0);
ActionManager *actionManager() const; ActionManager *actionManager() const;
FileManager *fileManager() const ; FileManager *fileManager() const ;
......
...@@ -38,6 +38,21 @@ ...@@ -38,6 +38,21 @@
namespace Core { namespace Core {
/*!
\class Core::IOptionsPage
\brief The IOptionsPage is an interface for providing options pages.
Guidelines for implementing:
\list
\o id() is an id used for filtering when calling ICore:: showOptionsDialog()
\o trName() is the (translated) name for display.
\o category() is the category used for filtering when calling ICore:: showOptionsDialog()
\o trCategory() is the translated category
\o apply() is called to store the settings. It should detect if any changes have been
made and store those.
\endlist
*/
class CORE_EXPORT IOptionsPage : public QObject class CORE_EXPORT IOptionsPage : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -45,7 +60,8 @@ public: ...@@ -45,7 +60,8 @@ public:
IOptionsPage(QObject *parent = 0) : QObject(parent) {} IOptionsPage(QObject *parent = 0) : QObject(parent) {}
virtual ~IOptionsPage() {} virtual ~IOptionsPage() {}
virtual QString name() const = 0; virtual QString id() const = 0;
virtual QString trName() const = 0;
virtual QString category() const = 0; virtual QString category() const = 0;
virtual QString trCategory() const = 0; virtual QString trCategory() const = 0;
......
...@@ -39,7 +39,7 @@ using namespace Core::Internal; ...@@ -39,7 +39,7 @@ using namespace Core::Internal;
SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory, SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
const QString &initialPage) const QString &initialPage)
: QDialog(parent) : QDialog(parent), m_applied(false)
{ {
setupUi(this); setupUi(this);
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
...@@ -60,7 +60,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory, ...@@ -60,7 +60,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
int index = 0; int index = 0;
foreach (IOptionsPage *page, pages) { foreach (IOptionsPage *page, pages) {
QTreeWidgetItem *item = new QTreeWidgetItem; QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, page->name()); item->setText(0, page->trName());
item->setData(0, Qt::UserRole, index); item->setData(0, Qt::UserRole, index);
QStringList categoriesId = page->category().split(QLatin1Char('|')); QStringList categoriesId = page->category().split(QLatin1Char('|'));
...@@ -94,7 +94,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory, ...@@ -94,7 +94,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
m_pages.append(page); m_pages.append(page);
stackedPages->addWidget(page->createPage(stackedPages)); stackedPages->addWidget(page->createPage(stackedPages));
if (page->name() == initialPage && currentCategory == initialCategory) { if (page->id() == initialPage && currentCategory == initialCategory) {
stackedPages->setCurrentIndex(stackedPages->count()); stackedPages->setCurrentIndex(stackedPages->count());
pageTree->setCurrentItem(item); pageTree->setCurrentItem(item);
} }
...@@ -123,6 +123,7 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *) ...@@ -123,6 +123,7 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *)
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
m_applied = true;
foreach (IOptionsPage *page, m_pages) { foreach (IOptionsPage *page, m_pages) {
page->apply(); page->apply();
page->finish(); page->finish();
...@@ -141,4 +142,12 @@ void SettingsDialog::apply() ...@@ -141,4 +142,12 @@ void SettingsDialog::apply()
{ {
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_pages)
page->apply(); page->apply();
m_applied = true;
}
bool SettingsDialog::execDialog()
{
m_applied = false;
exec();
return m_applied;
} }
...@@ -49,6 +49,10 @@ public: ...@@ -49,6 +49,10 @@ public:
const QString &initialPage = QString()); const QString &initialPage = QString());
~SettingsDialog(); ~SettingsDialog();
// Run the dialog and return true if 'Ok' was choosen or 'Apply' was invoked
// at least once
bool execDialog();
private slots: private slots:
void pageSelected(QTreeWidgetItem *cat); void pageSelected(QTreeWidgetItem *cat);
void accept(); void accept();
...@@ -57,6 +61,7 @@ private slots: ...@@ -57,6 +61,7 @@ private slots:
private: private:
QList<Core::IOptionsPage*> m_pages; QList<Core::IOptionsPage*> m_pages;
bool m_applied;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -59,7 +59,13 @@ ShortcutSettings::~ShortcutSettings() ...@@ -59,7 +59,13 @@ ShortcutSettings::~ShortcutSettings()
} }
// IOptionsPage // IOptionsPage
QString ShortcutSettings::name() const
QString ShortcutSettings::id() const
{
return QLatin1String("Keyboard");
}
QString ShortcutSettings::trName() const
{ {
return tr("Keyboard"); return tr("Keyboard");
} }
......
...@@ -67,7 +67,8 @@ public: ...@@ -67,7 +67,8 @@ public:
~ShortcutSettings(); ~ShortcutSettings();
// IOptionsPage // IOptionsPage
QString name() const; QString id() const;
QString trName() const;
QString category() const; QString category() const;
QString trCategory() const; QString trCategory() const;
......
...@@ -43,7 +43,12 @@ GeneralSettings::GeneralSettings(): ...@@ -43,7 +43,12 @@ GeneralSettings::GeneralSettings():
{ {
} }
QString GeneralSettings::name() const QString GeneralSettings::id() const
{
return QLatin1String("General");
}
QString GeneralSettings::trName() const
{ {
return tr("General"); return tr("General");
} }
......
...@@ -47,7 +47,8 @@ class GeneralSettings : public IOptionsPage ...@@ -47,7 +47,8 @@ class GeneralSettings : public IOptionsPage
public: public:
GeneralSettings(); GeneralSettings();
QString name() const; QString id() const;
QString trName() const;
QString category() const; QString category() const;
QString trCategory() const; QString trCategory() const;
QWidget* createPage(QWidget *parent); QWidget* createPage(QWidget *parent);
......
...@@ -70,8 +70,9 @@ public: ...@@ -70,8 +70,9 @@ public:
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()) = 0; const QString &defaultLocation = QString()) = 0;
virtual void showOptionsDialog(const QString &group = QString(), virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString()) = 0; const QString &page = QString(),
QWidget *parent = 0) = 0;
virtual ActionManager *actionManager() const = 0; virtual ActionManager *actionManager() const = 0;
virtual FileManager *fileManager() const = 0; virtual FileManager *fileManager() const = 0;
......
...@@ -865,11 +865,15 @@ QStringList MainWindow::showNewItemDialog(const QString &title, ...@@ -865,11 +865,15 @@ QStringList MainWindow::showNewItemDialog(const QString &title,
return wizard->runWizard(defaultDir, this); return wizard->runWizard(defaultDir, this);
} }
void MainWindow::showOptionsDialog(const QString &category, const QString &page) bool MainWindow::showOptionsDialog(const QString &category,
const QString &page,
QWidget *parent)
{ {
emit m_coreImpl->optionsDialogRequested(); emit m_coreImpl->optionsDialogRequested();
SettingsDialog dlg(this, category, page); if (!parent)
dlg.exec(); parent = this;
SettingsDialog dlg(parent, category, page);
return dlg.execDialog();
} }
void MainWindow::saveAll() void MainWindow::saveAll()
......
...@@ -132,7 +132,9 @@ public slots: ...@@ -132,7 +132,9 @@ public slots:
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()); const QString &defaultLocation = QString());
void showOptionsDialog(const QString &category = QString(), const QString &page = QString()); bool showOptionsDialog(const QString &category = QString(),
const QString &page = QString(),
QWidget *parent = 0);
protected: protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
......
...@@ -52,14 +52,19 @@ SettingsPage::SettingsPage() ...@@ -52,14 +52,19 @@ SettingsPage::SettingsPage()
} }
} }
QString SettingsPage::name() const QString SettingsPage::id() const
{ {