##// END OF EJS Templates
Ensures graph and zone names are not duplicated in the visualization
trabillard -
r1137:030ee50565df
parent child
Show More
@@ -18,20 +18,6 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
18
18
19 namespace {
19 namespace {
20
20
21 /// Generates a default name for a new zone, according to the number of zones already displayed in
22 /// the tab
23 QString defaultZoneName(const QLayout &layout)
24 {
25 auto count = 0;
26 for (auto i = 0; i < layout.count(); ++i) {
27 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
28 count++;
29 }
30 }
31
32 return QObject::tr("Zone %1").arg(count + 1);
33 }
34
35 /**
21 /**
36 * Applies a function to all zones of the tab represented by its layout
22 * Applies a function to all zones of the tab represented by its layout
37 * @param layout the layout that contains zones
23 * @param layout the layout that contains zones
@@ -43,13 +29,31 void processZones(QLayout &layout, Fun fun)
43 for (auto i = 0; i < layout.count(); ++i) {
29 for (auto i = 0; i < layout.count(); ++i) {
44 if (auto item = layout.itemAt(i)) {
30 if (auto item = layout.itemAt(i)) {
45 if (auto visualizationZoneWidget
31 if (auto visualizationZoneWidget
46 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
32 = qobject_cast<VisualizationZoneWidget *>(item->widget())) {
47 fun(*visualizationZoneWidget);
33 fun(*visualizationZoneWidget);
48 }
34 }
49 }
35 }
50 }
36 }
51 }
37 }
52
38
39 /// Generates a default name for a new zone, according to the number of zones already displayed in
40 /// the tab
41 QString defaultZoneName(QLayout &layout)
42 {
43 QSet<QString> existingNames;
44 processZones(layout,
45 [&existingNames](auto &zoneWidget) { existingNames.insert(zoneWidget.name()); });
46
47 int zoneNum = 1;
48 QString name;
49 do {
50 name = QObject::tr("Zone ").append(QString::number(zoneNum));
51 ++zoneNum;
52 } while (existingNames.contains(name));
53
54 return name;
55 }
56
53 } // namespace
57 } // namespace
54
58
55 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
59 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
@@ -27,21 +27,6 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
27
27
28 namespace {
28 namespace {
29
29
30
31 /// Generates a default name for a new graph, according to the number of graphs already displayed in
32 /// the zone
33 QString defaultGraphName(const QLayout &layout)
34 {
35 auto count = 0;
36 for (auto i = 0; i < layout.count(); ++i) {
37 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
38 count++;
39 }
40 }
41
42 return QObject::tr("Graph %1").arg(count + 1);
43 }
44
45 /**
30 /**
46 * Applies a function to all graphs of the zone represented by its layout
31 * Applies a function to all graphs of the zone represented by its layout
47 * @param layout the layout that contains graphs
32 * @param layout the layout that contains graphs
@@ -60,6 +45,24 void processGraphs(QLayout &layout, Fun fun)
60 }
45 }
61 }
46 }
62
47
48 /// Generates a default name for a new graph, according to the number of graphs already displayed in
49 /// the zone
50 QString defaultGraphName(QLayout &layout)
51 {
52 QSet<QString> existingNames;
53 processGraphs(
54 layout, [&existingNames](auto &graphWidget) { existingNames.insert(graphWidget.name()); });
55
56 int zoneNum = 1;
57 QString name;
58 do {
59 name = QObject::tr("Graph ").append(QString::number(zoneNum));
60 ++zoneNum;
61 } while (existingNames.contains(name));
62
63 return name;
64 }
65
63 } // namespace
66 } // namespace
64
67
65 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
68 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
General Comments 0
You need to be logged in to leave comments. Login now