added Qt data model that allows to switch all graphs between visible and invisible and shows all graphs in the plot + removed several warnings

This commit is contained in:
jkriege2 2018-08-19 17:03:46 +02:00
parent c8c3b607b1
commit 0f8c308421
8 changed files with 251 additions and 83 deletions

View File

@ -35,7 +35,8 @@
#include <QPrintPreviewWidget> #include <QPrintPreviewWidget>
#include <QDialog> #include <QDialog>
#include "jkqtpbaseplotter.h" #include "jkqtpbaseplotter.h"
#include<QPrinter> #include "jkqtpplotsmodel.h"
#include <QPrinter>
#include <QPrinterInfo> #include <QPrinterInfo>
#include <QPrintDialog> #include <QPrintDialog>
#include <QGridLayout> #include <QGridLayout>
@ -144,7 +145,7 @@ QSizeF JKQtBasePlotter::getTextSizeSize(const QString &fontName, double fontSize
* JKQtPlotterBase * JKQtPlotterBase
**************************************************************************************************************************/ **************************************************************************************************************************/
JKQtBasePlotter::JKQtBasePlotter(bool datastore_internal, QObject* parent, JKQTPdatastore* datast): JKQtBasePlotter::JKQtBasePlotter(bool datastore_internal, QObject* parent, JKQTPdatastore* datast):
QObject(parent) QObject(parent), m_plotsModel(nullptr), xAxis(nullptr), yAxis(nullptr)
{ {
dataColumnsListWidget=NULL; dataColumnsListWidget=NULL;
@ -177,6 +178,8 @@ JKQtBasePlotter::JKQtBasePlotter(bool datastore_internal, QObject* parent, JKQTP
xAxis=new JKQTPhorizontalAxis(this); xAxis=new JKQTPhorizontalAxis(this);
yAxis=new JKQTPverticalAxis(this); yAxis=new JKQTPverticalAxis(this);
m_plotsModel=new JKQTPPlotsModel(this);
connect(this, SIGNAL(plotUpdated()), m_plotsModel, SLOT(plotUpdated()));
emitSignals=false; emitSignals=false;
@ -4090,10 +4093,10 @@ void JKQtBasePlotter::setAllGraphsVisible()
if (emitPlotSignals) emit plotUpdated(); if (emitPlotSignals) emit plotUpdated();
} }
void JKQtBasePlotter::setGraphVisible(int i) void JKQtBasePlotter::setGraphVisible(int i, bool visible)
{ {
JKQTPgraph* g=graphs.value(i, NULL); JKQTPgraph* g=graphs.value(i, NULL);
if (g) g->set_visible(true); if (g) g->set_visible(visible);
if (emitPlotSignals) emit plotUpdated(); if (emitPlotSignals) emit plotUpdated();
} }

View File

@ -68,7 +68,7 @@
#define JKQTPBASEPLOTTER_H #define JKQTPBASEPLOTTER_H
class JKQTPPlotsModel; // forward
/** \brief base class for 2D plotter classes /** \brief base class for 2D plotter classes
@ -207,6 +207,9 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
/** \brief object used for the y-axis */ /** \brief object used for the y-axis */
JKQTPverticalAxis* yAxis; JKQTPverticalAxis* yAxis;
/** \brief model representing all Plots in this plotter and showing their visible/invisible state */
JKQTPPlotsModel* m_plotsModel;
/** \brief filename for the ini file in which to save the user settings /** \brief filename for the ini file in which to save the user settings
* \see jkqtplotter_base_userprops * \see jkqtplotter_base_userprops
*/ */
@ -237,7 +240,7 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
double paintMagnification; double paintMagnification;
/** \brief the decimal separator used when exporting data to text files */ /** \brief the decimal separator used when exporting data to text files */
JKQTPPROPERTY(QString, CSVdecimalSeparator); JKQTPPROPERTY(QString, CSVdecimalSeparator)
/** \brief this string is used to introduce comments in text output when exporting data */ /** \brief this string is used to introduce comments in text output when exporting data */
JKQTPPROPERTY(QString, CSVcommentInitializer) JKQTPPROPERTY(QString, CSVcommentInitializer)
@ -256,7 +259,7 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
/** \brief free space between widget top border and plot top border, this property may be set by the user and is possibly altered /** \brief free space between widget top border and plot top border, this property may be set by the user and is possibly altered
* by the key positioning algorithm. The altered value is written to iplotBorderTop */ * by the key positioning algorithm. The altered value is written to iplotBorderTop */
JKQTPPROPERTY(int, plotBorderTop); JKQTPPROPERTY(int, plotBorderTop)
/** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */ /** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */
int iplotBorderTop; int iplotBorderTop;
int iplotKeyBorderTop; int iplotKeyBorderTop;
@ -264,19 +267,19 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
int iTitleHeight; int iTitleHeight;
/** \brief free space between widget left border and plot left border, this property may be set by the user and is possibly altered /** \brief free space between widget left border and plot left border, this property may be set by the user and is possibly altered
* by the key positioning algorithm. The altered value is written to iplotBorderLeft */ * by the key positioning algorithm. The altered value is written to iplotBorderLeft */
JKQTPPROPERTY(int, plotBorderLeft); JKQTPPROPERTY(int, plotBorderLeft)
/** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */ /** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */
int iplotBorderLeft; int iplotBorderLeft;
int iplotKeyBorderLeft; int iplotKeyBorderLeft;
/** \brief free space between widget bottom border and plot bottom border, this property may be set by the user and is possibly altered /** \brief free space between widget bottom border and plot bottom border, this property may be set by the user and is possibly altered
* by the key positioning algorithm. The altered value is written to iplotBorderBottom */ * by the key positioning algorithm. The altered value is written to iplotBorderBottom */
JKQTPPROPERTY(int, plotBorderBottom); JKQTPPROPERTY(int, plotBorderBottom)
/** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */ /** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */
int iplotBorderBottom; int iplotBorderBottom;
int iplotKeyBorderBottom; int iplotKeyBorderBottom;
/** \brief free space between widget right border and plot right border, this property may be set by the user and is possibly altered /** \brief free space between widget right border and plot right border, this property may be set by the user and is possibly altered
* by the key positioning algorithm. The altered value is written to iplotBorderRight */ * by the key positioning algorithm. The altered value is written to iplotBorderRight */
JKQTPPROPERTY(int, plotBorderRight); JKQTPPROPERTY(int, plotBorderRight)
/** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */ /** \brief free space between widget top border and plot top border, as used to plot the graph (mnay be altered from user input ) */
int iplotBorderRight; int iplotBorderRight;
int iplotKeyBorderRight; int iplotKeyBorderRight;
@ -293,14 +296,14 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
int iplotBorderRight_nographs; int iplotBorderRight_nographs;
/** \brief indicates whether the widget should maintain an aspect ratio of plotwidth and plotheight */ /** \brief indicates whether the widget should maintain an aspect ratio of plotwidth and plotheight */
JKQTPPROPERTY(bool, maintainAspectRatio); JKQTPPROPERTY(bool, maintainAspectRatio)
/** \brief the aspect ratio of plotwidth and plotheight to maintain, if \c maintainAspectRatio==true */ /** \brief the aspect ratio of plotwidth and plotheight to maintain, if \c maintainAspectRatio==true */
JKQTPPROPERTY(double, aspectRatio); JKQTPPROPERTY(double, aspectRatio)
/** \brief indicates whether the axes should maintain an aspect ratio */ /** \brief indicates whether the axes should maintain an aspect ratio */
JKQTPPROPERTY(bool, maintainAxisAspectRatio); JKQTPPROPERTY(bool, maintainAxisAspectRatio)
/** \brief the aspect ratio of axis widths to maintain, if \c maintainAxisAspectRatio==true */ /** \brief the aspect ratio of axis widths to maintain, if \c maintainAxisAspectRatio==true */
JKQTPPROPERTY(double, axisAspectRatio); JKQTPPROPERTY(double, axisAspectRatio)
/** \brief plot width in pixels inside the widget (calculated by calcPlotScaling() from plotBorderLeft, plotBorderRight and widgetWidth) */ /** \brief plot width in pixels inside the widget (calculated by calcPlotScaling() from plotBorderLeft, plotBorderRight and widgetWidth) */
int plotWidth; int plotWidth;
@ -310,16 +313,16 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
/** \brief color of the plotted graph */ /** \brief color of the plotted graph */
JKQTPPROPERTY(QColor, graphColor); JKQTPPROPERTY(QColor, graphColor)
/** \brief colors used in modes where more than one graph is beeing plottet */ /** \brief colors used in modes where more than one graph is beeing plottet */
QColor manyGraphsColor[50]; QColor manyGraphsColor[50];
QColor def_manyGraphsColor[50]; QColor def_manyGraphsColor[50];
/** \brief number of actually defined items in manyGraphsColor */ /** \brief number of actually defined items in manyGraphsColor */
int manyGraphsColorCount; int manyGraphsColorCount;
/** \brief pen styles used in modes where more than one graph is beeing plottet */ /** \brief pen styles used in modes where more than one graph is beeing plottet */
JKQTPPROPERTY(Qt::PenStyle, manyGraphsStyle[5]); JKQTPPROPERTY(Qt::PenStyle, manyGraphsStyle[5])
/** \brief width of the plotted graph (in pixel) */ /** \brief width of the plotted graph (in pixel) */
JKQTPPROPERTY(double, graphWidth); JKQTPPROPERTY(double, graphWidth)
@ -329,64 +332,64 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
/** \brief color of the coordinate system */ /** \brief color of the coordinate system */
JKQTPPROPERTY(QColor, systemColor); JKQTPPROPERTY(QColor, systemColor)
/** \brief width of the coordinate (in pixel) */ /** \brief width of the coordinate (in pixel) */
JKQTPPROPERTY(double, systemWidth); JKQTPPROPERTY(double, systemWidth)
/** \brief color of the background*/ /** \brief color of the background*/
JKQTPPROPERTY(QColor, backgroundColor); JKQTPPROPERTY(QColor, backgroundColor)
/** \brief color of the background when exporting*/ /** \brief color of the background when exporting*/
JKQTPPROPERTY(QColor, exportBackgroundColor); JKQTPPROPERTY(QColor, exportBackgroundColor)
/** \brief color of the plot's background*/ /** \brief color of the plot's background*/
JKQTPPROPERTY(QColor, plotBackgroundColor); JKQTPPROPERTY(QColor, plotBackgroundColor)
/** \brief indicates whether to plot a frame around the key */ /** \brief indicates whether to plot a frame around the key */
JKQTPPROPERTY(bool, showKeyFrame); JKQTPPROPERTY(bool, showKeyFrame)
/** \brief color of the key frame line */ /** \brief color of the key frame line */
JKQTPPROPERTY(QColor, keyFrameColor); JKQTPPROPERTY(QColor, keyFrameColor)
/** \brief width of the key frame line */ /** \brief width of the key frame line */
JKQTPPROPERTY(double, keyFrameWidth); JKQTPPROPERTY(double, keyFrameWidth)
/** \brief color of the key background */ /** \brief color of the key background */
JKQTPPROPERTY(QColor, keyBackgroundColor); JKQTPPROPERTY(QColor, keyBackgroundColor)
/** \brief indicates whether to plot a key */ /** \brief indicates whether to plot a key */
JKQTPPROPERTY(bool, showKey); JKQTPPROPERTY(bool, showKey)
/** \brief font face for key labels */ /** \brief font face for key labels */
JKQTPPROPERTY(QString, keyFont); JKQTPPROPERTY(QString, keyFont)
/** \brief font size for key labels [in points] */ /** \brief font size for key labels [in points] */
JKQTPPROPERTY(double, keyFontSize); JKQTPPROPERTY(double, keyFontSize)
/** \brief width of a key item in pixels [in units of width of 'X' set in keyFont, keyFontSize] */ /** \brief width of a key item in pixels [in units of width of 'X' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, key_item_width); JKQTPPROPERTY(double, key_item_width)
/** \brief height of a key item in pixels [in units of height keyFont, keyFontSize] */ /** \brief height of a key item in pixels [in units of height keyFont, keyFontSize] */
JKQTPPROPERTY(double, key_item_height); JKQTPPROPERTY(double, key_item_height)
/** \brief length of the line samples in the key in pixels [in units of width of 'X' set in keyFont, keyFontSize] */ /** \brief length of the line samples in the key in pixels [in units of width of 'X' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, key_line_length); JKQTPPROPERTY(double, key_line_length)
/** \brief x-distance between key frame and key content [in units of width of 'X' set in keyFont, keyFontSize] */ /** \brief x-distance between key frame and key content [in units of width of 'X' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyXMargin); JKQTPPROPERTY(double, keyXMargin)
/** \brief y-distance between key frame and key content [in units of width of 'x' set in keyFont, keyFontSize] */ /** \brief y-distance between key frame and key content [in units of width of 'x' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyYMargin); JKQTPPROPERTY(double, keyYMargin)
/** \brief x-offset of the key from the border of the plot [in units of width of 'X' set in keyFont, keyFontSize] */ /** \brief x-offset of the key from the border of the plot [in units of width of 'X' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyXOffset); JKQTPPROPERTY(double, keyXOffset)
/** \brief y-offset of the key from the border of the plot [in units of width of 'x' set in keyFont, keyFontSize] */ /** \brief y-offset of the key from the border of the plot [in units of width of 'x' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyYOffset); JKQTPPROPERTY(double, keyYOffset)
/** \brief distance between key line example and key text [in units of width of 'X' set in keyFont, keyFontSize] */ /** \brief distance between key line example and key text [in units of width of 'X' set in keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyXSeparation); JKQTPPROPERTY(double, keyXSeparation)
/** \brief distance between two key entries [in units of height of keyFont, keyFontSize] */ /** \brief distance between two key entries [in units of height of keyFont, keyFontSize] */
JKQTPPROPERTY(double, keyYSeparation); JKQTPPROPERTY(double, keyYSeparation)
/** \brief key position */ /** \brief key position */
JKQTPPROPERTY(JKQTPkeyPosition, keyPosition); JKQTPPROPERTY(JKQTPkeyPosition, keyPosition)
/** \brief the key layout */ /** \brief the key layout */
JKQTPPROPERTY(JKQTPkeyLayout, keyLayout); JKQTPPROPERTY(JKQTPkeyLayout, keyLayout)
/** \brief determine width of the key automatically */ /** \brief determine width of the key automatically */
JKQTPPROPERTY(bool, keyAutosize); JKQTPPROPERTY(bool, keyAutosize)
/** \brief the plot label text */ /** \brief the plot label text */
QString plotLabel; QString plotLabel;
/** \brief the plot label font name */ /** \brief the plot label font name */
JKQTPPROPERTY(QString, plotLabelFontname); JKQTPPROPERTY(QString, plotLabelFontname)
/** \brief the plot label font size */ /** \brief the plot label font size */
JKQTPPROPERTY(double, plotLabelFontSize); JKQTPPROPERTY(double, plotLabelFontSize)
/** \brief calculate the scaling and offset values from axis min/max values */ /** \brief calculate the scaling and offset values from axis min/max values */
void calcPlotScaling(JKQTPEnhancedPainter& painter); void calcPlotScaling(JKQTPEnhancedPainter& painter);
@ -398,20 +401,20 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
bool emitSignals; bool emitSignals;
/** \brief specifies whether to use antialiasing for plotting the coordinate system */ /** \brief specifies whether to use antialiasing for plotting the coordinate system */
JKQTPPROPERTY(bool, useAntiAliasingForSystem); JKQTPPROPERTY(bool, useAntiAliasingForSystem)
/** \brief specifies whether to use antialiasing for plotting the graphs /** \brief specifies whether to use antialiasing for plotting the graphs
* *
* \note You can set this property \c false to increase plotting speed of complex plots (with many graphs inside). You can reach a * \note You can set this property \c false to increase plotting speed of complex plots (with many graphs inside). You can reach a
* roughly three-fold speed improvement! * roughly three-fold speed improvement!
*/ */
JKQTPPROPERTY(bool, useAntiAliasingForGraphs); JKQTPPROPERTY(bool, useAntiAliasingForGraphs)
/** \brief specifies whether to use antialiasing when drawing any text /** \brief specifies whether to use antialiasing when drawing any text
* \note You can set this property \c false to increase plotting speed of complex plots (with many graphs inside). You can reach a * \note You can set this property \c false to increase plotting speed of complex plots (with many graphs inside). You can reach a
* roughly three-fold speed improvement! * roughly three-fold speed improvement!
*/ */
JKQTPPROPERTY(bool, useAntiAliasingForText); JKQTPPROPERTY(bool, useAntiAliasingForText)
/** \brief multiplier which is used for font sizes when the plot is exported/printed */ /** \brief multiplier which is used for font sizes when the plot is exported/printed */
double fontSizePrintMultiplier; double fontSizePrintMultiplier;
@ -442,7 +445,7 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
/** \brief hidden default constructor */ /** \brief hidden default constructor */
JKQtBasePlotter() {}; JKQtBasePlotter() {}
@ -752,7 +755,10 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
virtual ~JKQtBasePlotter(); virtual ~JKQtBasePlotter();
/** \brief returns a pointer to the datastore used by this object */ /** \brief returns a pointer to the datastore used by this object */
inline JKQTPdatastore* getDatastore() { return datastore; }; inline JKQTPdatastore* getDatastore() { return datastore; }
/** \brief returns model representing all Plots in this plotter and showing their visible/invisible state */
inline JKQTPPlotsModel* getPlotsModel() { return m_plotsModel; }
/** \brief tells the plotter object to use the given external datastore. /** \brief tells the plotter object to use the given external datastore.
* *
@ -806,10 +812,10 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
void resize(int width, int height); void resize(int width, int height);
/** \brief gets the width of the plot widget */ /** \brief gets the width of the plot widget */
inline int getWidth() {return widgetWidth; }; inline int getWidth() {return widgetWidth; }
/** \brief gets the width of the plot widget */ /** \brief gets the width of the plot widget */
inline int getHeight() {return widgetHeight; }; inline int getHeight() {return widgetHeight; }
/** \brief sets the width of the plot widget */ /** \brief sets the width of the plot widget */
void setHeight(int heigh); void setHeight(int heigh);
@ -827,16 +833,16 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
void setXY(double xminn, double xmaxx, double yminn, double ymaxx); void setXY(double xminn, double xmaxx, double yminn, double ymaxx);
/** \brief returns the current x-axis min */ /** \brief returns the current x-axis min */
inline double getXMin() const {return xAxis->getMin(); }; inline double getXMin() const {return xAxis->getMin(); }
/** \brief returns the current x-axis max */ /** \brief returns the current x-axis max */
inline double getXMax() const {return xAxis->getMax(); }; inline double getXMax() const {return xAxis->getMax(); }
/** \brief returns the current y-axis min */ /** \brief returns the current y-axis min */
inline double getYMin() const {return yAxis->getMin(); }; inline double getYMin() const {return yAxis->getMin(); }
/** \brief returns the current y-axis max */ /** \brief returns the current y-axis max */
inline double getYMax() const {return yAxis->getMax(); }; inline double getYMax() const {return yAxis->getMax(); }
@ -1121,7 +1127,7 @@ class LIB_EXPORT JKQtBasePlotter: public QObject {
void setAllGraphsInvisible(); void setAllGraphsInvisible();
void setAllGraphsVisible(); void setAllGraphsVisible();
void setGraphVisible(int i); void setGraphVisible(int i, bool visible=true);
/** \brief add a new graph, returns it's position in the graphs list, if the graph is already in the plot, this returns the index in the list */ /** \brief add a new graph, returns it's position in the graphs list, if the graph is already in the plot, this returns the index in the list */
size_t addGraph(JKQTPgraph* gr); size_t addGraph(JKQTPgraph* gr);

View File

@ -16,7 +16,8 @@ HEADERS += $$PWD/jkqtpbaseplotter.h \
$$PWD/jkqtpoverlayelements.h \ $$PWD/jkqtpoverlayelements.h \
$$PWD/jkqtpgeoelements.h \ $$PWD/jkqtpgeoelements.h \
$$PWD/jkqtpmathparser.h \ $$PWD/jkqtpmathparser.h \
$$PWD/jkqtp_imexport.h $$PWD/jkqtp_imexport.h \
$$PWD/jkqtpplotsmodel.h
SOURCES += $$PWD/jkqtpbaseplotter.cpp \ SOURCES += $$PWD/jkqtpbaseplotter.cpp \
@ -32,7 +33,8 @@ SOURCES += $$PWD/jkqtpbaseplotter.cpp \
$$PWD/jkqtpparsedfunctionelements.cpp \ $$PWD/jkqtpparsedfunctionelements.cpp \
$$PWD/jkqtpoverlayelements.cpp \ $$PWD/jkqtpoverlayelements.cpp \
$$PWD/jkqtpgeoelements.cpp \ $$PWD/jkqtpgeoelements.cpp \
$$PWD/jkqtpmathparser.cpp $$PWD/jkqtpmathparser.cpp \
$$PWD/jkqtpplotsmodel.cpp
RESOURCES += $$PWD/jkqtpbaseplotter.qrc RESOURCES += $$PWD/jkqtpbaseplotter.qrc

89
jkqtpplotsmodel.cpp Normal file
View File

@ -0,0 +1,89 @@
/*
Copyright (c) 2008-2018 Jan W. Krieger (<jan@jkrieger.de>, <j.krieger@dkfz.de>), German Cancer Research Center
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file jkqtpplotsmodel.cpp
* \ingroup jkqtpbaseplotter
*/
#include "jkqtpplotsmodel.h"
#include "jkqtpbaseplotter.h"
#include "jkqtptools.h"
#include <QImage>
JKQTPPlotsModel::JKQTPPlotsModel(JKQtBasePlotter *parent):
QAbstractTableModel(parent), m_plotter(parent)
{
}
int JKQTPPlotsModel::rowCount(const QModelIndex &/*parent*/) const
{
return static_cast<int>(m_plotter->getGraphCount());
}
int JKQTPPlotsModel::columnCount(const QModelIndex &/*parent*/) const
{
return 1;
}
QVariant JKQTPPlotsModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole) {
if (index.row()<m_plotter->getGraphCount()) return m_plotter->getGraph(index.row())->get_title();
} else if (role == Qt::CheckStateRole) {
if (index.row()<m_plotter->getGraphCount()) return m_plotter->getGraph(index.row())->get_visible()?Qt::Checked:Qt::Unchecked;
} else if (role == Qt::DecorationRole) {
if (index.row()<m_plotter->getGraphCount()) {
QImage img(16,16,QImage::Format_ARGB32);
{
JKQTPEnhancedPainter painter(&img);
QRectF rect(0,0,16,16);
m_plotter->getGraph(index.row())->drawKeyMarker(painter, rect);
}
return img;
}
}
return QVariant();
}
bool JKQTPPlotsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role == Qt::CheckStateRole) {
if (index.row()<m_plotter->getGraphCount()) {
m_plotter->setGraphVisible(index.row(), value.toBool());
return true;
}
}
return false;
}
Qt::ItemFlags JKQTPPlotsModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsUserCheckable | QAbstractTableModel::flags(index);
}
void JKQTPPlotsModel::plotUpdated()
{
beginResetModel();
endResetModel();
}

60
jkqtpplotsmodel.h Normal file
View File

@ -0,0 +1,60 @@
/*
Copyright (c) 2008-2018 Jan W. Krieger (<jan@jkrieger.de>, <j.krieger@dkfz.de>), German Cancer Research Center (DKFZ) & IWR, University of Heidelberg
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \defgroup jkqtpplotsmodel data model with all plots ina JKQtBasePlotter (+ allows to switch them visible/invisible)
* \ingroup jkqtpbaseplotter
*
*
*/
/** \file jkqtpplotsmodel.h
* \ingroup jkqtpbaseplotter
*/
#ifndef JKQTPPLOTSMODEL_H
#define JKQTPPLOTSMODEL_H
#include "jkqtpbaseplotter.h"
#include "jkqtp_imexport.h"
#include <QAbstractTableModel>
class JKQtBasePlotter; // forward
/** \brief data model with all plots ina JKQtBasePlotter (+ allows to switch them visible/invisible) */
class JKQTPPlotsModel : public QAbstractTableModel
{
Q_OBJECT
public:
JKQTPPlotsModel(JKQtBasePlotter *parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const override ;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex & index) const override ;
public slots:
void plotUpdated();
private:
JKQtBasePlotter* m_plotter;
};
#endif // JKQTPPLOTSMODEL_H

View File

@ -151,24 +151,24 @@
inline virtual void set_##varname (const typedef_set_##varname & __value) \ inline virtual void set_##varname (const typedef_set_##varname & __value) \
{ \ { \
this->varname = __value; \ this->varname = __value; \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; }
#define JKQTPGET_SET_VMACRO(type,varname) \ #define JKQTPGET_SET_VMACRO(type,varname) \
typedef type typedef_set_##varname ;\ typedef type typedef_set_##varname ;\
/** \brief sets the property varname to the specified \a __value. \details Description of the parameter varname is: <CENTER>\copybrief varname.</CENTER> \see varname for more information */ \ /** \brief sets the property varname to the specified \a __value. \details Description of the parameter varname is: <CENTER>\copybrief varname.</CENTER> \see varname for more information */ \
inline virtual void set_##varname (const typedef_set_##varname & __value) \ inline virtual void set_##varname (const typedef_set_##varname & __value) \
{ \ { \
this->varname = __value; \ this->varname = __value; \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; }
#define JKQTPGetSetMacro(type,varname) JKQTPGET_SET_MACRO(type,varname) #define JKQTPGetSetMacro(type,varname) JKQTPGET_SET_MACRO(type,varname)
/** /**
@ -184,11 +184,11 @@
{ \ { \
this->varname = __value; \ this->varname = __value; \
this-> paramsChanged=true; \ this-> paramsChanged=true; \
}; \ } \
inline virtual type get_##varname () const /** \brief returns the property varname. \see varname for more information */ \ inline virtual type get_##varname () const /** \brief returns the property varname. \see varname for more information */ \
{\ {\
return this->varname; \ return this->varname; \
}; }
#define JKQTPGetSetMacroP(type,varname) JKQTPGET_SET_MACRO_P(type,varname) #define JKQTPGetSetMacroP(type,varname) JKQTPGET_SET_MACRO_P(type,varname)
/** /**
@ -205,12 +205,12 @@
this-> paramsChanged=true; \ this-> paramsChanged=true; \
inst; \ inst; \
} \ } \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{ \ { \
return this->varname; \ return this->varname; \
}; }
#define JKQTPGetSetMacroIP(type,varname,inst) JKQTPGET_SET_MACRO_IP(type,varname,inst) #define JKQTPGetSetMacroIP(type,varname,inst) JKQTPGET_SET_MACRO_IP(type,varname,inst)
/** /**
@ -226,12 +226,12 @@
this->varname = __value; \ this->varname = __value; \
inst; \ inst; \
} \ } \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; }
#define JKQTPGetSetMacroI(type,varname,inst) JKQTPGET_SET_MACRO_I(type,varname,inst) #define JKQTPGetSetMacroI(type,varname,inst) JKQTPGET_SET_MACRO_I(type,varname,inst)
/** /**
@ -249,17 +249,17 @@
if (this->varname2 != __value2) { \ if (this->varname2 != __value2) { \
this->varname2 = __value2; \ this->varname2 = __value2; \
} \ } \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; \ } \
/** \brief returns the property varname2. \see varname2 for more information */\ /** \brief returns the property varname2. \see varname2 for more information */\
inline virtual type2 get_##varname2 () const \ inline virtual type2 get_##varname2 () const \
{\ {\
return this->varname2; \ return this->varname2; \
}; }
#define JKQTPGetSetMacroTwo(name,type,varname,type2,varname2) JKQTPGET_SET_MACRO_TWO(name,type,varname,type2,varname2) #define JKQTPGetSetMacroTwo(name,type,varname,type2,varname2) JKQTPGET_SET_MACRO_TWO(name,type,varname,type2,varname2)
/** /**
@ -282,17 +282,17 @@
if (set) { \ if (set) { \
inst; \ inst; \
} \ } \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; \ } \
/** \brief returns the property varname2. \see varname2 for more information */ \ /** \brief returns the property varname2. \see varname2 for more information */ \
inline virtual type2 get_##varname2 () const \ inline virtual type2 get_##varname2 () const \
{\ {\
return this->varname2; \ return this->varname2; \
}; }
#define JKQTPGetSetMacroTwoI(name,type,varname,type2,varname2,inst) JKQTPGET_SET_MACRO_TWO_I(name,type,varname,type2,varname2,inst) #define JKQTPGetSetMacroTwoI(name,type,varname,type2,varname2,inst) JKQTPGET_SET_MACRO_TWO_I(name,type,varname,type2,varname2,inst)
@ -308,12 +308,12 @@
{\ {\
this->varname = __value; \ this->varname = __value; \
inst; \ inst; \
}; \ } \
/** \brief returns the property varname. \see varname for more information */ \ /** \brief returns the property varname. \see varname for more information */ \
inline virtual type get_##varname () const \ inline virtual type get_##varname () const \
{\ {\
return this->varname; \ return this->varname; \
}; }
#define JKQTPGetSetMacroINC(type,varname,inst) JKQTPGET_SET_MACRO_INC(type,varname,inst) #define JKQTPGetSetMacroINC(type,varname,inst) JKQTPGET_SET_MACRO_INC(type,varname,inst)
/** \brief create get_varname() and set_varname(type __value) methods/functions /** \brief create get_varname() and set_varname(type __value) methods/functions
@ -324,7 +324,7 @@
#define JKQTPGET_MACRO(type,varname) \ #define JKQTPGET_MACRO(type,varname) \
/** \brief returns the property varname. \details Description of the parameter varname is: <CENTER>\copybrief varname.</CENTER>. \see varname for more information */ \ /** \brief returns the property varname. \details Description of the parameter varname is: <CENTER>\copybrief varname.</CENTER>. \see varname for more information */ \
inline virtual type get_##varname() const \ inline virtual type get_##varname() const \
{ return this->varname; }; { return this->varname; }
#define JKQTPGetMacro(type,varname) JKQTPGET_MACRO(type,varname) #define JKQTPGetMacro(type,varname) JKQTPGET_MACRO(type,varname)
@ -340,7 +340,7 @@
inline virtual void set_##varname (const typedef_set_##varname & __value) \ inline virtual void set_##varname (const typedef_set_##varname & __value) \
{ \ { \
this->varname = __value; \ this->varname = __value; \
}; }
#define JKQTPSetMacro(type,varname) JKQTPSET_MACRO(type,varname) #define JKQTPSetMacro(type,varname) JKQTPSET_MACRO(type,varname)
/** /**
@ -359,7 +359,7 @@
this->varname = __value; \ this->varname = __value; \
this->paramsChanged=true; \ this->paramsChanged=true; \
} \ } \
}; }
#define JKQTPSetMacroP(type,varname) JKQTPSET_MACRO_P(type,varname) #define JKQTPSetMacroP(type,varname) JKQTPSET_MACRO_P(type,varname)
/** /**
@ -375,7 +375,7 @@
this->varname = __value; \ this->varname = __value; \
inst; \ inst; \
} \ } \
}; }
#define JKQTPSetMacroI(type,varname,inst) JKQTPSET_MACRO_I(type,varname,inst) #define JKQTPSetMacroI(type,varname,inst) JKQTPSET_MACRO_I(type,varname,inst)
/** /**
@ -391,7 +391,7 @@
if (this->varname != __value) { \ if (this->varname != __value) { \
this->varname = __value; \ this->varname = __value; \
} \ } \
}; }
#define JKQTPSetMacroIBefore(type,varname,inst) JKQTPSET_MACRO_I_BEFORE(type,varname,inst) #define JKQTPSetMacroIBefore(type,varname,inst) JKQTPSET_MACRO_I_BEFORE(type,varname,inst)
/** /**
* \brief like SetMacroP(), but adds the instruction \a inst to the set method. This may be used * \brief like SetMacroP(), but adds the instruction \a inst to the set method. This may be used
@ -407,7 +407,7 @@
this->paramsChanged=true; \ this->paramsChanged=true; \
inst; \ inst; \
} \ } \
}; }
#define JKQTPSetMacroIP(type,varname,inst) JKQTPSET_MACRO_IP(type,varname,inst) #define JKQTPSetMacroIP(type,varname,inst) JKQTPSET_MACRO_IP(type,varname,inst)
/*@}*/ /*@}*/

View File

@ -51,9 +51,16 @@ TestMain::TestMain(QWidget *parent) :
plotBot->get_plotter()->set_userSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot/"); plotBot->get_plotter()->set_userSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot/");
plotBot2->get_plotter()->set_userSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot/"); plotBot2->get_plotter()->set_userSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot/");
QListView* listPlots=new QListView(win);
listPlots->setModel(plot->get_plotter()->getPlotsModel());
listPlots->setMaximumWidth(256);
QVBoxLayout* layout=new QVBoxLayout(win); QVBoxLayout* layout=new QVBoxLayout(win);
layout->addWidget(plot); QGridLayout* layout_grid=new QGridLayout(win);
layout->addWidget(plotBot); layout_grid->addWidget(plot,0,0,1,1);
layout_grid->addWidget(plotBot,1,0,1,1);
layout_grid->addWidget(listPlots,0,1,1,1);
layout_grid->setColumnStretch(0,1);
layout->addLayout(layout_grid);
layout->addWidget(plotBot2); layout->addWidget(plotBot2);
win->setLayout(layout); win->setLayout(layout);
win->resize(1000, 800); win->resize(1000, 800);

View File

@ -16,6 +16,7 @@
#include "../../jkqtpoverlayelements.h" #include "../../jkqtpoverlayelements.h"
#include "../../jkqtpparsedfunctionelements.h" #include "../../jkqtpparsedfunctionelements.h"
#include "../../jkqtpbaseelements.h" #include "../../jkqtpbaseelements.h"
#include "../../jkqtpplotsmodel.h"
#include "../../jkqtptools.h" #include "../../jkqtptools.h"
#define N1 200 #define N1 200