Commit da5963f0 authored by Joao Oliveira's avatar Joao Oliveira

Deleted unused QDebug, added check to see if text is valid on start and...

Deleted unused QDebug, added check to see if text is valid on start and changed m_formatted to be consistent
parent 4c2f0354
Pipeline #6976 canceled with stage
diff --git a/autotests/formattest.cpp b/autotests/formattest.cpp
index 2c0cd190d..f4bcb889e 100644
--- a/autotests/formattest.cpp
+++ b/autotests/formattest.cpp
@@ -31,18 +31,12 @@ private slots:
void testTimeFormat_data();
void testSpecialFormat();
void testSpecialFormat_data();
-<<<<<<< HEAD
void testFocusAction();
void testFocusAction_data();
void testValidateAction();
void testValidateAction_data();
-=======
void testNumberFormat();
-<<<<<<< HEAD
->>>>>>> Added unittests to test number Format
-=======
void testNumberFormat_data();
->>>>>>> Made the AFNumber_Format and AFSimple_Calculate to depend only on JavaScript
private:

Okular::Document *m_document;
@@ -148,7 +142,6 @@ void FormatTest::testSpecialFormat_data()
QTest::newRow( "field invalid SSN" ) << QStringLiteral( "CPF" ) << QStringLiteral( "1234567890" ) << false << QStringLiteral( "123-45-6789" );
}

-<<<<<<< HEAD
void FormatTest::testFocusAction()
{
QFETCH( QString, result );
@@ -185,7 +178,8 @@ void FormatTest::testValidateAction_data()

QTest::newRow( "valid text was set" ) << QStringLiteral( "123" ) << QStringLiteral( "valid" );
QTest::newRow( "invalid text was set" ) << QStringLiteral( "abc" ) << QStringLiteral( "invalid" );
-=======
+}
+
void FormatTest::testNumberFormat()
{
m_formattedText = QStringLiteral( "" );
@@ -211,11 +205,6 @@ void FormatTest::testNumberFormat_data()
QTest::addColumn< bool >( "edited" );
QTest::addColumn< QString > ( "result" );

-<<<<<<< HEAD
- QCOMPARE( ok, true );
- QCOMPARE( QStringLiteral( "1234,20 €" ), fft->text() );
->>>>>>> Added unittests to test number Format
-=======
// The tests which have invalid edited, keep the same value as when it was formatted before.
QTest::newRow( "EUR on left" ) << QStringLiteral( "number1" ) << QStringLiteral( "1.20" ) << true << QStringLiteral( "€ 1.20" );
QTest::newRow( "EUR on left with comma" ) << QStringLiteral( "number1" ) << QStringLiteral( "1234.20" ) << true << QStringLiteral( "€ 1,234.20" );
@@ -227,7 +216,6 @@ void FormatTest::testNumberFormat_data()
QTest::newRow( "invalid number with dot sep" ) << QStringLiteral( "number3" ) << QStringLiteral( "1234.20" ) << false << QStringLiteral( "" );
QTest::newRow( "EUR on right" ) << QStringLiteral( "number4" ) << QStringLiteral( "1,20" ) << true << QStringLiteral( "1,20 €" );
QTest::newRow( "EUR on right with dot sep without thousands sep" ) << QStringLiteral( "number4" ) << QStringLiteral( "1234,20" ) << true << QStringLiteral( "1234,20 €" );
->>>>>>> Made the AFNumber_Format and AFSimple_Calculate to depend only on JavaScript
}


diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp
index b34986f28..ccf13e80d 100644
--- a/ui/formwidgets.cpp
+++ b/ui/formwidgets.cpp
@@ -517,7 +517,6 @@ bool FormLineEdit::event( QEvent* e )
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast< QKeyEvent* >( e );
- qDebug() << (keyEvent->text());
if ( keyEvent == QKeySequence::Undo )
{
emit m_controller->requestUndo();
@@ -536,8 +535,9 @@ bool FormLineEdit::event( QEvent* e )
else if ( e->type() == QEvent::FocusIn )
{
const auto fft = static_cast< Okular::FormFieldText * > ( m_ff );
- setText( fft->text() );
- m_editing = m_formatted = true;
+ setText( m_lastText.isEmpty() ? fft->text() : m_lastText );
+ m_editing = true;
+ m_formatted = false;
if( const Okular::Action *action = m_ff->additionalAction( Okular::Annotation::FocusIn ) )
emit m_controller->focusAction( action, fft );
setFocus();
@@ -554,16 +554,20 @@ void FormLineEdit::processFormTextCommitActions()
{
m_editing = false;

+ const auto fft = static_cast< Okular::FormFieldText * > ( m_ff );
+
+ m_lastText = text();
+ fft->setText( text() );
if( const Okular::Action *action = m_ff->additionalAction( Okular::FormField::FieldModified ) )
{
bool ok = false;
- emit m_controller->keystrokeAction( action, static_cast< Okular::FormFieldText * > ( m_ff ), ok, true );
+ emit m_controller->keystrokeAction( action, fft, ok, true );
}

if( const Okular::Action *action = m_ff->additionalAction( Okular::Annotation::FocusOut ) )
{
bool ok = false;
- emit m_controller->validateAction( action, static_cast< Okular::FormFieldText * > ( m_ff ), ok );
+ emit m_controller->validateAction( action, fft, ok );
}

emit m_controller->recalculateForms();
@@ -571,7 +575,7 @@ void FormLineEdit::processFormTextCommitActions()
if ( const Okular::Action *action = m_ff->additionalAction( Okular::FormField::FormatField ) )
{
m_formatted = true;
- emit m_controller->formatAction( action, static_cast< Okular::FormFieldText * > ( m_ff ) );
+ emit m_controller->formatAction( action, fft );
}
}

diff --git a/ui/formwidgets.h b/ui/formwidgets.h
index 0d2dd27fa..347170143 100644
--- a/ui/formwidgets.h
+++ b/ui/formwidgets.h
@@ -264,6 +264,7 @@ class FormLineEdit : public QLineEdit, public FormWidgetIface
int m_prevAnchorPos;
bool m_editing;
bool m_formatted;
+ QString m_lastText;
DECLARE_ADDITIONAL_ACTIONS
};

......@@ -496,8 +496,7 @@ FormLineEdit::FormLineEdit( Okular::FormFieldText * text, QWidget * parent )
m_prevCursorPos = cursorPosition();
m_prevAnchorPos = cursorPosition();
m_editing = false;
m_formatted = true;
m_editing = m_formatted = false;
connect( this, &QLineEdit::textEdited, this, &FormLineEdit::slotChanged );
connect( this, &QLineEdit::cursorPositionChanged, this, &FormLineEdit::slotChanged );
......@@ -510,6 +509,25 @@ void FormLineEdit::setFormWidgetsController(FormWidgetsController* controller)
FormWidgetIface::setFormWidgetsController(controller);
connect( m_controller, &FormWidgetsController::formTextChangedByUndoRedo,
this, &FormLineEdit::slotHandleTextChangedByUndoRedo );
Okular::FormFieldText *fft = static_cast< Okular::FormFieldText * > ( m_ff );
m_lastText = fft->text();
if( const Okular::Action *action = m_ff->additionalAction( Okular::FormField::FieldModified ) )
{
bool ok = false;
emit m_controller->keystrokeAction( action, fft, ok );
if( !ok ){
fft->setText( text().replace( '.', ',' ) );
emit m_controller->keystrokeAction( action, fft, ok );
fft->setText( text() );
if( ok )
m_lastText = text().replace( '.', ',' );
}
}
setText( m_lastText );
processFormTextCommitActions();
}
bool FormLineEdit::event( QEvent* e )
......@@ -517,7 +535,6 @@ bool FormLineEdit::event( QEvent* e )
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast< QKeyEvent* >( e );
qDebug() << (keyEvent->text());
if ( keyEvent == QKeySequence::Undo )
{
emit m_controller->requestUndo();
......@@ -578,6 +595,7 @@ void FormLineEdit::processFormTextCommitActions()
{
m_formatted = true;
emit m_controller->formatAction( action, fft );
m_formatted = false;
}
}
......
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