Commit a214a691 authored by Julien Wintz's avatar Julien Wintz
Browse files

Merge branch 'develop' of gitlab.inria.fr:dtk/dtk-visualization into develop

parents 8dde4984 fb28c437
......@@ -65,9 +65,9 @@ int main(int argc, char **argv)
// ///////////////////////////////////////////////////////////////////
dtkVisualizationPlot2D *plot = new dtkVisualizationPlot2D;
plot->setWindowTitle("dtkVisualizationPlot2D");
plot->addField(field_1);
plot->addField(field_2, true, vtkChart::LINE, vtkPlotPoints::NONE);
plot->addField(field_3);
plot->addFieldX(field_1);
plot->addFieldY(field_2, true, vtkChart::LINE, vtkPlotPoints::NONE);
plot->addFieldY(field_3);
plot->show();
plot->raise();
plot->render();
......@@ -78,6 +78,8 @@ int main(int argc, char **argv)
qDebug() << plot->fields();
plot->addFieldX(field_3);
plot->removeField("third_field");
// ///////////////////////////////////////////////////////////////////
return application.exec();
......
......@@ -88,13 +88,18 @@ public:
dtkWidgetsHUD *hud;
dtkWidgetsOverlayPane *overlay;
struct FieldParameters {
int chart_type;
int marker_style;
int width;
QColor color;
};
public:
QComboBox *field_x;
QListWidget *field_y;
QStringListModel *fields_table_model;
QMap<QString, int> chart_type;
QMap<QString, QColor> fields_color;
QMap<QString, int> marker_style;
QMap<QString, FieldParameters> fields_parameters;
bool show_legend = true;
};
......@@ -312,16 +317,17 @@ void dtkVisualizationPlot2D::render(void)
for(int row=0; row < d->field_y->count(); ++row) {
if(d->field_y->item(row)->checkState() == Qt::Checked) {
int chart_type = d->chart_type[d->field_y->item(row)->text()];
vtkPlot *points = d->chart->AddPlot(chart_type);
dtkVisualizationPlot2DPrivate::FieldParameters param = d->fields_parameters[d->field_y->item(row)->text()];
vtkPlot *points = d->chart->AddPlot(param.chart_type);
points->SetInputData(d->fields_table,
d->field_x->currentText().toStdString(),
d->field_y->item(row)->text().toStdString());
QColor color = d->fields_color[d->field_y->item(row)->text()];
points->SetColor(color.red(), color.green(), color.blue(), 255);
points->SetColor(param.color.red(), param.color.green(), param.color.blue(), 255);
points->GetBrush()->SetColor(255, 64, 64);
points->SetWidth(1.0);
vtkPlotPoints::SafeDownCast(points)->SetMarkerStyle(d->marker_style[d->field_y->item(row)->text()]);
points->SetWidth(param.width);
vtkPlotPoints::SafeDownCast(points)->SetMarkerStyle(param.marker_style);
}
}
......@@ -333,28 +339,53 @@ QStringList dtkVisualizationPlot2D::fields(void)
return d->fields_table_model->stringList();
}
void dtkVisualizationPlot2D::addField(vtkSmartPointer<vtkAbstractArray> field, bool checked, int chart_type, int marker_style)
void dtkVisualizationPlot2D::addFieldX(vtkSmartPointer<vtkAbstractArray> field)
{
d->fields_table->AddColumn(field);
d->field_x->addItem(field->GetName());
d->field_x->model()->sort(0);
}
void dtkVisualizationPlot2D::addFieldY(vtkSmartPointer<vtkAbstractArray> field,
bool checked,
int chart_type,
int marker_style,
QColor color,
int width)
{
Q_ASSERT_X(chart_type >= 0 && chart_type < 7, "setChartType", "0: Line , 1: Points , 2: Bar , 3: Stacked , 4: Bag , 5: functionalBag , 6: Area -> as in vtkPlot");
Q_ASSERT_X(marker_style >= 0 && marker_style < 6, "setMarkerStyle", "NONE , CROSS , PLUS , SQUARE , CIRCLE , DIAMOND ");
d->fields_table->AddColumn(field);
d->chart_type[field->GetName()] = chart_type;
d->fields_color[field->GetName()] = d->random();
d->marker_style[field->GetName()] = marker_style;
d->field_x->addItem(field->GetName());
dtkVisualizationPlot2DPrivate::FieldParameters param;
param.chart_type = chart_type;
param.marker_style = marker_style;
param.width = width;
if(color == Qt::transparent) {
param.color = d->random();
} else {
param.color = color;
}
d->fields_parameters[field->GetName()] = param;
QListWidgetItem *new_field_item = new QListWidgetItem(field->GetName(), d->field_y);
new_field_item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
new_field_item->setCheckState(Qt::Unchecked);
new_field_item->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
d->field_x->model()->sort(0);
d->field_y->sortItems();
this->render();
}
void dtkVisualizationPlot2D::addField(vtkSmartPointer<vtkAbstractArray> field, bool checked, int chart_type, int marker_style)
{
this->addFieldX(field);
this->addFieldY(field, checked, chart_type, marker_style);
}
void dtkVisualizationPlot2D::removeField(vtkSmartPointer<vtkAbstractArray> field)
{
this->removeField(field->GetName());
......@@ -363,17 +394,12 @@ void dtkVisualizationPlot2D::removeField(vtkSmartPointer<vtkAbstractArray> field
void dtkVisualizationPlot2D::removeField(const QString& field)
{
int idx = d->field_x->findText(field);
Q_ASSERT(idx > 0);
d->field_x->removeItem(idx);
if(idx > 0) {
d->field_x->removeItem(idx);
}
qDeleteAll(d->field_y->findItems(field, Qt::MatchFixedString));
d->chart_type.remove(field);
d->fields_color.remove(field);
d->marker_style.remove(field);
d->fields_parameters.remove(field);
d->fields_table->RemoveColumnByName(field.toStdString().c_str());
}
......
......@@ -50,7 +50,14 @@ public:
QStringList fields(void);
public:
void addField(vtkSmartPointer<vtkAbstractArray>, bool checked = false, int type = vtkChart::POINTS, int marker_style = vtkPlotPoints::PLUS);
[[deprecated]] void addField(vtkSmartPointer<vtkAbstractArray>, bool checked = false, int type = vtkChart::POINTS, int marker_style = vtkPlotPoints::PLUS);
void addFieldX(vtkSmartPointer<vtkAbstractArray>);
void addFieldY(vtkSmartPointer<vtkAbstractArray>,
bool checked = false,
int type = vtkChart::POINTS,
int marker_style = vtkPlotPoints::PLUS,
QColor color = Qt::transparent,
int width = 1);
void removeField(vtkSmartPointer<vtkAbstractArray>);
void removeField(const QString&);
void setShowLegend(bool);
......
Markdown is supported
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