-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathComplexplotWrapper.cpp
More file actions
executable file
·185 lines (161 loc) · 4.81 KB
/
Copy pathComplexplotWrapper.cpp
File metadata and controls
executable file
·185 lines (161 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "ComplexplotWrapper.h"
#include "ComplexWidget.h"
#include "srsgui/common/Events.h"
#include <qapplication.h>
#include <QThread>
#include <QGridLayout>
using namespace std;
ComplexplotWrapper::ComplexplotWrapper()
:widget_(NULL)
,destroyed_(true)
{
if(QCoreApplication::instance() == NULL)
return; //TODO: throw exception here in Iris
if(qApp->thread() == QThread::currentThread())
{
connect( this, SIGNAL( createWidgetSignal() ),
this, SLOT(createWidgetSlot()) );
connect( this, SIGNAL( destroyWidgetSignal() ),
this, SLOT(destroyWidgetSlot()) );
connect( this, SIGNAL( destroyWidgetSignalBlocking() ),
this, SLOT(destroyWidgetSlot()) );
}
else
{
connect( this, SIGNAL( createWidgetSignal() ),
this, SLOT(createWidgetSlot()),
Qt::BlockingQueuedConnection );
connect( this, SIGNAL( destroyWidgetSignal() ),
this, SLOT(destroyWidgetSlot()) );
connect( this, SIGNAL( destroyWidgetSignalBlocking() ),
this, SLOT(destroyWidgetSlot()),
Qt::BlockingQueuedConnection );
moveToThread(QCoreApplication::instance()->thread());
}
emit createWidgetSignal();
}
ComplexplotWrapper::~ComplexplotWrapper()
{
if(QCoreApplication::instance() == NULL) {
destroyed_ = true;
}
if(destroyed_)
emit destroyWidgetSignal();
else
emit destroyWidgetSignalBlocking();
}
void ComplexplotWrapper::createWidgetSlot()
{
widget_ = new ComplexWidget;
destroyed_ = false;
widget_->setAttribute(Qt::WA_DeleteOnClose, true);
connect(widget_, SIGNAL( destroyed() ),
this, SLOT( widgetDestroyed() ));
connect(this, SIGNAL(addToWindowSignal(QString, int, int)),
this, SLOT(addToWindowSlot(QString, int, int)));
connect(this, SIGNAL(setWidgetTitle(QString)),
widget_, SLOT(setWidgetTitle(QString)));
connect(this, SIGNAL(setWidgetXAxisScale(int,double,double)),
widget_, SLOT(setWidgetXAxisScale(int,double,double)));
connect(this, SIGNAL(setWidgetYAxisScale(int,double,double)),
widget_, SLOT(setWidgetYAxisScale(int,double,double)));
connect(this, SIGNAL(setWidgetXAxisAutoScale(int,bool)),
widget_, SLOT(setWidgetXAxisAutoScale(int,bool)));
connect(this, SIGNAL(setWidgetYAxisAutoScale(int,bool)),
widget_, SLOT(setWidgetYAxisAutoScale(int,bool)));
connect(this, SIGNAL(setWidgetXAxisRange(double,double)),
widget_, SLOT(setWidgetXAxisRange(double,double)));
widget_->resize( 800, 600 );
widget_->show();
}
void ComplexplotWrapper::destroyWidgetSlot()
{
if(widget_)
delete widget_;
widget_ = NULL;
}
void ComplexplotWrapper::widgetDestroyed()
{
destroyed_ = true;
}
void ComplexplotWrapper::addToWindow(std::string window, int row, int column)
{
emit addToWindowSignal(QString::fromStdString(window), row, column);
}
void ComplexplotWrapper::addToWindowSlot(QString window, int row, int column)
{
if(destroyed_)
return;
if(window != "")
{
QWidgetList widgets = qApp->topLevelWidgets();
for(QWidgetList::iterator i = widgets.begin(); i != widgets.end(); ++i)
{
if ((*i)->objectName() == window)
{
QGridLayout *l = (QGridLayout*)(*i)->layout();
if(row<0) row = l->count()/3;
if(column<0) column = l->count()%3;
l->addWidget(widget_, row, column);
return;
}
}
QWidget *p = new QWidget();
p->setObjectName(window);
QGridLayout *layout = new QGridLayout();
p->setLayout(layout);
if(row<0) row = 0;
if(column<0) column = 0;
layout->addWidget(widget_, row, column);
p->show();
}
}
void ComplexplotWrapper::setNewData(complex<double>* data, int numPoints)
{
if(destroyed_)
return;
qApp->postEvent(widget_, new ComplexDataEvent(data, numPoints));
}
void ComplexplotWrapper::setNewData(complex<float>* data, int numPoints)
{
if(destroyed_)
return;
qApp->postEvent(widget_, new ComplexDataEvent(data, numPoints));
}
void ComplexplotWrapper::setTitle(std::string title)
{
if(destroyed_)
return;
QString str = QString::fromUtf8(title.c_str());
emit setWidgetTitle(str);
}
void ComplexplotWrapper::setXAxisAutoScale(int id, bool on=true)
{
if(destroyed_)
return;
emit setWidgetXAxisAutoScale(id, on);
}
void ComplexplotWrapper::setYAxisAutoScale(int id, bool on=true)
{
if(destroyed_)
return;
emit setWidgetYAxisAutoScale(id, on);
}
void ComplexplotWrapper::setXAxisScale(int id, double xMin, double xMax)
{
if(destroyed_)
return;
emit setWidgetXAxisScale(id, xMin, xMax);
}
void ComplexplotWrapper::setYAxisScale(int id, double yMin, double yMax)
{
if(destroyed_)
return;
emit setWidgetYAxisScale(id, yMin, yMax);
}
void ComplexplotWrapper::setXAxisRange(double xMin, double xMax)
{
if(destroyed_)
return;
emit setWidgetXAxisRange(xMin, xMax);
}