|
21 | 21 | #include <QComboBox>
|
22 | 22 | #include <QStackedWidget>
|
23 | 23 | #include <QToolButton>
|
| 24 | +#include <QLineEdit> |
| 25 | +#include <QPlainTextEdit> |
24 | 26 |
|
25 | 27 | #include "qgstest.h"
|
26 | 28 | #include "qgsgui.h"
|
@@ -138,6 +140,7 @@ class TestProcessingGui : public QObject
|
138 | 140 | void testWrapperDynamic();
|
139 | 141 | void testModelerWrapper();
|
140 | 142 | void testBooleanWrapper();
|
| 143 | + void testStringWrapper(); |
141 | 144 | };
|
142 | 145 |
|
143 | 146 | void TestProcessingGui::initTestCase()
|
@@ -561,5 +564,178 @@ void TestProcessingGui::testBooleanWrapper()
|
561 | 564 | delete l;
|
562 | 565 | }
|
563 | 566 |
|
| 567 | +void TestProcessingGui::testStringWrapper() |
| 568 | +{ |
| 569 | + QgsProcessingParameterString param( QStringLiteral( "string" ), QStringLiteral( "string" ) ); |
| 570 | + |
| 571 | + // standard wrapper |
| 572 | + QgsProcessingStringWidgetWrapper wrapper( ¶m ); |
| 573 | + |
| 574 | + QgsProcessingContext context; |
| 575 | + QWidget *w = wrapper.createWrappedWidget( context ); |
| 576 | + |
| 577 | + QSignalSpy spy( &wrapper, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 578 | + wrapper.setWidgetValue( QStringLiteral( "a" ), context ); |
| 579 | + QCOMPARE( spy.count(), 1 ); |
| 580 | + QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 581 | + QCOMPARE( static_cast< QLineEdit * >( wrapper.wrappedWidget() )->text(), QStringLiteral( "a" ) ); |
| 582 | + wrapper.setWidgetValue( QString(), context ); |
| 583 | + QCOMPARE( spy.count(), 2 ); |
| 584 | + QVERIFY( wrapper.widgetValue().toString().isEmpty() ); |
| 585 | + QVERIFY( static_cast< QLineEdit * >( wrapper.wrappedWidget() )->text().isEmpty() ); |
| 586 | + |
| 587 | + QLabel *l = wrapper.createWrappedLabel(); |
| 588 | + QVERIFY( l ); |
| 589 | + QCOMPARE( l->text(), QStringLiteral( "string" ) ); |
| 590 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 591 | + delete l; |
| 592 | + |
| 593 | + // check signal |
| 594 | + static_cast< QLineEdit * >( wrapper.wrappedWidget() )->setText( QStringLiteral( "b" ) ); |
| 595 | + QCOMPARE( spy.count(), 3 ); |
| 596 | + static_cast< QLineEdit * >( wrapper.wrappedWidget() )->clear(); |
| 597 | + QCOMPARE( spy.count(), 4 ); |
| 598 | + |
| 599 | + delete w; |
| 600 | + |
| 601 | + // batch wrapper |
| 602 | + QgsProcessingStringWidgetWrapper wrapperB( ¶m, QgsProcessingGui::Batch ); |
| 603 | + |
| 604 | + w = wrapperB.createWrappedWidget( context ); |
| 605 | + QSignalSpy spy2( &wrapperB, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 606 | + wrapperB.setWidgetValue( QStringLiteral( "a" ), context ); |
| 607 | + QCOMPARE( spy2.count(), 1 ); |
| 608 | + QCOMPARE( wrapperB.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 609 | + QCOMPARE( static_cast< QLineEdit * >( wrapperB.wrappedWidget() )->text(), QStringLiteral( "a" ) ); |
| 610 | + wrapperB.setWidgetValue( QString(), context ); |
| 611 | + QCOMPARE( spy2.count(), 2 ); |
| 612 | + QVERIFY( wrapperB.widgetValue().toString().isEmpty() ); |
| 613 | + QVERIFY( static_cast< QLineEdit * >( wrapperB.wrappedWidget() )->text().isEmpty() ); |
| 614 | + |
| 615 | + // check signal |
| 616 | + static_cast< QLineEdit * >( w )->setText( QStringLiteral( "x" ) ); |
| 617 | + QCOMPARE( spy2.count(), 3 ); |
| 618 | + static_cast< QLineEdit * >( w )->clear(); |
| 619 | + QCOMPARE( spy2.count(), 4 ); |
| 620 | + |
| 621 | + // should be no label in batch mode |
| 622 | + QVERIFY( !wrapperB.createWrappedLabel() ); |
| 623 | + delete w; |
| 624 | + |
| 625 | + // modeler wrapper |
| 626 | + QgsProcessingStringWidgetWrapper wrapperM( ¶m, QgsProcessingGui::Modeler ); |
| 627 | + |
| 628 | + w = wrapperM.createWrappedWidget( context ); |
| 629 | + QSignalSpy spy3( &wrapperM, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 630 | + wrapperM.setWidgetValue( QStringLiteral( "a" ), context ); |
| 631 | + QCOMPARE( wrapperM.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 632 | + QCOMPARE( spy3.count(), 1 ); |
| 633 | + QCOMPARE( static_cast< QLineEdit * >( wrapperM.wrappedWidget() )->text(), QStringLiteral( "a" ) ); |
| 634 | + wrapperM.setWidgetValue( QString(), context ); |
| 635 | + QVERIFY( wrapperM.widgetValue().toString().isEmpty() ); |
| 636 | + QCOMPARE( spy3.count(), 2 ); |
| 637 | + QVERIFY( static_cast< QLineEdit * >( wrapperM.wrappedWidget() )->text().isEmpty() ); |
| 638 | + |
| 639 | + // check signal |
| 640 | + static_cast< QLineEdit * >( w )->setText( QStringLiteral( "x" ) ); |
| 641 | + QCOMPARE( spy3.count(), 3 ); |
| 642 | + static_cast< QLineEdit * >( w )->clear(); |
| 643 | + QCOMPARE( spy3.count(), 4 ); |
| 644 | + |
| 645 | + // should be a label in modeler mode |
| 646 | + l = wrapperM.createWrappedLabel(); |
| 647 | + QVERIFY( l ); |
| 648 | + QCOMPARE( l->text(), QStringLiteral( "string" ) ); |
| 649 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 650 | + delete w; |
| 651 | + delete l; |
| 652 | + |
| 653 | + // |
| 654 | + // multiline parameter |
| 655 | + // |
| 656 | + param = QgsProcessingParameterString( QStringLiteral( "string" ), QStringLiteral( "string" ), QVariant(), true ); |
| 657 | + |
| 658 | + // standard wrapper |
| 659 | + QgsProcessingStringWidgetWrapper wrapperMultiLine( ¶m ); |
| 660 | + |
| 661 | + w = wrapperMultiLine.createWrappedWidget( context ); |
| 662 | + |
| 663 | + QSignalSpy spy4( &wrapperMultiLine, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 664 | + wrapperMultiLine.setWidgetValue( QStringLiteral( "a" ), context ); |
| 665 | + QCOMPARE( spy4.count(), 1 ); |
| 666 | + QCOMPARE( wrapperMultiLine.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 667 | + QCOMPARE( static_cast< QPlainTextEdit * >( wrapperMultiLine.wrappedWidget() )->toPlainText(), QStringLiteral( "a" ) ); |
| 668 | + wrapperMultiLine.setWidgetValue( QString(), context ); |
| 669 | + QCOMPARE( spy4.count(), 2 ); |
| 670 | + QVERIFY( wrapperMultiLine.widgetValue().toString().isEmpty() ); |
| 671 | + QVERIFY( static_cast< QPlainTextEdit * >( wrapperMultiLine.wrappedWidget() )->toPlainText().isEmpty() ); |
| 672 | + |
| 673 | + l = wrapper.createWrappedLabel(); |
| 674 | + QVERIFY( l ); |
| 675 | + QCOMPARE( l->text(), QStringLiteral( "string" ) ); |
| 676 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 677 | + delete l; |
| 678 | + |
| 679 | + // check signal |
| 680 | + static_cast< QPlainTextEdit * >( wrapperMultiLine.wrappedWidget() )->setPlainText( QStringLiteral( "b" ) ); |
| 681 | + QCOMPARE( spy4.count(), 3 ); |
| 682 | + static_cast< QPlainTextEdit * >( wrapperMultiLine.wrappedWidget() )->clear(); |
| 683 | + QCOMPARE( spy4.count(), 4 ); |
| 684 | + |
| 685 | + delete w; |
| 686 | + |
| 687 | + // batch wrapper - should still be a line edit |
| 688 | + QgsProcessingStringWidgetWrapper wrapperMultiLineB( ¶m, QgsProcessingGui::Batch ); |
| 689 | + |
| 690 | + w = wrapperMultiLineB.createWrappedWidget( context ); |
| 691 | + QSignalSpy spy5( &wrapperMultiLineB, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 692 | + wrapperMultiLineB.setWidgetValue( QStringLiteral( "a" ), context ); |
| 693 | + QCOMPARE( spy5.count(), 1 ); |
| 694 | + QCOMPARE( wrapperMultiLineB.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 695 | + QCOMPARE( static_cast< QLineEdit * >( wrapperMultiLineB.wrappedWidget() )->text(), QStringLiteral( "a" ) ); |
| 696 | + wrapperMultiLineB.setWidgetValue( QString(), context ); |
| 697 | + QCOMPARE( spy5.count(), 2 ); |
| 698 | + QVERIFY( wrapperMultiLineB.widgetValue().toString().isEmpty() ); |
| 699 | + QVERIFY( static_cast< QLineEdit * >( wrapperMultiLineB.wrappedWidget() )->text().isEmpty() ); |
| 700 | + |
| 701 | + // check signal |
| 702 | + static_cast< QLineEdit * >( w )->setText( QStringLiteral( "x" ) ); |
| 703 | + QCOMPARE( spy5.count(), 3 ); |
| 704 | + static_cast< QLineEdit * >( w )->clear(); |
| 705 | + QCOMPARE( spy5.count(), 4 ); |
| 706 | + |
| 707 | + // should be no label in batch mode |
| 708 | + QVERIFY( !wrapperB.createWrappedLabel() ); |
| 709 | + delete w; |
| 710 | + |
| 711 | + // modeler wrapper |
| 712 | + QgsProcessingStringWidgetWrapper wrapperMultiLineM( ¶m, QgsProcessingGui::Modeler ); |
| 713 | + |
| 714 | + w = wrapperMultiLineM.createWrappedWidget( context ); |
| 715 | + QSignalSpy spy6( &wrapperMultiLineM, &QgsProcessingStringWidgetWrapper::widgetValueHasChanged ); |
| 716 | + wrapperMultiLineM.setWidgetValue( QStringLiteral( "a" ), context ); |
| 717 | + QCOMPARE( wrapperMultiLineM.widgetValue().toString(), QStringLiteral( "a" ) ); |
| 718 | + QCOMPARE( spy6.count(), 1 ); |
| 719 | + QCOMPARE( static_cast< QPlainTextEdit * >( wrapperMultiLineM.wrappedWidget() )->toPlainText(), QStringLiteral( "a" ) ); |
| 720 | + wrapperMultiLineM.setWidgetValue( QString(), context ); |
| 721 | + QVERIFY( wrapperMultiLineM.widgetValue().toString().isEmpty() ); |
| 722 | + QCOMPARE( spy6.count(), 2 ); |
| 723 | + QVERIFY( static_cast< QPlainTextEdit * >( wrapperMultiLineM.wrappedWidget() )->toPlainText().isEmpty() ); |
| 724 | + |
| 725 | + // check signal |
| 726 | + static_cast< QPlainTextEdit * >( w )->setPlainText( QStringLiteral( "x" ) ); |
| 727 | + QCOMPARE( spy6.count(), 3 ); |
| 728 | + static_cast< QPlainTextEdit * >( w )->clear(); |
| 729 | + QCOMPARE( spy6.count(), 4 ); |
| 730 | + |
| 731 | + // should be a label in modeler mode |
| 732 | + l = wrapperMultiLineM.createWrappedLabel(); |
| 733 | + QVERIFY( l ); |
| 734 | + QCOMPARE( l->text(), QStringLiteral( "string" ) ); |
| 735 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 736 | + delete w; |
| 737 | + delete l; |
| 738 | +} |
| 739 | + |
564 | 740 | QGSTEST_MAIN( TestProcessingGui )
|
565 | 741 | #include "testprocessinggui.moc"
|
0 commit comments