This commit is contained in:
2020-08-01 10:53:17 +08:00
parent ffc8207491
commit cfa905548a
14 changed files with 294 additions and 134 deletions
+47 -15
View File
@@ -9,6 +9,16 @@ Scope::Scope(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
//load qss
QFile file(":/qss/Scope.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
timeseries = 0; timeseries = 0;
chartView = new QChartView(this); chartView = new QChartView(this);
@@ -16,6 +26,7 @@ Scope::Scope(QWidget *parent) :
chartView->chart()->legend()->setAlignment(Qt::AlignRight); chartView->chart()->legend()->setAlignment(Qt::AlignRight);
chartView->chart()->legend()->setMarkerShape(QLegend::MarkerShapeCircle); chartView->chart()->legend()->setMarkerShape(QLegend::MarkerShapeCircle);
chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean); chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean);
//chartView->setMouseTracking(true); //chartView->setMouseTracking(true);
//chartView->setRubberBand(QChartView::RectangleRubberBand); //chartView->setRubberBand(QChartView::RectangleRubberBand);
//chartView->chart()->setAcceptDrops(true); //chartView->chart()->setAcceptDrops(true);
@@ -30,13 +41,16 @@ Scope::Scope(QWidget *parent) :
chartView->chart()->addAxis(axisX, Qt::AlignBottom); chartView->chart()->addAxis(axisX, Qt::AlignBottom);
QValueAxis *axisY = new QValueAxis(); QValueAxis *axisY = new QValueAxis();
axisY->setRange(-10, 10); axisY->setRange(-3, 3);
axisY->setTickCount(11); axisY->setTickCount(7);
axisY->setLabelFormat("%.2f"); axisY->setLabelFormat("%.2f");
chartView->chart()->addAxis(axisY, Qt::AlignLeft); chartView->chart()->addAxis(axisY, Qt::AlignLeft);
chartView->setGeometry(ui->frame->geometry()); chartView->setGeometry(ui->frame->geometry());
//默认不使用,因为使用显卡加速图形会闪
setUseOpenGL(false);
QTimer::singleShot(10,this,SLOT(timeout())); QTimer::singleShot(10,this,SLOT(timeout()));
@@ -163,26 +177,26 @@ void Scope::chartUpdate(void)
{ {
//读取新数据,如果没有,那就保持 //读取新数据,如果没有,那就保持
setSerieData("sin",sin(timeseries)); //setSerieData("sin",sin(timeseries));
setSerieData("cos",cos(timeseries)); //setSerieData("cos",cos(timeseries));
setSerieData("tan",tan(timeseries)); //setSerieData("tan",tan(timeseries));
//setSerieData("acos",acos(timeseries)); //setSerieData("acos",acos(timeseries));
//setSerieData("asin",asin(timeseries)); //setSerieData("asin",asin(timeseries));
//setSerieData("atan",atan(timeseries)); //setSerieData("atan",atan(timeseries));
setSerieData("x1",1 * timeseries + 1); //setSerieData("x1",1 * timeseries + 1);
setSerieData("x2",timeseries * timeseries + 1); //setSerieData("x2",timeseries * timeseries + 1);
setSerieData("x3",timeseries * timeseries * timeseries + 1); //setSerieData("x3",timeseries * timeseries * timeseries + 1);
setSerieData("sqrt",sqrt(timeseries)); //setSerieData("sqrt",sqrt(timeseries));
//setSerieData("pow",pow(timeseries,2)); //setSerieData("pow",pow(timeseries,2));
//setSerieData("log",log(timeseries + 1)); //setSerieData("log",log(timeseries + 1));
//setSerieData("log10",log10(timeseries)); //setSerieData("log10",log10(timeseries));
//setSerieData("exp",exp(timeseries)); //setSerieData("exp",exp(timeseries));
setSerieData("tan+1",tan(timeseries + 1)); //setSerieData("tan+1",tan(timeseries + 1));
//setSerieData("log2",log2(timeseries)); //setSerieData("log2",log2(timeseries));
setSerieData("timeseries",timeseries); //setSerieData("timeseries",timeseries);
setSerieData("12",timeseries * log(timeseries)); //setSerieData("12",timeseries * log(timeseries));
//滚动显示器 //滚动显示器
//当到达最大时(0.95),开始滚动 //当到达最大时(0.95),开始滚动
@@ -200,6 +214,12 @@ void Scope::chartUpdate(void)
} }
void Scope::setUseOpenGL(const bool &value)
{
isOpenGL= value;
}
bool Scope::addSeries(QString name = tr("new")) bool Scope::addSeries(QString name = tr("new"))
{ {
//查找有没有这个名字的序列 //查找有没有这个名字的序列
@@ -219,7 +239,7 @@ bool Scope::addSeries(QString name = tr("new"))
s->setColor(ColorMap::Color[ChannelIndex]); s->setColor(ColorMap::Color[ChannelIndex]);
s->setName(name); s->setName(name);
s->append(timeseries,0); s->append(timeseries,0);
s->setUseOpenGL(true); s->setUseOpenGL(isOpenGL);
chartView->chart()->addSeries(s); chartView->chart()->addSeries(s);
chartView->chart()->setAxisX(chartView->chart()->axisX(),s); chartView->chart()->setAxisX(chartView->chart()->axisX(),s);
chartView->chart()->setAxisY(chartView->chart()->axisY(),s); chartView->chart()->setAxisY(chartView->chart()->axisY(),s);
@@ -262,7 +282,7 @@ bool Scope::addSeries(QString name = tr("new"), int index = 0)
s->setColor(ColorMap::Color[ChannelIndex]); s->setColor(ColorMap::Color[ChannelIndex]);
s->setName(name); s->setName(name);
s->append(timeseries,0); s->append(timeseries,0);
//s->setUseOpenGL(true); s->setUseOpenGL(isOpenGL);
chartView->chart()->addSeries(s); chartView->chart()->addSeries(s);
chartView->chart()->setAxisX(chartView->chart()->axisX(),s); chartView->chart()->setAxisX(chartView->chart()->axisX(),s);
chartView->chart()->setAxisY(chartView->chart()->axisY(),s); chartView->chart()->setAxisY(chartView->chart()->axisY(),s);
@@ -299,7 +319,7 @@ bool Scope::addSeries(QString name = tr("new"),QColor color = QColor("#FFFFFF"))
s->setColor(color); s->setColor(color);
s->setName(name); s->setName(name);
s->append(timeseries,0); s->append(timeseries,0);
s->setUseOpenGL(true); s->setUseOpenGL(isOpenGL);
chartView->chart()->addSeries(s); chartView->chart()->addSeries(s);
chartView->chart()->setAxisX(chartView->chart()->axisX(),s); chartView->chart()->setAxisX(chartView->chart()->axisX(),s);
chartView->chart()->setAxisY(chartView->chart()->axisY(),s); chartView->chart()->setAxisY(chartView->chart()->axisY(),s);
@@ -398,6 +418,8 @@ void Scope::on_pushButton_Clear_clicked()
} }
} }
emit clearall();
} }
void Scope::on_pushButton_Flag1_clicked() void Scope::on_pushButton_Flag1_clicked()
@@ -409,3 +431,13 @@ void Scope::on_pushButton_Flag2_clicked()
{ {
} }
void Scope::on_pushButton_Close_clicked()
{
delete ui;
emit willcloase();
this->deleteLater();
this->close();
}
+9
View File
@@ -67,7 +67,13 @@ protected:
void wheelEvent(QWheelEvent *e); void wheelEvent(QWheelEvent *e);
void resizeEvent(QResizeEvent *e); void resizeEvent(QResizeEvent *e);
signals:
void clearall(void);
void willcloase(void);
public slots: public slots:
void setUseOpenGL(const bool &value);
bool addSeries(QString name); bool addSeries(QString name);
bool addSeries(QString name,int index); bool addSeries(QString name,int index);
bool addSeries(QString name, QColor color); bool addSeries(QString name, QColor color);
@@ -88,6 +94,8 @@ private slots:
void on_pushButton_Flag2_clicked(); void on_pushButton_Flag2_clicked();
void on_pushButton_Close_clicked();
private: private:
Ui::Scope *ui; Ui::Scope *ui;
@@ -96,6 +104,7 @@ private:
qreal timeseries = 0;//时间基准,注意时间长度,可能会出现时间反转的情况 qreal timeseries = 0;//时间基准,注意时间长度,可能会出现时间反转的情况
bool isOpenGL = false;
bool isScroll = true; bool isScroll = true;
bool isPress = false; bool isPress = false;
+4 -17
View File
@@ -1,23 +1,10 @@
.QWidget {
QListWidget { background-color: #FFFFFF;
background-color: #F0FFFF;
border-width: 2px;
border-color: darkkhaki;
border-style: solid;
border-radius: 5;
padding: 3px;
font: 20px;
} }
QListWidget::Item { QFrame {
height: 60; background-color: #FFFFFF;
}
QScrollBar{
width:60;
background-color:palegoldenrod;
} }
.QPushButton { .QPushButton {
+110 -64
View File
@@ -14,47 +14,46 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout_3">
<item> <property name="leftMargin">
<widget class="QPushButton" name="pushButton_Pause"> <number>6</number>
<property name="minimumSize"> </property>
<size> <property name="topMargin">
<width>60</width> <number>6</number>
<height>60</height> </property>
</size> <property name="rightMargin">
</property> <number>6</number>
<property name="maximumSize"> </property>
<size> <property name="bottomMargin">
<width>60</width> <number>6</number>
<height>60</height> </property>
</size> <item row="2" column="0">
</property>
<property name="text">
<string>Pause</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Clear">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Flag1"> <widget class="QPushButton" name="pushButton_Flag1">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@@ -73,7 +72,64 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="0">
<widget class="QPushButton" name="pushButton_Pause">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Pause</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pushButton_Close">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButton_Clear">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pushButton_Flag2"> <widget class="QPushButton" name="pushButton_Flag2">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@@ -92,31 +148,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>72</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item row="1" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
BIN
View File
Binary file not shown.
+36 -9
View File
@@ -4,14 +4,12 @@
<context> <context>
<name>About</name> <name>About</name>
<message> <message>
<location filename="About/About.ui" line="16"/>
<source>Form</source> <source>Form</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="About/About.cpp" line="9"/>
<source>About</source> <source>About</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
</context> </context>
<context> <context>
@@ -623,14 +621,12 @@
<context> <context>
<name>Help</name> <name>Help</name>
<message> <message>
<location filename="Help/Help.ui" line="16"/>
<source>Form</source> <source>Form</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="Help/Help.cpp" line="9"/>
<source>Help</source> <source>Help</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
</context> </context>
<context> <context>
@@ -874,7 +870,7 @@
</message> </message>
<message> <message>
<location filename="ToolsUI/tools_Index0/MAVLinkInspector/MAVLinkInspector.cc" line="68"/> <location filename="ToolsUI/tools_Index0/MAVLinkInspector/MAVLinkInspector.cc" line="68"/>
<location filename="ToolsUI/tools_Index0/MAVLinkInspector/MAVLinkInspector.cc" line="309"/> <location filename="ToolsUI/tools_Index0/MAVLinkInspector/MAVLinkInspector.cc" line="311"/>
<source>Vehicle %1</source> <source>Vehicle %1</source>
<translation> %1</translation> <translation> %1</translation>
</message> </message>
@@ -1183,6 +1179,37 @@
<source>Form</source> <source>Form</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<location filename="ComponentUI/Scope/Scope.ui" line="52"/>
<location filename="ComponentUI/Scope/Scope.cpp" line="387"/>
<source>Pause</source>
<translation></translation>
</message>
<message>
<location filename="ComponentUI/Scope/Scope.ui" line="71"/>
<source>Clear</source>
<translation></translation>
</message>
<message>
<location filename="ComponentUI/Scope/Scope.ui" line="90"/>
<source>Flag1</source>
<translation>1</translation>
</message>
<message>
<location filename="ComponentUI/Scope/Scope.ui" line="109"/>
<source>Flag2</source>
<translation>2</translation>
</message>
<message>
<location filename="ComponentUI/Scope/Scope.ui" line="128"/>
<source>Close</source>
<translation></translation>
</message>
<message>
<location filename="ComponentUI/Scope/Scope.cpp" line="383"/>
<source>Scroll</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>Selector</name> <name>Selector</name>
@@ -105,10 +105,10 @@ void ConnectDialog::setInit(QVariant inter, QVariant device)
} }
else if(m_Type.toString() == tr("UDP")) else if(m_Type.toString() == tr("UDP"))
{ {
m_Param1 = tr("192.168.0.1"); m_Param1 = tr("127.0.0.1");
m_Param2 = tr("6060"); m_Param2 = tr("6061");
m_Param3 = tr("192.168.0.1"); m_Param3 = tr("127.0.0.1");
m_Param4 = tr("6061"); m_Param4 = tr("6060");
} }
} }
@@ -109,10 +109,48 @@ void MAVLinkInspector::rebuildComponentList()
void MAVLinkInspector::on_pushButton_system_clicked() void MAVLinkInspector::on_pushButton_system_clicked()
{ {
if(ui->pushButton_system->text().size()) ui->pushButton_system->hide();
{ ui->clearButton->hide();
}
if(!scope)
{
scope = new Scope(this);
connect(scope,SIGNAL(willcloase()),
this,SLOT(ScopeClose()));
connect(scope,SIGNAL(clearall()),
this,SLOT(ScopeClearall()));
ui->gridLayout->addWidget(scope,0,0,1,1);
scope->show();
}
}
void MAVLinkInspector::ScopeClose(void)//可能有点问题
{
//qDebug() << "cloase";
//ui->gridLayout->addWidget(scope,0,0,1,1);
//qDebug() << ui->gridLayout->children();
//ui->gridLayout->removeWidget();
ui->pushButton_system->show();
ui->clearButton->show();
}
void MAVLinkInspector::ScopeClearall(void)
{
clearView();
//qDebug() << "ScopeClearall";
} }
@@ -274,8 +312,8 @@ void MAVLinkInspector::refreshView()
for (unsigned int i = 0; i < msgInfo->num_fields; ++i) for (unsigned int i = 0; i < msgInfo->num_fields; ++i)
{ {
QTreeWidgetItem* field = new QTreeWidgetItem(); QTreeWidgetItem* field = new QTreeWidgetItem();
field->setCheckState(0,Qt::PartiallyChecked); field->setCheckState(0,Qt::Unchecked);
widget->setCheckState(0,Qt::PartiallyChecked); //widget->setCheckState(0,Qt::PartiallyChecked);
widget->addChild(field); widget->addChild(field);
} }
msgTreeItems->insert(msg->msgid,widget); msgTreeItems->insert(msg->msgid,widget);
@@ -715,6 +753,12 @@ void MAVLinkInspector::updateField(mavlink_message_t* msg, const mavlink_message
} }
break; break;
} }
if(item->checkState(0) == Qt::Checked)
{
scope->setSerieData(item->data(0,Qt::DisplayRole).toString(),item->data(1,Qt::DisplayRole).toFloat());
}
} }
@@ -759,8 +803,11 @@ void MAVLinkInspector::on_treeWidget_itemChanged(QTreeWidgetItem *item, int colu
} }
else else
{ {
updateParentItem(item); //updateParentItem(item);
} }
} }
else if (item->checkState(0) == Qt::Unchecked) else if (item->checkState(0) == Qt::Unchecked)
{ {
@@ -774,7 +821,7 @@ void MAVLinkInspector::on_treeWidget_itemChanged(QTreeWidgetItem *item, int colu
} }
else else
{ {
updateParentItem(item); //updateParentItem(item);
} }
} }
} }
@@ -11,7 +11,7 @@
#include "mavlink.h" #include "mavlink.h"
#include "mavlink_get_info.h" #include "mavlink_get_info.h"
#include "Scope.h"
#ifdef QtMavlinkInspector #ifdef QtMavlinkInspector
#include <mavlinkinspectorglobal.h> #include <mavlinkinspectorglobal.h>
@@ -83,6 +83,10 @@ protected:
static const float updateHzLowpass; ///< The low-pass filter value for the frequency of each message static const float updateHzLowpass; ///< The low-pass filter value for the frequency of each message
private slots: private slots:
void ScopeClose(void);
void ScopeClearall(void);
void _vehicleAdded(quint32 id); void _vehicleAdded(quint32 id);
void on_pushButton_system_clicked(); void on_pushButton_system_clicked();
@@ -96,6 +100,7 @@ private slots:
private: private:
Ui::MAVLinkInspector *ui; Ui::MAVLinkInspector *ui;
Scope *scope = nullptr;
}; };
#endif // QGCMAVLINKINSPECTOR_H #endif // QGCMAVLINKINSPECTOR_H
@@ -26,20 +26,20 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>6</number> <number>6</number>
</property> </property>
<item row="0" column="1"> <item row="0" column="0">
<widget class="QPushButton" name="clearButton"> <widget class="QPushButton" name="pushButton_system">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>120</width> <width>0</width>
<height>60</height> <height>60</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Clear</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QTreeWidget" name="treeWidget"> <widget class="QTreeWidget" name="treeWidget">
<property name="headerHidden"> <property name="headerHidden">
<bool>true</bool> <bool>true</bool>
@@ -64,16 +64,16 @@
</column> </column>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="1">
<widget class="QPushButton" name="pushButton_system"> <widget class="QPushButton" name="clearButton">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>120</width>
<height>60</height> <height>60</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>Clear</string>
</property> </property>
</widget> </widget>
</item> </item>
+6 -1
View File
@@ -19,7 +19,9 @@ Tools_Index0::Tools_Index0(QWidget *parent) :
mavlinkinspector->setParent(this); mavlinkinspector->setParent(this);
mavlinkinspector->show(); mavlinkinspector->show();
//scope = new Scope(this);
//scope->setGeometry(ui->frame->geometry());
//scope->show();
} }
@@ -36,6 +38,9 @@ void Tools_Index0::resizeEvent(QResizeEvent *event)
{ {
mavlinkinspector->setGeometry(0,0,ui->frame->width(),ui->frame->height()); mavlinkinspector->setGeometry(0,0,ui->frame->width(),ui->frame->height());
} }
update(); update();
} }
+3 -1
View File
@@ -9,6 +9,8 @@
#include "MAVLinkInspector.h" #include "MAVLinkInspector.h"
//#include "Scope.h"
namespace Ui { namespace Ui {
class Tools_Index0; class Tools_Index0;
} }
@@ -40,7 +42,7 @@ private:
Ui::Tools_Index0 *ui; Ui::Tools_Index0 *ui;
QWidget *Inspect = nullptr; QWidget *Inspect = nullptr;
//Scope *scope = nullptr;
}; };
+4 -4
View File
@@ -16,9 +16,9 @@ Tools_Index1::Tools_Index1(QWidget *parent) :
file.close(); file.close();
scope = new Scope(this); //scope = new Scope(this);
scope->setGeometry(ui->frame->geometry()); //scope->setGeometry(ui->frame->geometry());
scope->show(); //scope->show();
} }
Tools_Index1::~Tools_Index1() Tools_Index1::~Tools_Index1()
@@ -29,7 +29,7 @@ Tools_Index1::~Tools_Index1()
void Tools_Index1::resizeEvent(QResizeEvent *event) void Tools_Index1::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
scope->setGeometry(ui->frame->geometry()); //scope->setGeometry(ui->frame->geometry());
update(); update();
} }
+2 -2
View File
@@ -6,7 +6,7 @@
#include "QTextStream" #include "QTextStream"
#include "QDebug" #include "QDebug"
#include "Scope.h" //#include "Scope.h"
namespace Ui { namespace Ui {
@@ -26,7 +26,7 @@ public:
private: private:
Ui::Tools_Index1 *ui; Ui::Tools_Index1 *ui;
Scope *scope = nullptr; //Scope *scope = nullptr;
}; };
#endif // INDEX1_H #endif // INDEX1_H