diff --git a/demos/chartviewer/grid.cpp b/demos/chartviewer/grid.cpp index 5236e21..d332566 100644 --- a/demos/chartviewer/grid.cpp +++ b/demos/chartviewer/grid.cpp @@ -31,6 +31,8 @@ Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent), m_valueCount(7), m_size(size), m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), + m_state(NoState), + m_currentState(NoState), m_rubberBand(new QGraphicsRectItem()), m_gridLayout(new QGraphicsGridLayout()) { @@ -45,28 +47,6 @@ Grid::~Grid() } -void Grid::createCharts() -{ - clear(); - - Charts::ChartList list = Charts::chartList(); - - for (int i = 0; i < m_size * m_size; ++i) { - QChart *chart = 0; - if (i < list.size()) { - chart = list.at(i)->createChart(m_dataTable); - } - else { - chart = new QChart(); - chart->setTitle(QObject::tr("Empty")); - } - - m_gridLayout->addItem(chart, i / m_size, i % m_size); - m_chartHash[chart] = i; - } - -} - void Grid::createCharts(const QString& category) { clear(); @@ -74,23 +54,42 @@ void Grid::createCharts(const QString& category) QChart *qchart(0); Charts::ChartList list = Charts::chartList(); - int j = 0; - for (int i = 0; i < list.size(); ++i) { - Chart *chart = list.at(i); - if (chart->category() == category && j < m_size * m_size) { - qchart = list.at(i)->createChart(m_dataTable); + if (category.isEmpty()) { + + for (int i = 0; i < m_size * m_size; ++i) { + QChart *chart = 0; + if (i < list.size()) { + chart = list.at(i)->createChart(m_dataTable); + } + else { + chart = new QChart(); + chart->setTitle(QObject::tr("Empty")); + } + + m_gridLayout->addItem(chart, i / m_size, i % m_size); + m_chartHash[chart] = i; + } + } + else { + + int j = 0; + for (int i = 0; i < list.size(); ++i) { + Chart *chart = list.at(i); + if (chart->category() == category && j < m_size * m_size) { + qchart = list.at(i)->createChart(m_dataTable); + m_gridLayout->addItem(qchart, j / m_size, j % m_size); + m_chartHash[qchart] = j; + j++; + } + } + for (; j < m_size * m_size; ++j) { + qchart = new QChart(); + qchart->setTitle(QObject::tr("Empty")); m_gridLayout->addItem(qchart, j / m_size, j % m_size); m_chartHash[qchart] = j; - j++; } } - for (; j < m_size * m_size; ++j) { - qchart = new QChart(); - qchart->setTitle(QObject::tr("Empty")); - m_gridLayout->addItem(qchart, j / m_size, j % m_size); - m_chartHash[qchart] = j; - } - + m_category = category; m_gridLayout->activate(); } @@ -114,6 +113,15 @@ void Grid::setState(State state) m_state = state; } +void Grid::setSize(int size) +{ + if(m_size !=size) + { + m_size = size; + createCharts(m_category); + } +} + void Grid::setRubberPen(const QPen& pen) { m_rubberBand->setPen(pen); diff --git a/demos/chartviewer/grid.h b/demos/chartviewer/grid.h index 2c0ffa2..4ebcddd 100644 --- a/demos/chartviewer/grid.h +++ b/demos/chartviewer/grid.h @@ -26,7 +26,6 @@ #include class QGraphicsGridLayout; -class GridControl; class Chart; QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -43,12 +42,13 @@ public: Grid(int size , QGraphicsItem *parent = 0 ); ~Grid(); QList charts(); - void createCharts(); - void createCharts(const QString& category); + void createCharts(const QString& category = QString()); void replaceChart(QChart* oldChart, Chart* newChart); void setState(State state); - State state(){ return m_state; }; + State state() const { return m_state; }; void setRubberPen(const QPen& pen); + void setSize(int size); + int size() const {return m_size;} Q_SIGNAL void chartSelected(QChart* chart); protected: @@ -64,12 +64,12 @@ private: int m_size; DataTable m_dataTable; QHash m_chartHash; - GridControl* m_control; State m_state; State m_currentState; QPointF m_origin; QGraphicsRectItem *m_rubberBand; QGraphicsGridLayout* m_gridLayout; + QString m_category; }; #endif /* GRID_H_ */ diff --git a/demos/chartviewer/window.cpp b/demos/chartviewer/window.cpp index 245acee..be6546b 100644 --- a/demos/chartviewer/window.cpp +++ b/demos/chartviewer/window.cpp @@ -39,6 +39,7 @@ #include #include #include +#include Window::Window(const QVariantHash& parameters,QWidget *parent) : QMainWindow(parent), @@ -50,21 +51,25 @@ Window::Window(const QVariantHash& parameters,QWidget *parent) : m_animatedComboBox(0), m_legendComboBox(0), m_templateComboBox(0), + m_viewComboBox(0), m_openGLCheckBox(0), m_zoomCheckBox(0), m_scrollCheckBox(0), m_baseLayout(new QGraphicsLinearLayout()), m_menu(createMenu()), m_template(0), - m_grid(new Grid(3)) + m_grid(new Grid(1)) { createProxyWidgets(); // create layout QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); + settingsLayout->setOrientation(Qt::Vertical); settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); + settingsLayout->addItem(m_widgetHash["viewLabel"]); + settingsLayout->addItem(m_widgetHash["viewComboBox"]); settingsLayout->addItem(m_widgetHash["themeLabel"]); settingsLayout->addItem(m_widgetHash["themeComboBox"]); settingsLayout->addItem(m_widgetHash["animationsLabel"]); @@ -94,6 +99,7 @@ Window::Window(const QVariantHash& parameters,QWidget *parent) : m_antialiasCheckBox->setChecked(true); initializeFromParamaters(parameters); updateUI(); + handleGeometryChanged(); setCentralWidget(m_view); connectSignals(); @@ -106,6 +112,7 @@ Window::~Window() void Window::connectSignals() { QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); + QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); @@ -120,6 +127,7 @@ void Window::connectSignals() void Window::createProxyWidgets() { m_themeComboBox = createThemeBox(); + m_viewComboBox = createViewBox(); m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); m_animatedComboBox = createAnimationBox(); m_legendComboBox = createLegendBox(); @@ -127,6 +135,8 @@ void Window::createProxyWidgets() m_zoomCheckBox = new QCheckBox(tr("Zoom")); m_scrollCheckBox = new QCheckBox(tr("Scroll")); m_templateComboBox = createTempleteBox(); + m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); + m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); @@ -139,7 +149,6 @@ void Window::createProxyWidgets() m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); - } QComboBox *Window::createThemeBox() @@ -155,6 +164,16 @@ QComboBox *Window::createThemeBox() return themeComboBox; } +QComboBox *Window::createViewBox() +{ + QComboBox *viewComboBox = new ComboBox(this); + viewComboBox->addItem("1 chart", 1); + viewComboBox->addItem("4 charts", 2); + viewComboBox->addItem("9 charts", 3); + viewComboBox->addItem("16 charts", 4); + return viewComboBox; +} + QComboBox *Window::createAnimationBox() { QComboBox *animationComboBox = new ComboBox(this); @@ -235,11 +254,22 @@ void Window::initializeFromParamaters(const QVariantHash& parameters) } } } + if (parameters.contains("view")) { + int t = parameters["view"].toInt(); + for (int i = 0; i < m_viewComboBox->count(); ++i) { + if (m_viewComboBox->itemData(i).toInt() == t) { + + m_viewComboBox->setCurrentIndex(i); + break; + } + } + } } void Window::updateUI() { checkTemplate(); + checkView(); checkOpenGL(); checkTheme(); checkAnimationOptions(); @@ -247,6 +277,12 @@ void Window::updateUI() checkState(); } +void Window::checkView() +{ + int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); + m_grid->setSize(count); +} + void Window::checkLegend() { Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); diff --git a/demos/chartviewer/window.h b/demos/chartviewer/window.h index a9220e7..94178cf 100644 --- a/demos/chartviewer/window.h +++ b/demos/chartviewer/window.h @@ -33,6 +33,7 @@ class View; class QGraphicsLinearLayout; class Chart; class Grid; +class QPushButton; QTCOMMERCIALCHART_BEGIN_NAMESPACE class QChart; @@ -53,6 +54,7 @@ private Q_SLOTS: void handleGeometryChanged(); void handleChartSelected(QChart *chart); private: + QComboBox *createViewBox(); QComboBox *createThemeBox(); QComboBox *createAnimationBox(); QComboBox *createLegendBox(); @@ -61,6 +63,7 @@ private: void createProxyWidgets(); void comboBoxFocused(QComboBox *combox); inline void checkAnimationOptions(); + inline void checkView(); inline void checkLegend(); inline void checkOpenGL(); inline void checkTheme(); @@ -70,11 +73,6 @@ private: QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); void initializeFromParamaters(const QVariantHash& parameters); -protected: - //void mousePressEvent(QMouseEvent *event); - //void mouseMoveEvent(QMouseEvent *event); - //void mouseReleaseEvent(QMouseEvent *event); - private: QGraphicsScene *m_scene; View *m_view; @@ -86,6 +84,7 @@ private: QComboBox *m_animatedComboBox; QComboBox *m_legendComboBox; QComboBox *m_templateComboBox; + QComboBox *m_viewComboBox; QCheckBox *m_openGLCheckBox; QCheckBox *m_zoomCheckBox; QCheckBox *m_scrollCheckBox;