From 3456b7f2ae05692cc923dd6ff8da1f36412adec0 2012-01-16 08:10:38 From: Michal Klocek Date: 2012-01-16 08:10:38 Subject: [PATCH] Initial project refactor, xylinecharts * refactors pro files to include QCHART namespace * removes QWidget dependency * adds xylinechart to library * adds xylinechart example --- diff --git a/charts.pro b/charts.pro index b2ae450..4366d14 100644 --- a/charts.pro +++ b/charts.pro @@ -1,7 +1,11 @@ TEMPLATE = subdirs -SUBDIRS += widget qmlplugin +SUBDIRS += src #qmlplugin + +QMAKE_CXXFLAGS += -g -Wall +QMAKE_DISTCLEAN += -r build # install feature file feature.path = $$[QT_INSTALL_DATA]/mkspecs/features feature.files = $$PWD/features/charts.prf INSTALLS += feature + diff --git a/features/charts.prf b/features/charts.prf index d596701..0032e86 100644 --- a/features/charts.prf +++ b/features/charts.prf @@ -1,9 +1,8 @@ -INCLUDEPATH += $$[QT_INSTALL_HEADERS]/Charts +INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QCharts -contains(CHARTS, widget) { - CONFIG(debug, debug|release) { - LIBS += -lChartWidgetd - } else { - LIBS += -lChartWidget - } +CONFIG(debug, debug|release) { + LIBS += -lQChartd +} else { + LIBS += -lQChart } + diff --git a/src/chart.cpp b/src/chart.cpp deleted file mode 100644 index 83ff0ad..0000000 --- a/src/chart.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "chart.h" - -Chart::Chart() -{ - -} - -Chart::~Chart() -{ - -} - -QColor Chart::color() const -{ - return m_color; -} - -void Chart::setColor(const QColor &color) -{ - m_color = color; -} - -void Chart::drawChart(QPainter *painter, const QRectF& drawRect) -{ - QRectF r = drawRect; - r.adjust(10, 10, -10, -10); - - QPen pen(m_color, 2); - pen.setCapStyle(Qt::RoundCap); - painter->setPen(pen); - painter->setRenderHints(QPainter::Antialiasing, true); - painter->drawLine(r.topLeft(), r.bottomLeft()); - painter->drawLine(r.bottomLeft(), r.bottomRight()); - - painter->drawText(drawRect, "Axis x", QTextOption(Qt::AlignBottom | Qt::AlignHCenter)); - QTransform transform; - transform.translate(drawRect.width(), 0); // works badly if drawrect width != height :) - transform.rotate(90); - painter->setTransform(transform); - painter->drawText(drawRect, "Axis y", QTextOption(Qt::AlignBottom | Qt::AlignHCenter)); - painter->resetTransform(); - - painter->drawText(drawRect, QT_VERSION_STR, QTextOption(Qt::AlignTop | Qt::AlignRight)); - painter->drawText(drawRect, "Insert chart here", QTextOption(Qt::AlignCenter)); - -} diff --git a/src/chart.h b/src/chart.h deleted file mode 100644 index 7855831..0000000 --- a/src/chart.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CHART_H -#define CHART_H -#include -#include -#include - -class QPainter; - -class Chart -{ -public: - Chart(); - virtual ~Chart(); - - QColor color() const; - void setColor(const QColor &color); - - void drawChart(QPainter *painter, const QRectF& drawRect); - -private: - QColor m_color; -}; - -#endif diff --git a/src/chart.pri b/src/chart.pri deleted file mode 100644 index a0267e2..0000000 --- a/src/chart.pri +++ /dev/null @@ -1,2 +0,0 @@ -HEADERS += $$PWD/chart.h -SOURCES += $$PWD/chart.cpp diff --git a/src/qchartconfig.h b/src/qchartconfig.h new file mode 100644 index 0000000..681aaac --- /dev/null +++ b/src/qchartconfig.h @@ -0,0 +1,25 @@ +#ifndef CHARTCONFIG_H +#define CHARTCONFIG_H + +#define QCHART_VERSION_STR "1.0" +#define QCHART_VERSION 0x01 + +#if defined(QCHART_LIBRARY) +# define QCHART_EXPORT Q_DECL_EXPORT +#else +# define QCHART_EXPORT Q_DECL_IMPORT +#endif + +#define QCHART_NAMESPACE QtChart + +#ifdef QCHART_NAMESPACE +# define QCHART_BEGIN_NAMESPACE namespace QCHART_NAMESPACE { +# define QCHART_END_NAMESPACE } +# define QCHART_USE_NAMESPACE using namespace QCHART_NAMESPACE; +#else +# define QCHART_BEGIN_NAMESPACE +# define QCHART_END_NAMESPACE +# define QCHART_USE_NAMESPACE +#endif + +#endif diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..76b3af2 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,43 @@ +TARGET = QChart +TEMPLATE = lib +QT += core \ + gui +CONFIG += debug_and_release +CONFIG(debug, debug|release):TARGET = QChartd +SOURCES += \ + xylinechart/qchartwidget.cpp \ + xylinechart/qchart.cpp \ + xylinechart/qxyseries.cpp \ + xylinechart/axis.cpp \ + xylinechart/xylinechart.cpp \ + xylinechart/xygrid.cpp \ + xylinechart/xyplotdata.cpp + +PRIVATE_HEADERS += \ + xylinechart/xylinechart_p.h \ + xylinechart/axis_p.h \ + xylinechart/xygrid_p.h \ + xylinechart/xyplotdata_p.h + +PUBLIC_HEADERS += \ + xylinechart/qchart.h \ + xylinechart/qxyseries.h \ + xylinechart/qchartwidget.h \ + qchartconfig.h + +HEADERS += $$PUBLIC_HEADERS +HEADERS += $$PRIVATE_HEADERS + +INCLUDEPATH += xylinechart + +OBJECTS_DIR = ../build/lib +MOC_DIR = ../build/lib +UI_DIR = ../build/lib +RCC_DIR = ../build/lib +DEFINES += QCHART_LIBRARY + +public_headers.path = $$[QT_INSTALL_HEADERS]/QCharts +public_headers.files = $$PUBLIC_HEADERS +target.path = $$[QT_INSTALL_LIBS] +INSTALLS += target \ + public_headers diff --git a/widget/chartwidget.cpp b/widget/chartwidget.cpp deleted file mode 100644 index 54f68cd..0000000 --- a/widget/chartwidget.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "chartwidget.h" -#include "../src/chart.h" -#include - -class ChartWidgetPrivate : public Chart -{ -public: - //Q_DECLARE_PUBLIC(ChartWidget) - ChartWidgetPrivate() {} -}; - -ChartWidget::ChartWidget(QWidget *parent) - : QWidget(parent) -{ - d_ptr = new ChartWidgetPrivate(); -} - -ChartWidget::~ChartWidget() -{ - delete d_ptr; - d_ptr = 0; -} - -QColor ChartWidget::color() const -{ - return d_ptr->color(); -} - -void ChartWidget::setColor(const QColor &color) -{ - d_ptr->setColor(color); -} - -void ChartWidget::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - d_ptr->drawChart(&painter, rect()); -} diff --git a/widget/chartwidget.h b/widget/chartwidget.h deleted file mode 100644 index 3ecd186..0000000 --- a/widget/chartwidget.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CHARTWIDGET_H -#define CHARTWIDGET_H - -#include -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) - #include -#else - #include -#endif - -#if defined(CHARTWIDGET_LIBRARY) -# define CHARTWIDGET_EXPORT Q_DECL_EXPORT -#else -# define CHARTWIDGET_EXPORT Q_DECL_IMPORT -#endif - -class ChartWidgetPrivate; - -class CHARTWIDGET_EXPORT ChartWidget : public QWidget -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - explicit ChartWidget(QWidget *parent = 0); - ~ChartWidget(); - - QColor color() const; - void setColor(const QColor &color); - -protected: - virtual void paintEvent(QPaintEvent *); - -private: - Q_DISABLE_COPY(ChartWidget) - Q_DECLARE_PRIVATE(ChartWidget) - ChartWidgetPrivate* d_ptr; -}; - -#endif diff --git a/widget/widget.pro b/widget/widget.pro deleted file mode 100644 index b993c4d..0000000 --- a/widget/widget.pro +++ /dev/null @@ -1,29 +0,0 @@ -TARGET = ChartWidget -TEMPLATE = lib - -QT += core gui -contains(QT_MAJOR_VERSION, 5) { - QT += widgets -} -CONFIG += debug_and_release -CONFIG(debug, debug|release) { - TARGET = ChartWidgetd -} - -SOURCES += \ - chartwidget.cpp -HEADERS += \ - chartwidget.h -include(../src/chart.pri) - -OBJECTS_DIR = tmp -MOC_DIR = tmp - -DEFINES += CHARTWIDGET_LIBRARY - -public_headers.path = $$[QT_INSTALL_HEADERS]/Charts -public_headers.files = chartwidget.h - -target.path=$$[QT_INSTALL_LIBS] - -INSTALLS += target public_headers