| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 | 
							- /*=========================================================================
 
-   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.commontk.org/LICENSE
 
-   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 <QHBoxLayout>
 
- #include <QMouseEvent>
 
- #include <QTimer>
 
- // CTK includes
 
- #include "ctkMatrixWidget.h"
 
- // STD includes
 
- #include <iostream>
 
- //-----------------------------------------------------------------------------
 
- int ctkMatrixWidgetTest2(int argc, char * argv [] )
 
- {
 
-   QApplication app(argc, argv);
 
-   QWidget topLevel;
 
-   QHBoxLayout* layout = new QHBoxLayout(&topLevel);
 
-   ctkMatrixWidget matrixWidget;
 
-   // 4x4 by default, if not anymore, change the documentation
 
-   if (matrixWidget.rowCount() != 4 ||
 
-       matrixWidget.columnCount() != 4)
 
-     {
 
-     std::cerr << "Default constructor doesn't create a 4x4 matrix" << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   for (int i = 0; i != 4; ++i)
 
-     {
 
-     for (int j = 0; j != 4; ++j)
 
-       {
 
-       if ((i == j && matrixWidget.value(i,j) != 1.) ||
 
-           (i != j && matrixWidget.value(i,j) != 0.))
 
-         {
 
-         std::cerr << "Not an identity matrix: (" << i << "," << j << ") = "
 
-                   << matrixWidget.value(i,j) << std::endl;
 
-         return EXIT_FAILURE;
 
-         }
 
-       }
 
-     }
 
-   matrixWidget.setValue(2,3, 15.352);
 
-   if (matrixWidget.value(2,3) != 15.352)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setValue() failed: "
 
-               << matrixWidget.value(2,3) << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   // resize the matrix:
 
-   matrixWidget.setRowCount(8);
 
-   if (matrixWidget.rowCount() != 8 ||
 
-       matrixWidget.columnCount() != 4)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setRowCount() failed "
 
-               << matrixWidget.rowCount() << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setColumnCount(6);
 
-   if (matrixWidget.rowCount() != 8 ||
 
-       matrixWidget.columnCount() != 6)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setColumnCount() failed: "
 
-               << matrixWidget.columnCount() << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setEditable(false);
 
-   if (matrixWidget.isEditable())
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setEditable() failed" << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setMinimum(0.5);
 
-   if (matrixWidget.minimum() != 0.5 ||
 
-       matrixWidget.value(1,0) != 0.5 )
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setMinimum() failed:"
 
-               << matrixWidget.value(1,0) << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setMaximum(0.7);
 
-   if (matrixWidget.maximum() != 0.7 ||
 
-       matrixWidget.value(1,1) != 0.7 )
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setMaximum() failed:"
 
-               << matrixWidget.value(1,1) << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setMinimum(40.);
 
-   if (matrixWidget.minimum() != 40. ||
 
-       matrixWidget.maximum() != 40. ||
 
-       matrixWidget.value(2,2) != 40. ||
 
-       matrixWidget.value(1,2) != 40.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setMinimum() failed:"
 
-               << matrixWidget.maximum() << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setRowCount(3);
 
-   matrixWidget.setColumnCount(3);
 
-   if (matrixWidget.minimum() != 40. ||
 
-       matrixWidget.maximum() != 40. ||
 
-       matrixWidget.value(2,2) != 40. ||
 
-       matrixWidget.value(1,2) != 40.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setMinimum() failed:"
 
-               << matrixWidget.maximum() << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setRange(250., 10.);
 
-   if (matrixWidget.minimum() != 10. ||
 
-       matrixWidget.maximum() != 250. ||
 
-       matrixWidget.value(0,0) != 40. ||
 
-       matrixWidget.value(2,1) != 40.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setRange() failed:"
 
-               << matrixWidget.minimum() << " "
 
-               << matrixWidget.maximum() << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   QVector<double> items;
 
-   items.push_back(200.);
 
-   items.push_back(201.);
 
-   items.push_back(202.);
 
-   items.push_back(203.);
 
-   items.push_back(204.);
 
-   items.push_back(205.);
 
-   items.push_back(206.);
 
-   items.push_back(207.);
 
-   items.push_back(208.);
 
-   matrixWidget.setVector(items);
 
-   if (matrixWidget.value(2,1) != 207.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setVector() failed:"
 
-               << matrixWidget.value(2,1) << std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.identity();
 
-   if (matrixWidget.value(0,0) != 10. ||
 
-       matrixWidget.value(1,0) != 10.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::identity() failed:"
 
-               << matrixWidget.value(0,0) << " "
 
-               << matrixWidget.value(1,0) <<std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-   matrixWidget.setRange(-100, 100.);
 
-   matrixWidget.identity();
 
-   if (matrixWidget.value(1,1) != 1. ||
 
-       matrixWidget.value(0,2) != 0.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::identity() failed:"
 
-               << matrixWidget.value(1,1) << " "
 
-               << matrixWidget.value(0,2) <<std::endl;
 
-     return EXIT_FAILURE;
 
-     }
 
-  
 
-   matrixWidget.setSingleStep(1.);
 
-   if (matrixWidget.singleStep() != 1.)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setSingleStep() failed:"
 
-               << matrixWidget.singleStep() << std::endl;
 
-     }
 
-   matrixWidget.setDecimals(5);
 
-   if (matrixWidget.decimals() != 5)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setDecimals() failed:"
 
-               << matrixWidget.decimals() << std::endl;
 
-     }
 
-   matrixWidget.setDecimals(-1);
 
-   if (matrixWidget.decimals() != 0)
 
-     {
 
-     std::cerr << "ctkMatrixWidget::setDecimals() failed:"
 
-               << matrixWidget.decimals() << std::endl;
 
-     }
 
-   matrixWidget.setEditable(true);
 
-   layout->addWidget(&matrixWidget);
 
-   topLevel.setLayout(layout);
 
-   topLevel.show();
 
-   topLevel.resize(300, 401);
 
-   if (argc < 2 || QString(argv[1]) != "-I" )
 
-     {
 
-     QTimer::singleShot(200, &app, SLOT(quit()));
 
-     }
 
-   return app.exec();
 
- }
 
 
  |