Commit 2652d1bc authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: update QUrlValidator (fix #9932)

somehow #3435
parent d470a924
...@@ -24,12 +24,27 @@ ...@@ -24,12 +24,27 @@
#include "validators.hpp" #include "validators.hpp"
#include <QUrl>
QValidator::State UrlValidator::validate( QString& str, int& ) const QValidator::State UrlValidator::validate( QString& str, int& ) const
{ {
str = str.trimmed(); if( str.startsWith( ' ' ) )
if( str.contains( ' ' ) )
return QValidator::Invalid; return QValidator::Invalid;
if( !str.contains( "://" ) )
if ( str.isEmpty() )
return QValidator::Intermediate;
QUrl url( str );
if ( url.scheme().isEmpty() )
return QValidator::Intermediate; return QValidator::Intermediate;
return QValidator::Acceptable;
return ( url.isValid() ) ? QValidator::Acceptable : QValidator::Intermediate;
}
void UrlValidator::fixup( QString & input ) const
{
while( input.startsWith( ' ' ) )
input.chop( 1 );
QUrl fixed( input, QUrl::TolerantMode );
input = fixed.toString();
} }
...@@ -29,6 +29,7 @@ class UrlValidator : public QValidator ...@@ -29,6 +29,7 @@ class UrlValidator : public QValidator
public: public:
UrlValidator( QObject *parent ) : QValidator( parent ) { } UrlValidator( QObject *parent ) : QValidator( parent ) { }
virtual QValidator::State validate( QString&, int& ) const; virtual QValidator::State validate( QString&, int& ) const;
virtual void fixup ( QString & input ) const;
}; };
#endif // VALIDATORS_HPP #endif // VALIDATORS_HPP
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