File indexing completed on 2024-05-12 15:53:55
0001 /** 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include <QtTest/QtTest> 0021 0022 #include <QLabel> 0023 0024 #include <KChartGlobal> 0025 #include <KChartPosition> 0026 #include <KChartMeasure> 0027 #include <KChartRelativePosition> 0028 0029 using namespace KChart; 0030 0031 class TestRelativePosition: public QObject { 0032 Q_OBJECT 0033 private Q_SLOTS: 0034 0035 void initTestCase() 0036 { 0037 m_window = new QLabel(nullptr); 0038 m_window->setGeometry(100,100, 300,200); 0039 m_window->show(); 0040 } 0041 0042 void testRelativePositionHRelativeVAbsolute() 0043 { 0044 const qreal horizPerMille = 100.0; 0045 KChart::Measure mHoriz( 0046 horizPerMille, 0047 KChartEnums::MeasureCalculationModeRelative, 0048 KChartEnums::MeasureOrientationHorizontal ); 0049 mHoriz.setReferenceArea( m_window ); 0050 0051 const qreal vertAbsolute = -50.0; 0052 KChart::Measure mVert( 0053 vertAbsolute, 0054 KChartEnums::MeasureCalculationModeAbsolute ); 0055 0056 KChart::RelativePosition relPos; 0057 relPos.setReferenceArea( m_window ); 0058 relPos.setReferencePosition( KChart::Position::NorthWest ); 0059 relPos.setHorizontalPadding( mHoriz ); 0060 relPos.setVerticalPadding( mVert ); 0061 0062 // no auto mode is active, so we pass an empty QSizeF: 0063 const QPointF pt( relPos.calculatedPoint( QSizeF() ) ); 0064 const QRectF geo( m_window->geometry() ); 0065 QCOMPARE( pt.x(), geo.topLeft().x() + geo.size().width() / 1000.0 * horizPerMille ); 0066 QCOMPARE( pt.y(), geo.topLeft().y() + vertAbsolute ); 0067 } 0068 0069 void testRelativePositionHAbsoluteVRelative() 0070 { 0071 const qreal horizAbsolute = 100.0; 0072 KChart::Measure mHoriz( 0073 horizAbsolute, 0074 KChartEnums::MeasureCalculationModeAbsolute ); 0075 0076 const qreal vertRelative = -50.0; 0077 KChart::Measure mVert( 0078 vertRelative, 0079 KChartEnums::MeasureCalculationModeRelative, 0080 KChartEnums::MeasureOrientationVertical ); 0081 mVert.setReferenceArea( m_window ); 0082 0083 KChart::RelativePosition relPos; 0084 relPos.setReferenceArea( m_window ); 0085 relPos.setReferencePosition( KChart::Position::Center ); 0086 relPos.setHorizontalPadding( mHoriz ); 0087 relPos.setVerticalPadding( mVert ); 0088 0089 // no auto mode is active, so we pass an empty QSizeF: 0090 const QPointF pt( relPos.calculatedPoint( QSizeF() ) ); 0091 const QRectF geo( m_window->geometry() ); 0092 QCOMPARE( pt.x(), geo.center().x() + horizAbsolute ); 0093 QCOMPARE( pt.y(), geo.center().y() + geo.size().height() / 1000.0 * vertRelative ); 0094 } 0095 0096 0097 void cleanupTestCase() 0098 { 0099 } 0100 0101 private: 0102 QLabel *m_window; 0103 0104 }; 0105 0106 QTEST_MAIN(TestRelativePosition) 0107 0108 #include "main.moc"