1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -8,7 +8,11 | |||||
8 | In example we use barseries where we add or remove barsets. The legend reflects the changes in series. Legend can be detached or attached back to chart and its alignment can be modified. |
|
8 | In example we use barseries where we add or remove barsets. The legend reflects the changes in series. Legend can be detached or attached back to chart and its alignment can be modified. | |
9 | When legend is detached, it can be resized and positioned freely. |
|
9 | When legend is detached, it can be resized and positioned freely. | |
10 |
|
10 | |||
11 | \image examples_legend_detach.png |
|
11 | \table | |
|
12 | \row | |||
|
13 | \o \inlineimage examples_legend_detach.png | |||
|
14 | \o \inlineimage examples_legend_detach2.png | |||
|
15 | \endtable | |||
12 |
|
16 | |||
13 | Here we turn legend visible and set its alignment to the bottom of the chart. |
|
17 | Here we turn legend visible and set its alignment to the bottom of the chart. | |
14 |
|
18 |
@@ -30,7 +30,7 int main(int argc, char *argv[]) | |||||
30 | QApplication a(argc, argv); |
|
30 | QApplication a(argc, argv); | |
31 |
|
31 | |||
32 | MainWidget w; |
|
32 | MainWidget w; | |
33 |
w.resize( |
|
33 | w.resize(720, 480); | |
34 | w.show(); |
|
34 | w.show(); | |
35 |
|
35 | |||
36 | return a.exec(); |
|
36 | return a.exec(); |
@@ -36,12 +36,9 MainWidget::MainWidget(QWidget *parent) : | |||||
36 | { |
|
36 | { | |
37 | // Create buttons for ui |
|
37 | // Create buttons for ui | |
38 | m_buttonLayout = new QGridLayout(); |
|
38 | m_buttonLayout = new QGridLayout(); | |
39 |
QPushButton *detachLegendButton = new QPushButton(" |
|
39 | QPushButton *detachLegendButton = new QPushButton("Toggle attached"); | |
40 |
connect(detachLegendButton, SIGNAL(clicked()), this, SLOT( |
|
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); | |
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); | |
42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); |
|
|||
43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); |
|
|||
44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); |
|
|||
45 |
|
42 | |||
46 | QPushButton *addSetButton = new QPushButton("add barset"); |
|
43 | QPushButton *addSetButton = new QPushButton("add barset"); | |
47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); |
|
44 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); | |
@@ -50,21 +47,9 MainWidget::MainWidget(QWidget *parent) : | |||||
50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); |
|
47 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); | |
51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); |
|
48 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); | |
52 |
|
49 | |||
53 |
QPushButton * |
|
50 | QPushButton *alignButton = new QPushButton("Align (Bottom)"); | |
54 |
connect( |
|
51 | connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); | |
55 |
m_buttonLayout->addWidget( |
|
52 | m_buttonLayout->addWidget(alignButton, 4, 0); | |
56 |
|
||||
57 | QPushButton *rightButton = new QPushButton("Align legend right"); |
|
|||
58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); |
|
|||
59 | m_buttonLayout->addWidget(rightButton, 5, 0); |
|
|||
60 |
|
||||
61 | QPushButton *topButton = new QPushButton("Align legend top"); |
|
|||
62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); |
|
|||
63 | m_buttonLayout->addWidget(topButton, 6, 0); |
|
|||
64 |
|
||||
65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); |
|
|||
66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); |
|
|||
67 | m_buttonLayout->addWidget(bottomButton, 7, 0); |
|
|||
68 |
|
53 | |||
69 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
54 | QPushButton *boldButton = new QPushButton("Toggle bold"); | |
70 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
55 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); | |
@@ -85,8 +70,8 MainWidget::MainWidget(QWidget *parent) : | |||||
85 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
70 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
86 |
|
71 | |||
87 | QFormLayout* legendLayout = new QFormLayout(); |
|
72 | QFormLayout* legendLayout = new QFormLayout(); | |
88 |
legendLayout->addRow("H |
|
73 | legendLayout->addRow("HPos", m_legendPosX); | |
89 |
legendLayout->addRow("V |
|
74 | legendLayout->addRow("VPos", m_legendPosY); | |
90 | legendLayout->addRow("Width", m_legendWidth); |
|
75 | legendLayout->addRow("Width", m_legendWidth); | |
91 | legendLayout->addRow("Height", m_legendHeight); |
|
76 | legendLayout->addRow("Height", m_legendHeight); | |
92 | m_legendSettings = new QGroupBox("Detached legend"); |
|
77 | m_legendSettings = new QGroupBox("Detached legend"); | |
@@ -163,32 +148,25 void MainWidget::hideLegendSpinbox() | |||||
163 | } |
|
148 | } | |
164 |
|
149 | |||
165 |
|
150 | |||
166 |
void MainWidget:: |
|
151 | void MainWidget::toggleAttached() | |
167 | { |
|
152 | { | |
168 | //![2] |
|
|||
169 | QLegend *legend = m_chart->legend(); |
|
153 | QLegend *legend = m_chart->legend(); | |
|
154 | if (legend->isAttachedToChart()) { | |||
|
155 | //![2] | |||
170 | legend->detachFromChart(); |
|
156 | legend->detachFromChart(); | |
171 |
|
||||
172 | m_chart->legend()->setBackgroundVisible(true); |
|
157 | m_chart->legend()->setBackgroundVisible(true); | |
173 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
158 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); | |
174 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
159 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); | |
175 | //![2] |
|
160 | //![2] | |
176 |
|
||||
177 | showLegendSpinbox(); |
|
161 | showLegendSpinbox(); | |
178 | updateLegendLayout(); |
|
162 | updateLegendLayout(); | |
179 | update(); |
|
163 | } else { | |
180 | } |
|
|||
181 |
|
||||
182 |
|
||||
183 | void MainWidget::attachLegend() |
|
|||
184 | { |
|
|||
185 | //![3] |
|
164 | //![3] | |
186 | QLegend *legend = m_chart->legend(); |
|
|||
187 | legend->attachToChart(); |
|
165 | legend->attachToChart(); | |
188 |
|
|
166 | legend->setBackgroundVisible(false); | |
189 | //![3] |
|
167 | //![3] | |
190 |
|
||||
191 | hideLegendSpinbox(); |
|
168 | hideLegendSpinbox(); | |
|
169 | } | |||
192 | update(); |
|
170 | update(); | |
193 | } |
|
171 | } | |
194 |
|
172 | |||
@@ -208,24 +186,32 void MainWidget::removeBarset() | |||||
208 | } |
|
186 | } | |
209 | } |
|
187 | } | |
210 |
|
188 | |||
211 |
void MainWidget::setLegend |
|
189 | void MainWidget::setLegendAlignment() | |
212 | { |
|
190 | { | |
213 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
191 | QPushButton *button = qobject_cast<QPushButton *>(sender()); | |
214 | } |
|
|||
215 |
|
192 | |||
216 | void MainWidget::setLegendRight() |
|
193 | switch (m_chart->legend()->alignment()) { | |
217 | { |
|
194 | case Qt::AlignTop: | |
|
195 | m_chart->legend()->setAlignment(Qt::AlignLeft); | |||
|
196 | if (button) | |||
|
197 | button->setText("Align (Left)"); | |||
|
198 | break; | |||
|
199 | case Qt::AlignLeft: | |||
|
200 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |||
|
201 | if (button) | |||
|
202 | button->setText("Align (Bottom)"); | |||
|
203 | break; | |||
|
204 | case Qt::AlignBottom: | |||
218 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
205 | m_chart->legend()->setAlignment(Qt::AlignRight); | |
219 | } |
|
206 | if (button) | |
220 |
|
207 | button->setText("Align (Right)"); | ||
221 | void MainWidget::setLegendTop() |
|
208 | break; | |
222 | { |
|
209 | default: | |
|
210 | if (button) | |||
|
211 | button->setText("Align (Top)"); | |||
223 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
212 | m_chart->legend()->setAlignment(Qt::AlignTop); | |
|
213 | break; | |||
224 | } |
|
214 | } | |
225 |
|
||||
226 | void MainWidget::setLegendBottom() |
|
|||
227 | { |
|
|||
228 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
|||
229 | } |
|
215 | } | |
230 |
|
216 | |||
231 | void MainWidget::toggleBold() |
|
217 | void MainWidget::toggleBold() |
@@ -46,15 +46,11 public: | |||||
46 | signals: |
|
46 | signals: | |
47 |
|
47 | |||
48 | public slots: |
|
48 | public slots: | |
49 |
void |
|
49 | void toggleAttached(); | |
50 | void attachLegend(); |
|
|||
51 | void addBarset(); |
|
50 | void addBarset(); | |
52 | void removeBarset(); |
|
51 | void removeBarset(); | |
53 |
|
52 | |||
54 |
void setLegend |
|
53 | void setLegendAlignment(); | |
55 | void setLegendRight(); |
|
|||
56 | void setLegendTop(); |
|
|||
57 | void setLegendBottom(); |
|
|||
58 |
|
54 | |||
59 | void toggleBold(); |
|
55 | void toggleBold(); | |
60 | void toggleItalic(); |
|
56 | void toggleItalic(); |
@@ -368,7 +368,7 void QLegend::detachFromChart() | |||||
368 | void QLegend::attachToChart() |
|
368 | void QLegend::attachToChart() | |
369 | { |
|
369 | { | |
370 | d_ptr->m_attachedToChart = true; |
|
370 | d_ptr->m_attachedToChart = true; | |
371 | d_ptr->m_layout->invalidate(); |
|
371 | d_ptr->m_presenter->layout()->invalidate(); | |
372 | setParent(d_ptr->m_chart); |
|
372 | setParent(d_ptr->m_chart); | |
373 | } |
|
373 | } | |
374 |
|
374 |
General Comments 0
You need to be logged in to leave comments.
Login now