Skip to content

ctkMenuComboBox: Add completerMenu()/setCompleterMenu() #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libs/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(TEST_SOURCES
ctkMenuComboBoxTest1.cpp
ctkMenuComboBoxTest2.cpp
ctkMenuComboBoxTest3.cpp
ctkMenuComboBoxTest4.cpp
ctkMessageBoxDontShowAgainTest.cpp
ctkModalityWidgetTest1.cpp
ctkPathLineEditTest1.cpp
Expand Down Expand Up @@ -334,6 +335,7 @@ SIMPLE_TEST( ctkMenuButtonTest1 )
SIMPLE_TEST( ctkMenuComboBoxTest1 )
SIMPLE_TEST( ctkMenuComboBoxTest2 )
SIMPLE_TEST( ctkMenuComboBoxTest3 )
SIMPLE_TEST( ctkMenuComboBoxTest4 )
SIMPLE_TEST( ctkMessageBoxDontShowAgainTest )
SIMPLE_TEST( ctkModalityWidgetTest1 )
SIMPLE_TEST( ctkPathLineEditTest1 )
Expand Down
42 changes: 14 additions & 28 deletions Libs/Widgets/Testing/Cpp/ctkMenuComboBoxTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QVBoxLayout>

// CTK includes
#include "ctkCoreTestingMacros.h"
#include "ctkMenuComboBox.h"

// STD includes
Expand All @@ -54,37 +55,22 @@ int ctkMenuComboBoxTest1(int argc, char * argv [] )
menuComboBox->setDefaultText("Search");
menuComboBox->setAutoFillBackground(true);
menuComboBox->setMinimumContentsLength(25);
if (menuComboBox->isSearchIconVisible() != true)
{
std::cerr << "Wrong default isSearchIconVisible: "
<< menuComboBox->isSearchIconVisible()
<< std::endl;
return EXIT_FAILURE;
}

// isSearchIconVisible
CHECK_BOOL(menuComboBox->isSearchIconVisible(), true); // Check default value

menuComboBox->setSearchIconVisible(true);
if (menuComboBox->isSearchIconVisible() != true)
{
std::cerr << "Failed to set searchIconVisible: "
<< menuComboBox->isSearchIconVisible()
<< std::endl;
return EXIT_FAILURE;
}
CHECK_BOOL(menuComboBox->isSearchIconVisible(), true);

menuComboBox->setSearchIconVisible(false);
if (menuComboBox->toolButtonStyle() != Qt::ToolButtonIconOnly)
{
std::cerr << "Wrong default toolButtonStyle: "
<< static_cast<unsigned int>(menuComboBox->toolButtonStyle())
<< std::endl;
return EXIT_FAILURE;
}
CHECK_BOOL(menuComboBox->isSearchIconVisible(), false);

// toolButtonStyle
CHECK_INT(menuComboBox->toolButtonStyle(), Qt::ToolButtonIconOnly); // Check default value

menuComboBox->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
if (menuComboBox->toolButtonStyle() != Qt::ToolButtonTextUnderIcon)
{
std::cerr << "Failed to set toolButtonStyle: "
<< static_cast<unsigned int>(menuComboBox->toolButtonStyle())
<< std::endl;
return EXIT_FAILURE;
}
CHECK_INT(menuComboBox->toolButtonStyle(), Qt::ToolButtonTextUnderIcon);

menuComboBox->setSearchIconVisible(true);
menuComboBox->setEditableBehavior(ctkMenuComboBox::EditableOnPopup);

Expand Down
87 changes: 41 additions & 46 deletions Libs/Widgets/Testing/Cpp/ctkMenuComboBoxTest2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QVBoxLayout>

// CTK includes
#include "ctkCoreTestingMacros.h"
#include "ctkMenuComboBox.h"

// STD includes
Expand All @@ -46,24 +47,16 @@ int ctkMenuComboBoxTest2(int argc, char * argv [] )

/// ------ Test setMenu ------
menu->setMenu(new QMenu(0));
if(!menu->menu()->isEmpty())
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::setMenu failed";
return EXIT_FAILURE;
}
CHECK_BOOL(menu->menu()->isEmpty(), true);

QMenu* file = new QMenu("File");
file->addAction("first");
menu->setMenu(file);
// File [Menu]
// |-- first [Action]
QList<QCompleter* > completer = menu->findChildren<QCompleter *>();
if(menu->menu()->isEmpty()
&& completer[0]->model()->rowCount() != 1)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::setMenu failed";
return EXIT_FAILURE;
}
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 1);

/// ------- Test delete Menu -----
//delete menu->menu();
Expand All @@ -76,53 +69,55 @@ int ctkMenuComboBoxTest2(int argc, char * argv [] )
QMenu* informatics = new QMenu("Informatics");
QAction* titi = informatics->addAction("titi");
file->addMenu(informatics);
if(menu->menu()->isEmpty()
&& completer[0]->model()->rowCount() != 2)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::addAction failed";
return EXIT_FAILURE;
}
// File [Menu]
// |-- first [Action]
// |
// |-- Informatics [Menu]
// |-- titi [Action]
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 2);

/// ------- Test removeAction -------
informatics->removeAction(titi);
if(completer[0]->model()->rowCount() != 1)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::removeAction failed";
return EXIT_FAILURE;
}
// File [Menu]
// |-- first [Action]
// |
// |-- Informatics [Menu]
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 1);

/// ------- Test add 2 same actions -> only 1 add on the completer --------
informatics->addAction(titi);
file->addAction(titi);
if (completer[0]->model()->rowCount() != 2)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::addAction failed";
return EXIT_FAILURE;
}
// File [Menu]
// |-- first [Action]
// |-- titi [Action]
// |
// |-- Informatics [Menu]
// |-- titi [Action]
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 2);

/// ------- Test remove one of the two --------
informatics->removeAction(titi);
//file->removeAction(first);
if (completer[0]->model()->rowCount() != 2)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::addAction failed"
<< completer[0]->model()->rowCount();
return EXIT_FAILURE;
}

// File [Menu]
// |-- first [Action]
// |-- titi [Action]
// |
// |-- Informatics [Menu]
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 2);

/// ------- Test remove the second one -------
file->removeAction(titi);
if (completer[0]->model()->rowCount() != 1)
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::addAction failed"
<< completer[0]->model()->rowCount();
return EXIT_FAILURE;
}
// File [Menu]
// |-- first [Action]
// |
// |-- Informatics [Menu]
CHECK_BOOL(menu->menu()->isEmpty(), false);
CHECK_INT(completer[0]->model()->rowCount(), 1);

menu->show();
if (argc < 2 || QString(argv[1]) != "-I" )
Expand Down
34 changes: 9 additions & 25 deletions Libs/Widgets/Testing/Cpp/ctkMenuComboBoxTest3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QTimer>

// CTK includes
#include "ctkCoreTestingMacros.h"
#include "ctkMenuComboBox.h"

// STD includes
Expand All @@ -38,37 +39,20 @@ int ctkMenuComboBoxTest3(int argc, char * argv [] )
QApplication app(argc, argv);

ctkMenuComboBox menu;
if (menu.menu())
{
qDebug() << "Line : " << __LINE__
<< " ctkMenuComboBox::ctkmenuComboBox failed"
<< menu.menu();
return EXIT_FAILURE;
}
CHECK_NULL(menu.menu());

menu.setEditableBehavior(ctkMenuComboBox::Editable);
QList<QComboBox* > comboBox = menu.findChildren<QComboBox *>();
if (!comboBox[0]->isEditable())
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::setEditableBehavior failed";
return EXIT_FAILURE;
}
CHECK_BOOL(comboBox[0]->isEditable(), true); // Check default value

menu.setEditableBehavior(ctkMenuComboBox::EditableOnFocus);
if (comboBox[0]->isEditable())
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::setEditableBehavior failed";
return EXIT_FAILURE;
}
CHECK_BOOL(comboBox[0]->isEditable(), false);

menu.setEditableBehavior(ctkMenuComboBox::Editable);
CHECK_BOOL(comboBox[0]->isEditable(), true);

menu.setEditableBehavior(ctkMenuComboBox::NotEditable);
if (comboBox[0]->isEditable())
{
qDebug() << "Line : " << __LINE__
<< "ctkMenuComboBox::setEditableBehavior failed";
return EXIT_FAILURE;
}
CHECK_BOOL(comboBox[0]->isEditable(), false);

menu.show();
if (argc < 2 || QString(argv[1]) != "-I" )
Expand Down
118 changes: 118 additions & 0 deletions Libs/Widgets/Testing/Cpp/ctkMenuComboBoxTest4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*=========================================================================

Library: CTK

Copyright (c) Kitware Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=========================================================================*/

// Qt includes
#include <QApplication>
#include <QComboBox>
#include <QCompleter>
#include <QDebug>
#include <QIcon>
#include <QLineEdit>
#include <QListWidget>
#include <QMenu>
#include <QTimer>
#include <QToolBar>
#include <QVBoxLayout>

// CTK includes
#include "ctkCoreTestingMacros.h"
#include "ctkMenuComboBox.h"

// STD includes
#include <iostream>

//-----------------------------------------------------------------------------
int ctkMenuComboBoxTest4(int argc, char * argv [] )
{
QApplication app(argc, argv);

// File [Menu]
// |-- file 1 [Action]
// |-- file 2 [Action]
// |
// |-- Informatics [Menu]
// |-- info 1 [Action]
// |-- info 2 [Action]
QMenu* file = new QMenu("File");
QAction* file_file_1 = file->addAction("file 1");
QAction* file_file_2 = file->addAction("file 2");
QMenu* informatics = new QMenu("Informatics");
QAction* file_informatics_info_1 = informatics->addAction("info 1");
QAction* file_informatics_info_2 = informatics->addAction("info 2");
file->addMenu(informatics);

// Completer [Menu]
// |-- file 1 [Action]
// |-- file 2 [Action]
// |-- info 1 [Action]
// |-- info 2 [Action]
// |-- completer 1 [Action]
// |-- completer 2 [Action]
QMenu* completerMenu = new QMenu("Completer");
completerMenu->addAction(file_file_1);
completerMenu->addAction(file_file_2);
completerMenu->addAction(file_informatics_info_1);
completerMenu->addAction(file_informatics_info_2);
/*QAction* completer_1 = */completerMenu->addAction("completer 1");
/*QAction* completer_2 = */completerMenu->addAction("completer 2");

ctkMenuComboBox* menu = new ctkMenuComboBox();

/// ------ Test setMenu ------
menu->setMenu(file);
CHECK_POINTER(menu->menu(), file);
CHECK_POINTER(menu->completerMenu(), file);
CHECK_BOOL(menu->menu()->isEmpty(), false);
QList<QCompleter* > completer = menu->findChildren<QCompleter *>();
CHECK_INT(completer[0]->model()->rowCount(), 4);

/// ------ Test setMenu(0) ------
menu->setMenu(0);
CHECK_POINTER(menu->menu(), 0);
CHECK_POINTER(menu->completerMenu(), 0);
CHECK_INT(completer[0]->model()->rowCount(), 0);

/// ------ Test setCompleterMenu ------
menu->setMenu(file);
menu->setCompleterMenu(completerMenu);
CHECK_POINTER(menu->menu(), file);
CHECK_POINTER(menu->completerMenu(), completerMenu);
CHECK_INT(completer[0]->model()->rowCount(), 6);

/// ------ Test removeAction ------
file->removeAction(file_file_2);
informatics->removeAction(file_informatics_info_1);
CHECK_INT(completer[0]->model()->rowCount(), 6); // Completer should still include all actions

/// ------ Test setCompleterMenu ------
menu->setCompleterMenu(file);
CHECK_POINTER(menu->menu(), file);
CHECK_POINTER(menu->completerMenu(), file);
CHECK_INT(completer[0]->model()->rowCount(), 2);

menu->show();
if (argc < 2 || QString(argv[1]) != "-I" )
{
QTimer::singleShot(200, &app, SLOT(quit()));
}

return app.exec();
}

Loading