##// END OF EJS Templates
Make category axis label positioning at value work for polar charts...
Miikka Heikkinen -
r2801:acb3f8c5f190
parent child
Show More
@@ -20,6 +20,7
20 20 #include <private/qabstractaxis_p.h>
21 21 #include <private/chartpresenter_p.h>
22 22 #include <private/abstractchartlayout_p.h>
23 #include <QtCharts/QCategoryAxis>
23 24 #include <QtCore/QtMath>
24 25 #include <QtCore/QDateTime>
25 26 #include <QtGui/QTextDocument>
@@ -105,6 +106,13 void ChartAxisElement::connectSlots()
105 106 this, SLOT(handleMinorGridVisibleChanged(bool)));
106 107 QObject::connect(axis(), SIGNAL(minorGridLinePenChanged(const QPen&)),
107 108 this, SLOT(handleMinorGridPenChanged(const QPen&)));
109
110 if (axis()->type() == QAbstractAxis::AxisTypeCategory) {
111 QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis());
112 QObject::connect(categoryAxis,
113 SIGNAL(labelsPositionChanged(QCategoryAxis::AxisLabelsPosition)),
114 this, SLOT(handleLabelsPositionChanged()));
115 }
108 116 }
109 117
110 118 void ChartAxisElement::handleArrowVisibleChanged(bool visible)
@@ -127,6 +135,12 void ChartAxisElement::handleMinorGridVisibleChanged(bool visible)
127 135 m_minorGrid->setVisible(visible);
128 136 }
129 137
138 void ChartAxisElement::handleLabelsPositionChanged()
139 {
140 QGraphicsLayoutItem::updateGeometry();
141 presenter()->layout()->invalidate();
142 }
143
130 144 void ChartAxisElement::handleLabelsVisibleChanged(bool visible)
131 145 {
132 146 QGraphicsLayoutItem::updateGeometry();
@@ -132,7 +132,7 public Q_SLOTS:
132 132 void handleReverseChanged(bool reverse);
133 133 void handleMinorArrowVisibleChanged(bool visible);
134 134 void handleMinorGridVisibleChanged(bool visible);
135
135 void handleLabelsPositionChanged();
136 136
137 137 Q_SIGNALS:
138 138 void clicked();
@@ -20,6 +20,7
20 20 #include <private/chartpresenter_p.h>
21 21 #include <private/abstractchartlayout_p.h>
22 22 #include <QtCharts/QAbstractAxis>
23 #include <QtCharts/QCategoryAxis>
23 24 #include <private/qabstractaxis_p.h>
24 25 #include <QtCore/QDebug>
25 26 #include <QtCore/QtMath>
@@ -93,7 +94,7 void PolarChartAxisAngular::updateGeometry()
93 94 }
94 95
95 96 qreal labelCoordinate = angularCoordinate;
96 qreal labelVisible = currentTickVisible;
97 bool labelVisible = currentTickVisible;
97 98 if (intervalAxis()) {
98 99 qreal farEdge;
99 100 if (i == (layout.size() - 1))
@@ -105,12 +106,23 void PolarChartAxisAngular::updateGeometry()
105 106 if (nextTickVisible)
106 107 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
107 108
108 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
109 // Don't display label once the category gets too small near the axis
110 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
111 labelVisible = false;
112 else
113 labelVisible = true;
109 bool centeredLabel = true;
110 if (axis()->type() == QAbstractAxis::AxisTypeCategory) {
111 QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis());
112 if (categoryAxis->labelsPosition() == QCategoryAxis::AxisLabelsPositionOnValue)
113 centeredLabel = false;
114 }
115 if (centeredLabel) {
116 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
117 // Don't display label once the category gets too small near the axis
118 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
119 labelVisible = false;
120 else
121 labelVisible = true;
122 } else {
123 labelVisible = nextTickVisible;
124 labelCoordinate = farEdge;
125 }
114 126 }
115 127
116 128 // Need this also in label calculations, so determine it first
@@ -21,6 +21,7
21 21 #include <private/abstractchartlayout_p.h>
22 22 #include <private/qabstractaxis_p.h>
23 23 #include <private/linearrowitem_p.h>
24 #include <QtCharts/QCategoryAxis>
24 25 #include <QtGui/QTextDocument>
25 26
26 27 QT_CHARTS_BEGIN_NAMESPACE
@@ -85,8 +86,9 void PolarChartAxisRadial::updateGeometry()
85 86 }
86 87
87 88 qreal labelCoordinate = radialCoordinate;
88 qreal labelVisible = currentTickVisible;
89 bool labelVisible = currentTickVisible;
89 90 qreal labelPad = labelPadding() / 2.0;
91 bool centeredLabel = true; // Only used with interval axes
90 92 if (intervalAxis()) {
91 93 qreal farEdge;
92 94 if (i == (layout.size() - 1))
@@ -98,11 +100,21 void PolarChartAxisRadial::updateGeometry()
98 100 if (nextTickVisible)
99 101 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
100 102
101 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
102 if (labelCoordinate > 0.0 && labelCoordinate < radius)
103 labelVisible = true;
104 else
105 labelVisible = false;
103 if (axis()->type() == QAbstractAxis::AxisTypeCategory) {
104 QCategoryAxis *categoryAxis = static_cast<QCategoryAxis *>(axis());
105 if (categoryAxis->labelsPosition() == QCategoryAxis::AxisLabelsPositionOnValue)
106 centeredLabel = false;
107 }
108 if (centeredLabel) {
109 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
110 if (labelCoordinate > 0.0 && labelCoordinate < radius)
111 labelVisible = true;
112 else
113 labelVisible = false;
114 } else {
115 labelVisible = nextTickVisible;
116 labelCoordinate = farEdge;
117 }
106 118 }
107 119
108 120 // Radial axis label
@@ -118,7 +130,7 void PolarChartAxisRadial::updateGeometry()
118 130 boundingRect.moveCenter(labelCenter);
119 131 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
120 132 QPointF labelPoint = center;
121 if (intervalAxis())
133 if (intervalAxis() && centeredLabel)
122 134 labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0));
123 135 else
124 136 labelPoint += QPointF(labelPad, labelPad - labelCoordinate);
@@ -127,44 +127,84 MainWindow::MainWindow(QWidget *parent) :
127 127 ui->angularAxisComboBox->setCurrentIndex(int(m_angularAxisMode));
128 128 ui->radialAxisComboBox->setCurrentIndex(int(m_radialAxisMode));
129 129
130 connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularTicksChanged(int)));
131 connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialTicksChanged(int)));
132 connect(ui->angularMinorTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularMinorTicksChanged(int)));
133 connect(ui->radialMinorTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialMinorTicksChanged(int)));
134 connect(ui->anglesSpin, SIGNAL(valueChanged(int)), this, SLOT(anglesChanged(int)));
135 connect(ui->radialMinSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMinChanged(double)));
136 connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMaxChanged(double)));
137 connect(ui->angularMinSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMinChanged(double)));
138 connect(ui->angularMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMaxChanged(double)));
139 connect(ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularShadesIndexChanged(int)));
140 connect(ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialShadesIndexChanged(int)));
141 connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(animationIndexChanged(int)));
142 connect(ui->labelFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(labelFormatEdited(QString)));
143 connect(ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(labelFontChanged(QFont)));
144 connect(ui->labelFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(labelFontSizeChanged(int)));
145 connect(ui->labelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(labelsIndexChanged(int)));
146 connect(ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(titleFontChanged(QFont)));
147 connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(titleFontSizeChanged(int)));
148 connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(titleIndexChanged(int)));
149 connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridIndexChanged(int)));
150 connect(ui->minorGridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(minorGridIndexChanged(int)));
151 connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(arrowIndexChanged(int)));
152 connect(ui->logBaseSpin, SIGNAL(valueChanged(double)), this, SLOT(logBaseChanged(double)));
153 connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularAxisIndexChanged(int)));
154 connect(ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialAxisIndexChanged(int)));
155 connect(ui->niceNumbersCheckBox, SIGNAL(clicked()), this, SLOT(niceNumbersChecked()));
156 connect(ui->dateFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(dateFormatEdited(QString)));
157 connect(ui->moreCategoriesCheckBox, SIGNAL(clicked()), this, SLOT(moreCategoriesChecked()));
158 connect(ui->series1checkBox, SIGNAL(clicked()), this, SLOT(series1CheckBoxChecked()));
159 connect(ui->series2checkBox, SIGNAL(clicked()), this, SLOT(series2CheckBoxChecked()));
160 connect(ui->series3checkBox, SIGNAL(clicked()), this, SLOT(series3CheckBoxChecked()));
161 connect(ui->series4checkBox, SIGNAL(clicked()), this, SLOT(series4CheckBoxChecked()));
162 connect(ui->series5checkBox, SIGNAL(clicked()), this, SLOT(series5CheckBoxChecked()));
163 connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked()));
164 connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked()));
165 connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int)));
166 connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(backgroundIndexChanged(int)));
167 connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(plotAreaIndexChanged(int)));
130 connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)),
131 this, SLOT(angularTicksChanged(int)));
132 connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)),
133 this, SLOT(radialTicksChanged(int)));
134 connect(ui->angularMinorTicksSpin, SIGNAL(valueChanged(int)),
135 this, SLOT(angularMinorTicksChanged(int)));
136 connect(ui->radialMinorTicksSpin, SIGNAL(valueChanged(int)),
137 this, SLOT(radialMinorTicksChanged(int)));
138 connect(ui->anglesSpin, SIGNAL(valueChanged(int)),
139 this, SLOT(anglesChanged(int)));
140 connect(ui->radialMinSpin, SIGNAL(valueChanged(double)),
141 this, SLOT(radialMinChanged(double)));
142 connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)),
143 this, SLOT(radialMaxChanged(double)));
144 connect(ui->angularMinSpin, SIGNAL(valueChanged(double)),
145 this, SLOT(angularMinChanged(double)));
146 connect(ui->angularMaxSpin, SIGNAL(valueChanged(double)),
147 this, SLOT(angularMaxChanged(double)));
148 connect(ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)),
149 this, SLOT(angularShadesIndexChanged(int)));
150 connect(ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)),
151 this, SLOT(radialShadesIndexChanged(int)));
152 connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)),
153 this, SLOT(animationIndexChanged(int)));
154 connect(ui->labelFormatEdit, SIGNAL(textEdited(QString)),
155 this, SLOT(labelFormatEdited(QString)));
156 connect(ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)),
157 this, SLOT(labelFontChanged(QFont)));
158 connect(ui->labelFontSizeSpin, SIGNAL(valueChanged(int)),
159 this, SLOT(labelFontSizeChanged(int)));
160 connect(ui->labelComboBox, SIGNAL(currentIndexChanged(int)),
161 this, SLOT(labelsIndexChanged(int)));
162 connect(ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)),
163 this, SLOT(titleFontChanged(QFont)));
164 connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)),
165 this, SLOT(titleFontSizeChanged(int)));
166 connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)),
167 this, SLOT(titleIndexChanged(int)));
168 connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)),
169 this, SLOT(gridIndexChanged(int)));
170 connect(ui->minorGridComboBox, SIGNAL(currentIndexChanged(int)),
171 this, SLOT(minorGridIndexChanged(int)));
172 connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)),
173 this, SLOT(arrowIndexChanged(int)));
174 connect(ui->logBaseSpin, SIGNAL(valueChanged(double)),
175 this, SLOT(logBaseChanged(double)));
176 connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)),
177 this, SLOT(angularAxisIndexChanged(int)));
178 connect(ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)),
179 this, SLOT(radialAxisIndexChanged(int)));
180 connect(ui->niceNumbersCheckBox, SIGNAL(clicked()),
181 this, SLOT(niceNumbersChecked()));
182 connect(ui->dateFormatEdit, SIGNAL(textEdited(QString)),
183 this, SLOT(dateFormatEdited(QString)));
184 connect(ui->moreCategoriesCheckBox, SIGNAL(clicked()),
185 this, SLOT(moreCategoriesChecked()));
186 connect(ui->categoryLabelLocationCheckBox, SIGNAL(clicked()),
187 this, SLOT(categoryLabelLocationChecked()));
188 connect(ui->series1checkBox, SIGNAL(clicked()),
189 this, SLOT(series1CheckBoxChecked()));
190 connect(ui->series2checkBox, SIGNAL(clicked()),
191 this, SLOT(series2CheckBoxChecked()));
192 connect(ui->series3checkBox, SIGNAL(clicked()),
193 this, SLOT(series3CheckBoxChecked()));
194 connect(ui->series4checkBox, SIGNAL(clicked()),
195 this, SLOT(series4CheckBoxChecked()));
196 connect(ui->series5checkBox, SIGNAL(clicked()),
197 this, SLOT(series5CheckBoxChecked()));
198 connect(ui->series6checkBox, SIGNAL(clicked()),
199 this, SLOT(series6CheckBoxChecked()));
200 connect(ui->series7checkBox, SIGNAL(clicked()),
201 this, SLOT(series7CheckBoxChecked()));
202 connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)),
203 this, SLOT(themeIndexChanged(int)));
204 connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)),
205 this, SLOT(backgroundIndexChanged(int)));
206 connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)),
207 this, SLOT(plotAreaIndexChanged(int)));
168 208
169 209 ui->chartView->setChart(m_chart);
170 210 ui->chartView->setRenderHint(QPainter::Antialiasing);
@@ -1039,6 +1079,11 void MainWindow::moreCategoriesChecked()
1039 1079 m_moreCategories = ui->moreCategoriesCheckBox->isChecked();
1040 1080 }
1041 1081
1082 void MainWindow::categoryLabelLocationChecked()
1083 {
1084 applyCategories();
1085 }
1086
1042 1087 void MainWindow::series1CheckBoxChecked()
1043 1088 {
1044 1089 if (ui->series1checkBox->isChecked())
@@ -1206,6 +1251,10 void MainWindow::applyCategories()
1206 1251 angCatAxis->remove("Cat D");
1207 1252 angCatAxis->remove("Cat E");
1208 1253 }
1254 if (ui->categoryLabelLocationCheckBox->isChecked())
1255 angCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
1256 else
1257 angCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionCenter);
1209 1258 }
1210 1259
1211 1260 if (m_radialAxisMode == AxisModeCategory) {
@@ -1231,5 +1280,9 void MainWindow::applyCategories()
1231 1280 radCatAxis->remove("Cat 4");
1232 1281 radCatAxis->remove("Cat 5");
1233 1282 }
1283 if (ui->categoryLabelLocationCheckBox->isChecked())
1284 radCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
1285 else
1286 radCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionCenter);
1234 1287 }
1235 1288 }
@@ -79,6 +79,7 public slots:
79 79 void niceNumbersChecked();
80 80 void dateFormatEdited(const QString &text);
81 81 void moreCategoriesChecked();
82 void categoryLabelLocationChecked();
82 83 void series1CheckBoxChecked();
83 84 void series2CheckBoxChecked();
84 85 void series3CheckBoxChecked();
@@ -688,23 +688,23
688 688 <property name="geometry">
689 689 <rect>
690 690 <x>10</x>
691 <y>692</y>
692 <width>198</width>
693 <height>19</height>
691 <y>680</y>
692 <width>191</width>
693 <height>31</height>
694 694 </rect>
695 695 </property>
696 <layout class="QHBoxLayout" name="horizontalLayout_3">
697 <item>
698 <widget class="QCheckBox" name="niceNumbersCheckBox">
696 <layout class="QGridLayout" name="gridLayout_6">
697 <item row="0" column="1">
698 <widget class="QCheckBox" name="moreCategoriesCheckBox">
699 699 <property name="text">
700 <string>Nice Numbers</string>
700 <string>More Categories</string>
701 701 </property>
702 702 </widget>
703 703 </item>
704 <item>
705 <widget class="QCheckBox" name="moreCategoriesCheckBox">
704 <item row="0" column="0">
705 <widget class="QCheckBox" name="niceNumbersCheckBox">
706 706 <property name="text">
707 <string>More Categories</string>
707 <string>Nice Numbers</string>
708 708 </property>
709 709 </widget>
710 710 </item>
@@ -714,7 +714,7
714 714 <property name="geometry">
715 715 <rect>
716 716 <x>10</x>
717 <y>729</y>
717 <y>740</y>
718 718 <width>221</width>
719 719 <height>22</height>
720 720 </rect>
@@ -899,6 +899,19
899 899 </property>
900 900 </item>
901 901 </widget>
902 <widget class="QCheckBox" name="categoryLabelLocationCheckBox">
903 <property name="geometry">
904 <rect>
905 <x>10</x>
906 <y>710</y>
907 <width>142</width>
908 <height>17</height>
909 </rect>
910 </property>
911 <property name="text">
912 <string>Category Label On Tick</string>
913 </property>
914 </widget>
902 915 </widget>
903 916 </item>
904 917 </layout>
General Comments 0
You need to be logged in to leave comments. Login now