Commit 34135941 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Adding options for QCPCurve.

parent a574318d
Pipeline #6578 skipped
......@@ -1561,8 +1561,226 @@ void GraphPropertyManager::scatterStyleChanged( QtProperty *property, int value
// update graph's scatter style, replot
graph->setScatterStyle( ss );
graph->parentPlot()->replot();
} // GraphPropertyManager::scatterStyleChanged
QStringList CurvePropertyManager::lineStyleNames;
QStringList CurvePropertyManager::penNames;
QStringList CurvePropertyManager::scatterNames;
QMap<int, QIcon> CurvePropertyManager::scatterIcons;
CurvePropertyManager::CurvePropertyManager( QObject *parent )
: QObject( parent )
{
initEnums();
}
void CurvePropertyManager::initEnums()
{
// only init helpers once
static bool first = true;
// no-op
if( !first )
{
return;
}
// ensure init doesn't happen again
first = false;
// pen types; skipping "No Pen" options so we will need to adjust +1
penNames << "Solid"
<< "Dash"
<< "Dot"
<< "DashDot"
<< "DashDotDot";
// scatter styles
scatterNames << "None"
<< "Dot"
<< "Cross"
<< "Plus"
<< "Circle"
<< "Disc"
<< "Square"
<< "Diamond"
<< "Star"
<< "Triangle"
<< "TriangleInverted"
<< "CrossSquare"
<< "PlusSquare"
<< "CrossCircle"
<< "PlusCircle"
<< "Peace";
for( int i = 0, ie = scatterNames.size(); i < ie; i++ )
{
scatterIcons.insert( i, QIcon( QString( ":/radix/plot/images/ss%1.png" )
.arg( scatterNames[i] ) ) );
}
}
void CurvePropertyManager::lineColorChanged( QtProperty *property, QColor color )
{
// graph's current pen
auto pen = curve->pen();
// update pen color, update graph's pen, replot
pen.setColor( color );
curve->setPen( pen );
curve->parentPlot()->replot();
}
void CurvePropertyManager::lineWeightChanged( QtProperty *property, int value )
{
// graph's current pen
auto pen = curve->pen();
// update pen width, update graph's pen, replot
pen.setWidth( value );
curve->setPen( pen );
curve->parentPlot()->replot();
}
void CurvePropertyManager::manage(
QtAbstractPropertyBrowser *pb
, QtAbstractPropertyManager* pm
, QCPCurve *curve )
{
// property manager
auto gpm = new CurvePropertyManager( pm );
gpm->curve = curve;
// property editor factories
auto colorEditor = new QtColorEditorFactory( gpm );
auto doubleSpinBoxEditor = new QtDoubleSpinBoxFactory( gpm );
auto enumEditor = new QtEnumEditorFactory( gpm );
auto lineEditEditor = new QtLineEditFactory( gpm );
auto spinBoxEditor = new QtSpinBoxFactory( gpm );
// property managers
auto lineColor = new QtColorPropertyManager( gpm );
auto lineWeight = new QtIntPropertyManager( gpm );
auto name = new QtStringPropertyManager( gpm );
auto penStyle = new QtEnumPropertyManager( gpm );
auto scatterSize = new QtDoublePropertyManager( gpm );
auto scatterStyle = new QtEnumPropertyManager( gpm );
// Register property managers and factory for browser
pb->setFactoryForManager( lineColor, colorEditor );
pb->setFactoryForManager( lineWeight, spinBoxEditor );
pb->setFactoryForManager( name, lineEditEditor );
pb->setFactoryForManager( penStyle, enumEditor );
pb->setFactoryForManager( scatterStyle, enumEditor );
pb->setFactoryForManager( scatterSize, doubleSpinBoxEditor );
// Create selectable item displaying name
auto property = pm->addProperty( curve->name() );
// Create graph name property
auto subprop = name->addProperty( "Name" );
name->setValue( subprop, curve->name() );
property->addSubProperty( subprop );
// Create subproperty for line color
subprop = lineColor->addProperty( "Line Color" );
lineColor->setValue( subprop, curve->pen().color() );
property->addSubProperty( subprop );
// Create subproperty for line weight
subprop = lineWeight->addProperty( "Line Weight" );
lineWeight->setRange( subprop, 0, 10 );
lineWeight->setValue( subprop, curve->pen().width() );
property->addSubProperty( subprop );
// Create subproperty for scatter style
subprop = scatterStyle->addProperty( "Scatter Style" );
scatterStyle->setEnumNames( subprop, scatterNames );
scatterStyle->setEnumIcons( subprop, scatterIcons );
scatterStyle->setValue( subprop, curve->scatterStyle().shape() );
property->addSubProperty( subprop );
// Create subproperty for scatter size
subprop = scatterSize->addProperty( "Scatter Size" );
scatterSize->setRange( subprop, 1, 50 );
scatterSize->setValue( subprop, curve->scatterStyle().size() );
property->addSubProperty( subprop );
// Create subproperty for pen style
subprop = penStyle->addProperty( "Pen Style" );
penStyle->setEnumNames( subprop, penNames );
// we must subtract 1 to adjust to missing "No Pen"
penStyle->setValue( subprop, curve->pen().style() - 1 );
property->addSubProperty( subprop );
// connect signals/slots
connect( lineColor, SIGNAL( valueChanged( QtProperty*, QColor ) ),
gpm, SLOT( lineColorChanged( QtProperty*, QColor ) ) );
connect( lineWeight, SIGNAL( valueChanged( QtProperty*, int ) ),
gpm, SLOT( lineWeightChanged( QtProperty*, int ) ) );
connect( name, SIGNAL( valueChanged( QtProperty*, QString ) ),
gpm, SLOT( nameChanged( QtProperty*, QString ) ) );
connect( penStyle, SIGNAL( valueChanged( QtProperty*, int ) ),
gpm, SLOT( penStyleChanged( QtProperty*, int ) ) );
connect( scatterSize, SIGNAL( valueChanged( QtProperty*, double ) ),
gpm, SLOT( scatterSizeChanged( QtProperty*, double ) ) );
connect( scatterStyle, SIGNAL( valueChanged( QtProperty*, int ) ),
gpm, SLOT( scatterStyleChanged( QtProperty*, int ) ) );
// add property to browser
pb->addProperty( property );
}
void CurvePropertyManager::nameChanged( QtProperty *property, QString value )
{
curve->setName( value );
curve->parentPlot()->replot();
}
void CurvePropertyManager::penStyleChanged( QtProperty *property, int value )
{
// graph's current pen
auto pen = curve->pen();
// We must add 1 to adjust to the missing "No Pen" option
// update pen's style, update graph's pen, replot
pen.setStyle( static_cast<Qt::PenStyle>( value + 1 ) );
curve->setPen( pen );
curve->parentPlot()->replot();
}
void CurvePropertyManager::scatterSizeChanged( QtProperty *property, double value )
{
// graph's current scatter style
QCPScatterStyle style = curve->scatterStyle();
// update scatter style's size, update graph's scatter style, replot
style.setSize( value );
curve->setScatterStyle( style );
curve->parentPlot()->replot();
}
void CurvePropertyManager::scatterStyleChanged( QtProperty *property, int value )
{
// new scatter style with current size
QCPScatterStyle ss( static_cast<QCPScatterStyle::ScatterShape>( value ),
curve->scatterStyle().size() );
// update graph's scatter style, replot
curve->setScatterStyle( ss );
curve->parentPlot()->replot();
}
LegendPropertyManager::LegendPropertyManager( QObject *parent )
: QObject( parent )
{
......@@ -1870,6 +2088,53 @@ void PlotOptionDialog::initGraphProperties()
sectionContentWidget->addWidget( tpb );
}
void PlotOptionDialog::initCurveProperties()
{
// plot
auto qcp = plot->qcp();
// list of curves
QList<QCPCurve*> cms;
// populate list of color maps
for( auto i = 0, ie = qcp->plottableCount(); i < ie; i++ )
{
if( auto cm = qobject_cast<QCPCurve*>( qcp->plottable( i ) ) )
{
cms << cm;
}
}
// no color maps
if( cms.isEmpty() )
{
return;
}
// sections model
auto sectionModel = qobject_cast<QStandardItemModel*>( sectionsView->model() );
// section navigation item
sectionModel->appendRow( new QStandardItem( QString( "Curves (%1)" )
.arg( cms.size() ) ) );
// Create property browser for this section
auto tpb = new QtTreePropertyBrowser();
// group property manager
auto gpm = new QtGroupPropertyManager( this );
// init properties for each color map
for( auto cm : cms )
{
// manage color map
CurvePropertyManager::manage( tpb, gpm, cm );
}
// Add browser to section content widget
sectionContentWidget->addWidget( tpb );
}
void PlotOptionDialog::initLayout()
{
// content scroll area
......@@ -1910,6 +2175,7 @@ void PlotOptionDialog::initLayout()
initLegendProperties();
initAxisProperties();
initGraphProperties();
initCurveProperties();
initColorMapProperties();
initBarsProperties();
......
......@@ -426,6 +426,46 @@ private:
static QMap<int, QIcon> scatterIcons;
};
class CurvePropertyManager : public QObject
{
Q_OBJECT
public:
static void manage(
QtAbstractPropertyBrowser *pb
, QtAbstractPropertyManager *pm
, QCPCurve *curve );
private slots:
void lineColorChanged( QtProperty *property, QColor color );
void lineWeightChanged( QtProperty *property, int value );
void nameChanged( QtProperty *property, QString value );
void penStyleChanged( QtProperty *property, int value );
void scatterSizeChanged( QtProperty *property, double value );
void scatterStyleChanged( QtProperty *property, int value );
private:
CurvePropertyManager( QObject *parent = nullptr );
static void initEnums();
QCPCurve *curve;
static QStringList lineStyleNames;
static QStringList penNames;
static QStringList scatterNames;
static QMap<int, QIcon> scatterIcons;
};
class LegendPropertyManager : public QObject
{
Q_OBJECT
......@@ -489,6 +529,8 @@ private:
void initGraphProperties();
void initCurveProperties();
void initLayout();
void initLegendProperties();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment