summaryrefslogtreecommitdiff
path: root/src/libs/utils/filenamevalidatinglineedit.cpp
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@nokia.com>2011-09-20 12:54:18 +0200
committerAlessandro Portale <alessandro.portale@nokia.com>2011-09-20 13:29:31 +0200
commitdfbdf287034fca3cc9c59c546d06fda2af3e67ba (patch)
tree1119541029f435331ab3328f052e6f2f4bf6901e /src/libs/utils/filenamevalidatinglineedit.cpp
parent71cbd765b2f887a68495b947e202ee4ca4295fd8 (diff)
downloadqt-creator-dfbdf287034fca3cc9c59c546d06fda2af3e67ba.tar.gz
Add extension property to FileNameValidatingLineEdit
Does nothing if extension is empty. The extension check is case sensitive. Change-Id: I58f89eb57d53146dae95e58d77cd8b47826b8f42 Reviewed-on: http://codereview.qt-project.org/5163 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
Diffstat (limited to 'src/libs/utils/filenamevalidatinglineedit.cpp')
-rw-r--r--src/libs/utils/filenamevalidatinglineedit.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/libs/utils/filenamevalidatinglineedit.cpp b/src/libs/utils/filenamevalidatinglineedit.cpp
index 9a428eaf0e..a3e83a0594 100644
--- a/src/libs/utils/filenamevalidatinglineedit.cpp
+++ b/src/libs/utils/filenamevalidatinglineedit.cpp
@@ -68,8 +68,7 @@ static const QRegExp &windowsDeviceSubDirPattern()
// ----------- FileNameValidatingLineEdit
FileNameValidatingLineEdit::FileNameValidatingLineEdit(QWidget *parent) :
BaseValidatingLineEdit(parent),
- m_allowDirectories(false),
- m_unused(0)
+ m_allowDirectories(false)
{
}
@@ -143,7 +142,46 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
bool FileNameValidatingLineEdit::validate(const QString &value, QString *errorMessage) const
{
- return validateFileName(value, m_allowDirectories, errorMessage);
+ return validateFileNameExtension(value, requiredExtensions(), errorMessage)
+ && validateFileName(value, allowDirectories(), errorMessage);
+}
+
+
+bool FileNameValidatingLineEdit::validateFileNameExtension(const QString &fileName,
+ const QStringList &requiredExtensions,
+ QString *errorMessage)
+{
+ // file extension
+ if (!requiredExtensions.isEmpty()) {
+ foreach (const QString &requiredExtension, requiredExtensions) {
+ QString extension = QLatin1String(".") + requiredExtension;
+ if (fileName.endsWith(extension, Qt::CaseSensitive) && extension.count() < fileName.count()) {
+ return true;
+ }
+ }
+
+ if (errorMessage) {
+ if (requiredExtensions.count() == 1) {
+ *errorMessage = tr("File extension %1 is required:").arg(requiredExtensions.first());
+ } else {
+ *errorMessage = tr("File extensions %1 are required:").arg(requiredExtensions.join(", "));
+ }
+ }
+
+ return false;
+ }
+
+ return true;
+}
+
+QStringList FileNameValidatingLineEdit::requiredExtensions() const
+{
+ return m_requiredExtensionList;
+}
+
+void FileNameValidatingLineEdit::setRequiredExtensions(const QStringList &extensions)
+{
+ m_requiredExtensionList = extensions;
}
} // namespace Utils