Commit 5f139b49 authored by mae's avatar mae
Browse files

Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

parents 71fe3435 2246be65
......@@ -150,5 +150,10 @@ void BaseValidatingLineEdit::slotReturnPressed()
emit validReturnPressed();
}
void BaseValidatingLineEdit::triggerChanged()
{
slotChanged(text());
}
} // namespace Utils
} // namespace Core
......@@ -72,6 +72,9 @@ public:
QColor errorColor() const;
void setErrorColor(const QColor &);
// Trigger an update (after changing settings)
void triggerChanged();
static QColor textColor(const QWidget *w);
static void setTextColor(QWidget *w, const QColor &c);
......
......@@ -43,13 +43,15 @@ struct ClassNameValidatingLineEditPrivate {
const QRegExp m_nameRegexp;
const QString m_namespaceDelimiter;
bool m_namespacesEnabled;
bool m_lowerCaseFileName;
};
// Match something like "Namespace1::Namespace2::ClassName".
ClassNameValidatingLineEditPrivate:: ClassNameValidatingLineEditPrivate() :
m_nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*")),
m_namespaceDelimiter(QLatin1String("::")),
m_namespacesEnabled(false)
m_namespacesEnabled(false),
m_lowerCaseFileName(true)
{
QTC_ASSERT(m_nameRegexp.isValid(), return);
}
......@@ -96,7 +98,7 @@ void ClassNameValidatingLineEdit::slotChanged(const QString &t)
Core::Utils::BaseValidatingLineEdit::slotChanged(t);
if (isValid()) {
// Suggest file names, strip namespaces
QString fileName = t.toLower();
QString fileName = m_d->m_lowerCaseFileName ? t.toLower() : t;
if (m_d->m_namespacesEnabled) {
const int namespaceIndex = fileName.lastIndexOf(m_d->m_namespaceDelimiter);
if (namespaceIndex != -1)
......@@ -132,5 +134,15 @@ QString ClassNameValidatingLineEdit::createClassName(const QString &name)
return className;
}
bool ClassNameValidatingLineEdit::lowerCaseFileName() const
{
return m_d->m_lowerCaseFileName;
}
void ClassNameValidatingLineEdit::setLowerCaseFileName(bool v)
{
m_d->m_lowerCaseFileName = v;
}
} // namespace Utils
} // namespace Core
......@@ -46,6 +46,7 @@ class QWORKBENCH_UTILS_EXPORT ClassNameValidatingLineEdit
{
Q_DISABLE_COPY(ClassNameValidatingLineEdit)
Q_PROPERTY(bool namespacesEnabled READ namespacesEnabled WRITE setNamespacesEnabled DESIGNABLE true)
Q_PROPERTY(bool lowerCaseFileName READ lowerCaseFileName WRITE setLowerCaseFileName)
Q_OBJECT
public:
......@@ -55,6 +56,9 @@ public:
bool namespacesEnabled() const;
void setNamespacesEnabled(bool b);
bool lowerCaseFileName() const;
void setLowerCaseFileName(bool v);
// Clean an input string to get a valid class name.
static QString createClassName(const QString &name);
......
......@@ -84,7 +84,7 @@ NewClassWidget::NewClassWidget(QWidget *parent) :
m_d->m_ui.baseClassComboBox->setEditable(false);
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)),
this, SLOT(classNameEdited()));
connect(m_d->m_ui.baseClassComboBox, SIGNAL(currentIndexChanged(int)),
......@@ -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()
{
const bool newValid = isValid();
......@@ -415,7 +425,12 @@ bool NewClassWidget::isValid(QString *error) const
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)
qDebug() << Q_FUNC_INFO << baseName << m_d->m_headerExtension << m_d->m_sourceExtension;
......
......@@ -70,6 +70,7 @@ class QWORKBENCH_UTILS_EXPORT NewClassWidget : public QWidget
Q_PROPERTY(bool formInputCheckable READ formInputCheckable WRITE setFormInputCheckable DESIGNABLE true)
Q_PROPERTY(bool formInputChecked READ formInputChecked WRITE setFormInputChecked DESIGNABLE true)
Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories)
Q_PROPERTY(bool lowerCaseFiles READ lowerCaseFiles WRITE setLowerCaseFiles)
// Utility "USER" property for wizards containing file names.
Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true)
public:
......@@ -95,6 +96,7 @@ public:
QString headerExtension() const;
QString formExtension() const;
bool allowDirectories() const;
bool lowerCaseFiles() const;
bool isValid(QString *error = 0) const;
......@@ -123,19 +125,25 @@ public slots:
void setHeaderExtension(const QString &e);
void setFormExtension(const QString &e);
void setAllowDirectories(bool v);
void setLowerCaseFiles(bool v);
/* Suggest a class name from the base class by stripping the leading 'Q'
* character. This will happen automagically if the base class combo
* changes until the class line edited is manually edited. */
void suggestClassNameFromBase();
public slots:
// Trigger an update (after changing settings)
void triggerUpdateFileNames();
private slots:
void updateFileNames(const QString &t);
void slotUpdateFileNames(const QString &t);
void slotValidChanged();
void slotActivated();
void classNameEdited();
void slotFormInputChecked();
private:
void setFormInputCheckable(bool checkable, bool force);
......
......@@ -234,15 +234,19 @@ QString CMakeSettingsPage::findCmakeExecutable() const
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
{
return "CMake";
return QLatin1String("CMake");
}
QString CMakeSettingsPage::trCategory() const
......
......@@ -92,7 +92,8 @@ class CMakeSettingsPage : public Core::IOptionsPage
public:
CMakeSettingsPage();
virtual ~CMakeSettingsPage();
virtual QString name() const;
virtual QString id() const;
virtual QString trName() const;
virtual QString category() const;
virtual QString trCategory() const;
......
......@@ -39,7 +39,11 @@ using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title)
: ProjectExplorer::ApplicationRunConfiguration(pro), m_runMode(Gui), m_target(target), m_workingDirectory(workingDirectory), m_title(title)
: ProjectExplorer::ApplicationRunConfiguration(pro)
, m_runMode(Gui)
, m_target(target)
, m_workingDirectory(workingDirectory)
, m_title(title)
{
setName(title);
}
......
......@@ -64,9 +64,9 @@ QStringList CoreImpl::showNewItemDialog(const QString &title,
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
......
......@@ -47,8 +47,9 @@ public:
QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString());
void showOptionsDialog(const QString &group = QString(),
const QString &page = QString());
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
ActionManager *actionManager() const;
FileManager *fileManager() const ;
......
......@@ -38,6 +38,21 @@
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
{
Q_OBJECT
......@@ -45,7 +60,8 @@ public:
IOptionsPage(QObject *parent = 0) : QObject(parent) {}
virtual ~IOptionsPage() {}
virtual QString name() const = 0;
virtual QString id() const = 0;
virtual QString trName() const = 0;
virtual QString category() const = 0;
virtual QString trCategory() const = 0;
......
......@@ -39,7 +39,7 @@ using namespace Core::Internal;
SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
const QString &initialPage)
: QDialog(parent)
: QDialog(parent), m_applied(false)
{
setupUi(this);
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
......@@ -60,7 +60,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
int index = 0;
foreach (IOptionsPage *page, pages) {
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, page->name());
item->setText(0, page->trName());
item->setData(0, Qt::UserRole, index);
QStringList categoriesId = page->category().split(QLatin1Char('|'));
......@@ -94,7 +94,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
m_pages.append(page);
stackedPages->addWidget(page->createPage(stackedPages));
if (page->name() == initialPage && currentCategory == initialCategory) {
if (page->id() == initialPage && currentCategory == initialCategory) {
stackedPages->setCurrentIndex(stackedPages->count());
pageTree->setCurrentItem(item);
}
......@@ -123,6 +123,7 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *)
void SettingsDialog::accept()
{
m_applied = true;
foreach (IOptionsPage *page, m_pages) {
page->apply();
page->finish();
......@@ -141,4 +142,12 @@ void SettingsDialog::apply()
{
foreach (IOptionsPage *page, m_pages)
page->apply();
m_applied = true;
}
bool SettingsDialog::execDialog()
{
m_applied = false;
exec();
return m_applied;
}
......@@ -49,6 +49,10 @@ public:
const QString &initialPage = QString());
~SettingsDialog();
// Run the dialog and return true if 'Ok' was choosen or 'Apply' was invoked
// at least once
bool execDialog();
private slots:
void pageSelected(QTreeWidgetItem *cat);
void accept();
......@@ -57,6 +61,7 @@ private slots:
private:
QList<Core::IOptionsPage*> m_pages;
bool m_applied;
};
} // namespace Internal
......
......@@ -59,7 +59,13 @@ ShortcutSettings::~ShortcutSettings()
}
// IOptionsPage
QString ShortcutSettings::name() const
QString ShortcutSettings::id() const
{
return QLatin1String("Keyboard");
}
QString ShortcutSettings::trName() const
{
return tr("Keyboard");
}
......
......@@ -67,7 +67,8 @@ public:
~ShortcutSettings();
// IOptionsPage
QString name() const;
QString id() const;
QString trName() const;
QString category() const;
QString trCategory() const;
......
......@@ -43,7 +43,12 @@ GeneralSettings::GeneralSettings():
{
}
QString GeneralSettings::name() const
QString GeneralSettings::id() const
{
return QLatin1String("General");
}
QString GeneralSettings::trName() const
{
return tr("General");
}
......
......@@ -47,7 +47,8 @@ class GeneralSettings : public IOptionsPage
public:
GeneralSettings();
QString name() const;
QString id() const;
QString trName() const;
QString category() const;
QString trCategory() const;
QWidget* createPage(QWidget *parent);
......
......@@ -70,8 +70,9 @@ public:
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()) = 0;
virtual void showOptionsDialog(const QString &group = QString(),
const QString &page = QString()) = 0;
virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0) = 0;
virtual ActionManager *actionManager() const = 0;
virtual FileManager *fileManager() const = 0;
......
......@@ -865,11 +865,15 @@ QStringList MainWindow::showNewItemDialog(const QString &title,
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();
SettingsDialog dlg(this, category, page);
dlg.exec();
if (!parent)
parent = this;
SettingsDialog dlg(parent, category, page);
return dlg.execDialog();
}
void MainWindow::saveAll()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment