getting rid of MSVC incompatible hacking private members
This commit is contained in:
parent
2e7c6c6676
commit
6b2b4c3017
@ -6,19 +6,9 @@
|
|||||||
#include "QskTextInput.h"
|
#include "QskTextInput.h"
|
||||||
#include "QskQuick.h"
|
#include "QskQuick.h"
|
||||||
|
|
||||||
// VS2012+ disable keyword macroizing unless _ALLOW_KEYWORD_MACROS is set
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#if ( _MSC_VER >= 1700 ) && !defined( _ALLOW_KEYWORD_MACROS )
|
|
||||||
#define _ALLOW_KEYWORD_MACROS
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QSK_QT_PRIVATE_BEGIN
|
QSK_QT_PRIVATE_BEGIN
|
||||||
// we need to access QQuickTextInputPrivate::hasAcceptableInput
|
|
||||||
#define private public
|
|
||||||
#include <private/qquicktextinput_p.h>
|
#include <private/qquicktextinput_p.h>
|
||||||
#include <private/qquicktextinput_p_p.h>
|
#include <private/qquicktextinput_p_p.h>
|
||||||
#undef private
|
|
||||||
QSK_QT_PRIVATE_END
|
QSK_QT_PRIVATE_END
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskTextInput, Panel )
|
QSK_SUBCONTROL( QskTextInput, Panel )
|
||||||
@ -92,24 +82,67 @@ namespace
|
|||||||
|
|
||||||
bool fixup()
|
bool fixup()
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
return QQuickTextInputPrivate::get( this )->fixup();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasAcceptableInput() const
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
We can't call hasAcceptableInput with MSVC
|
we would like to call QQuickTextInputPrivate::hasAcceptableInput
|
||||||
and need to find our own code instead TODO ...
|
but unfortunately it is private, so we need to hack somthing
|
||||||
|
together
|
||||||
*/
|
*/
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
auto d = QQuickTextInputPrivate::get( this );
|
|
||||||
|
|
||||||
// QQuickTextInputPrivate::checkIsValid ???
|
auto that = const_cast< TextInput* >( this );
|
||||||
const auto state = static_cast< int >( d->hasAcceptableInput( d->m_text ) );
|
auto d = QQuickTextInputPrivate::get( that );
|
||||||
|
|
||||||
bool isAcceptable = ( state == QValidator::Acceptable );
|
if ( d->m_validator )
|
||||||
if ( !isAcceptable )
|
{
|
||||||
isAcceptable = d->fixup();
|
QString text = d->m_text;
|
||||||
|
int pos = d->m_cursor;
|
||||||
|
|
||||||
|
const auto state = d->m_validator->validate( text, pos );
|
||||||
|
if ( state != QValidator::Acceptable )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( d->m_maskData )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
We only want to do the check for the maskData here
|
||||||
|
and have to disable d->m_validator temporarily
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Validator final : public QValidator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
State validate(QString &, int &) const override
|
||||||
|
{
|
||||||
|
return QValidator::Acceptable;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto validator = d->m_validator;
|
||||||
|
|
||||||
|
const auto validInput = d->m_validInput;
|
||||||
|
const auto acceptableInput = d->m_acceptableInput;
|
||||||
|
|
||||||
|
d->m_acceptableInput = true;
|
||||||
|
|
||||||
|
static Validator noValidator;
|
||||||
|
that->setValidator( &noValidator ); // implicitly checking maskData
|
||||||
|
that->setValidator( d->m_validator );
|
||||||
|
|
||||||
|
const bool isAcceptable = d->m_acceptableInput;
|
||||||
|
|
||||||
|
// restoring old values
|
||||||
|
d->m_validInput = validInput;
|
||||||
|
d->m_acceptableInput = acceptableInput;
|
||||||
|
|
||||||
return isAcceptable;
|
return isAcceptable;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateColors();
|
void updateColors();
|
||||||
@ -298,7 +331,7 @@ void QskTextInput::keyPressEvent( QKeyEvent* event )
|
|||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
{
|
{
|
||||||
if ( fixup() )
|
if ( hasAcceptableInput() || fixup() )
|
||||||
{
|
{
|
||||||
QGuiApplication::inputMethod()->commit();
|
QGuiApplication::inputMethod()->commit();
|
||||||
|
|
||||||
@ -571,7 +604,7 @@ void QskTextInput::setEditing( bool on )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( fixup() )
|
if ( hasAcceptableInput() || fixup() )
|
||||||
Q_EMIT m_data->textInput->editingFinished();
|
Q_EMIT m_data->textInput->editingFinished();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -132,8 +132,8 @@ class QSK_EXPORT QskTextInput : public QskControl
|
|||||||
void setOverwriteMode( bool );
|
void setOverwriteMode( bool );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual bool hasAcceptableInput() const;
|
bool hasAcceptableInput() const;
|
||||||
virtual bool fixup();
|
bool fixup();
|
||||||
|
|
||||||
QVariant inputMethodQuery( Qt::InputMethodQuery ) const override;
|
QVariant inputMethodQuery( Qt::InputMethodQuery ) const override;
|
||||||
QVariant inputMethodQuery( Qt::InputMethodQuery, QVariant argument ) const;
|
QVariant inputMethodQuery( Qt::InputMethodQuery, QVariant argument ) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user