summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTero Ahola <tero.ahola@digia.com>2012-09-07 13:07:37 +0300
committerTero Ahola <tero.ahola@digia.com>2012-09-07 13:10:00 +0300
commitaa64defd89b971642374cb3124155c3230bc95ca (patch)
tree1dd95cc0da15427a664d0a4b3dc57bc66ef598de
parentd117b49788e7d0330e28b3bd40c3fe9fae80784a (diff)
Fixed a bug with legend attach requiring a screen resize to update UI
-rw-r--r--doc/images/examples_legend_detach.pngbin57231 -> 61273 bytes
-rw-r--r--doc/images/examples_legend_detach2.pngbin0 -> 75296 bytes
-rw-r--r--doc/src/examples-legend.qdoc6
-rw-r--r--examples/legend/main.cpp2
-rw-r--r--examples/legend/mainwidget.cpp114
-rw-r--r--examples/legend/mainwidget.h8
-rw-r--r--src/legend/qlegend.cpp2
7 files changed, 59 insertions, 73 deletions
diff --git a/doc/images/examples_legend_detach.png b/doc/images/examples_legend_detach.png
index d3a8efa8..3376a4a0 100644
--- a/doc/images/examples_legend_detach.png
+++ b/doc/images/examples_legend_detach.png
Binary files differ
diff --git a/doc/images/examples_legend_detach2.png b/doc/images/examples_legend_detach2.png
new file mode 100644
index 00000000..5cc33819
--- /dev/null
+++ b/doc/images/examples_legend_detach2.png
Binary files differ
diff --git a/doc/src/examples-legend.qdoc b/doc/src/examples-legend.qdoc
index eb62409c..9f259507 100644
--- a/doc/src/examples-legend.qdoc
+++ b/doc/src/examples-legend.qdoc
@@ -8,7 +8,11 @@
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.
When legend is detached, it can be resized and positioned freely.
- \image examples_legend_detach.png
+ \table
+ \row
+ \o \inlineimage examples_legend_detach.png
+ \o \inlineimage examples_legend_detach2.png
+ \endtable
Here we turn legend visible and set its alignment to the bottom of the chart.
diff --git a/examples/legend/main.cpp b/examples/legend/main.cpp
index d7cefa35..61d5fa30 100644
--- a/examples/legend/main.cpp
+++ b/examples/legend/main.cpp
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
MainWidget w;
- w.resize(1024,768);
+ w.resize(720, 480);
w.show();
return a.exec();
diff --git a/examples/legend/mainwidget.cpp b/examples/legend/mainwidget.cpp
index 9e27d734..ff060998 100644
--- a/examples/legend/mainwidget.cpp
+++ b/examples/legend/mainwidget.cpp
@@ -36,12 +36,9 @@ MainWidget::MainWidget(QWidget *parent) :
{
// Create buttons for ui
m_buttonLayout = new QGridLayout();
- QPushButton *detachLegendButton = new QPushButton("detach legend");
- connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
+ QPushButton *detachLegendButton = new QPushButton("Toggle attached");
+ connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached()));
m_buttonLayout->addWidget(detachLegendButton, 0, 0);
- QPushButton *attachLegendButton = new QPushButton("attach legend");
- connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
- m_buttonLayout->addWidget(attachLegendButton, 1, 0);
QPushButton *addSetButton = new QPushButton("add barset");
connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
@@ -50,21 +47,9 @@ MainWidget::MainWidget(QWidget *parent) :
connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
- QPushButton *leftButton = new QPushButton("Align legend left");
- connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft()));
- m_buttonLayout->addWidget(leftButton, 4, 0);
-
- QPushButton *rightButton = new QPushButton("Align legend right");
- connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight()));
- m_buttonLayout->addWidget(rightButton, 5, 0);
-
- QPushButton *topButton = new QPushButton("Align legend top");
- connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop()));
- m_buttonLayout->addWidget(topButton, 6, 0);
-
- QPushButton *bottomButton = new QPushButton("Align legend bottom");
- connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom()));
- m_buttonLayout->addWidget(bottomButton, 7, 0);
+ QPushButton *alignButton = new QPushButton("Align (Bottom)");
+ connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment()));
+ m_buttonLayout->addWidget(alignButton, 4, 0);
QPushButton *boldButton = new QPushButton("Toggle bold");
connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold()));
@@ -85,8 +70,8 @@ MainWidget::MainWidget(QWidget *parent) :
connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
QFormLayout* legendLayout = new QFormLayout();
- legendLayout->addRow("Horizontal position", m_legendPosX);
- legendLayout->addRow("Vertical position", m_legendPosY);
+ legendLayout->addRow("HPos", m_legendPosX);
+ legendLayout->addRow("VPos", m_legendPosY);
legendLayout->addRow("Width", m_legendWidth);
legendLayout->addRow("Height", m_legendHeight);
m_legendSettings = new QGroupBox("Detached legend");
@@ -163,32 +148,25 @@ void MainWidget::hideLegendSpinbox()
}
-void MainWidget::detachLegend()
+void MainWidget::toggleAttached()
{
-//![2]
QLegend *legend = m_chart->legend();
- legend->detachFromChart();
-
- m_chart->legend()->setBackgroundVisible(true);
- m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
- m_chart->legend()->setPen(QPen(QColor(192,192,192,192)));
-//![2]
-
- showLegendSpinbox();
- updateLegendLayout();
- update();
-}
-
-
-void MainWidget::attachLegend()
-{
-//![3]
- QLegend *legend = m_chart->legend();
- legend->attachToChart();
- m_chart->legend()->setBackgroundVisible(false);
-//![3]
-
- hideLegendSpinbox();
+ if (legend->isAttachedToChart()) {
+ //![2]
+ legend->detachFromChart();
+ m_chart->legend()->setBackgroundVisible(true);
+ m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
+ m_chart->legend()->setPen(QPen(QColor(192,192,192,192)));
+ //![2]
+ showLegendSpinbox();
+ updateLegendLayout();
+ } else {
+ //![3]
+ legend->attachToChart();
+ legend->setBackgroundVisible(false);
+ //![3]
+ hideLegendSpinbox();
+ }
update();
}
@@ -208,24 +186,32 @@ void MainWidget::removeBarset()
}
}
-void MainWidget::setLegendLeft()
-{
- m_chart->legend()->setAlignment(Qt::AlignLeft);
-}
-
-void MainWidget::setLegendRight()
-{
- m_chart->legend()->setAlignment(Qt::AlignRight);
-}
-
-void MainWidget::setLegendTop()
-{
- m_chart->legend()->setAlignment(Qt::AlignTop);
-}
-
-void MainWidget::setLegendBottom()
-{
- m_chart->legend()->setAlignment(Qt::AlignBottom);
+void MainWidget::setLegendAlignment()
+{
+ QPushButton *button = qobject_cast<QPushButton *>(sender());
+
+ switch (m_chart->legend()->alignment()) {
+ case Qt::AlignTop:
+ m_chart->legend()->setAlignment(Qt::AlignLeft);
+ if (button)
+ button->setText("Align (Left)");
+ break;
+ case Qt::AlignLeft:
+ m_chart->legend()->setAlignment(Qt::AlignBottom);
+ if (button)
+ button->setText("Align (Bottom)");
+ break;
+ case Qt::AlignBottom:
+ m_chart->legend()->setAlignment(Qt::AlignRight);
+ if (button)
+ button->setText("Align (Right)");
+ break;
+ default:
+ if (button)
+ button->setText("Align (Top)");
+ m_chart->legend()->setAlignment(Qt::AlignTop);
+ break;
+ }
}
void MainWidget::toggleBold()
diff --git a/examples/legend/mainwidget.h b/examples/legend/mainwidget.h
index e0b2fbd2..0a94c1f4 100644
--- a/examples/legend/mainwidget.h
+++ b/examples/legend/mainwidget.h
@@ -46,15 +46,11 @@ public:
signals:
public slots:
- void detachLegend();
- void attachLegend();
+ void toggleAttached();
void addBarset();
void removeBarset();
- void setLegendLeft();
- void setLegendRight();
- void setLegendTop();
- void setLegendBottom();
+ void setLegendAlignment();
void toggleBold();
void toggleItalic();
diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp
index 570c360b..a4e3b1b7 100644
--- a/src/legend/qlegend.cpp
+++ b/src/legend/qlegend.cpp
@@ -366,7 +366,7 @@ void QLegend::detachFromChart()
void QLegend::attachToChart()
{
d_ptr->m_attachedToChart = true;
- d_ptr->m_layout->invalidate();
+ d_ptr->m_presenter->layout()->invalidate();
setParent(d_ptr->m_chart);
}