able to specify the protocol's data display format, for bin/ocx/hex/dec/ascii..

This commit is contained in:
dreamsourcelabTAI 2021-10-15 17:26:50 +08:00
parent ea11b48470
commit a80151e3c0
27 changed files with 1126 additions and 258 deletions

View File

@ -41,6 +41,7 @@
#include "mystyle.h"
#include "pv/devicemanager.h"
#include "pv/mainframe.h"
#include "pv/config/appconfig.h"
#include "config.h"
@ -186,6 +187,8 @@ int main(int argc, char *argv[])
// Load the protocol decoders
srd_decoder_load_all();
#endif
//load app config
AppConfig::Instance().Load("./appconfig.json");
try {
// Create the device manager, initialise the drivers

View File

@ -0,0 +1,186 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "appconfig.h"
#include <assert.h>
#include <QFile>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTextStream>
#include <QStringList>
#define MAX_PROTOCOL_FORMAT_LIST 15
StringPair::StringPair(const string &key, const string &value)
{
m_key = key;
m_value = value;
}
//------------function
QString FormatArrayToString(vector<StringPair> &protocolFormats){
QString str;
for (StringPair &o : protocolFormats){
if (!str.isEmpty()){
str += ";";
}
std::string line;
line += o.m_key;
line += "=";
line += o.m_value;
str += line.c_str();
}
return str;
}
void StringToFormatArray(const QString &str, vector<StringPair> &protocolFormats){
QStringList arr = str.split(";");
for (int i=0; i<arr.size(); i++){
QString line = arr[i];
if (!line.isEmpty()){
QStringList vs = line.split("=");
if (vs.size() == 2){
protocolFormats.push_back(StringPair(vs[0].toStdString(), vs[1].toStdString()));
}
}
}
}
//------------AppConfig
AppConfig::AppConfig()
{
}
AppConfig::~AppConfig()
{
}
AppConfig& AppConfig::Instance()
{
static AppConfig *ins = NULL;
if (ins == NULL){
ins = new AppConfig();
}
return *ins;
}
bool AppConfig::Load(const char *file)
{
assert(file);
m_fileName = file;
QFile qf(file);
if (qf.open(QIODevice::ReadOnly))
{
QByteArray bytes = qf.readAll();
qf.close();
string json;
json.append(bytes.data(), bytes.size());
FromJson(json);
return true;
}
return false;
}
bool AppConfig::Save()
{
if (m_fileName != "")
{
QFile qf(m_fileName.c_str());
if (qf.open(QIODevice::WriteOnly | QIODevice::Text))
{
string json = ToJsonString();
QByteArray bytes(json.c_str(), json.size());
QTextStream _stream(&qf);
_stream.setCodec("UTF-8");
_stream << QString::fromUtf8(bytes);
qf.close();
return true;
}
}
return false;
}
string AppConfig::ToJsonString()
{
QJsonObject jobj;
QString profomats = FormatArrayToString(m_protocolFormats);
jobj["ProtocolFormats"] = QJsonValue::fromVariant(profomats);
QJsonDocument jdoc(jobj);
QByteArray bytes = jdoc.toJson();
string json;
json.append(bytes.data(), bytes.size());
return json;
}
void AppConfig::FromJson(string &json)
{
if (!json.size())
return;
QByteArray bytes(json.c_str(), json.size());
QJsonDocument jdoc = QJsonDocument::fromJson(bytes);
QJsonObject jobj = jdoc.object();
if (jobj.contains("ProtocolFormats")){
m_protocolFormats.clear();
StringToFormatArray(jobj["ProtocolFormats"].toString(), m_protocolFormats);
}
}
void AppConfig::SetProtocolFormat(const string &protocolName, const string &value)
{
for (StringPair &o : m_protocolFormats){
if (o.m_key == protocolName){
o.m_value = value;
return;
}
}
if (m_protocolFormats.size() > MAX_PROTOCOL_FORMAT_LIST){
while (m_protocolFormats.size() < MAX_PROTOCOL_FORMAT_LIST)
{
m_protocolFormats.erase(m_protocolFormats.begin());
}
}
m_protocolFormats.push_back(StringPair(protocolName,value));
}
string AppConfig::GetProtocolFormat(const string &protocolName)
{
for (StringPair &o : m_protocolFormats){
if (o.m_key == protocolName){
return o.m_value;
}
}
return "";
}

View File

@ -0,0 +1,75 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <string>
#include <vector>
using namespace std;
struct app_status{
};
class StringPair
{
public:
StringPair(const string &key, const string &value);
string m_key;
string m_value;
};
class config_data
{
public:
};
class AppConfig
{
private:
AppConfig();
~AppConfig();
public:
static AppConfig &Instance();
bool Load(const char *file);
bool Save();
string ToJsonString();
void FromJson(string &json);
void SetProtocolFormat(const string &protocolName, const string &value);
string GetProtocolFormat(const string &protocolName);
public:
config_data m_data;
app_status m_status;
private:
string m_fileName;
vector<StringPair> m_protocolFormats;
};

View File

@ -27,7 +27,91 @@
#include "annotation.h"
#include "AnnotationResTable.h"
#include <cstring>
#include <assert.h>
#include <string.h>
#include "../../config/appconfig.h"
#include "decoderstatus.h"
#include "../../dsvdef.h"
#define DECODER_MAX_DATA_BLOCK_LEN 300
#define FORMAT_TMP_BUFFER_SIZE 1200
const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111";
char g_bin_format_tmp_buffer[FORMAT_TMP_BUFFER_SIZE + 3];
char g_oct_format_tmp_buffer[FORMAT_TMP_BUFFER_SIZE + 6];
std::vector<QString> g_format_ret_vector;
char* bin2oct_string(char *buf, int size, const char *bin, int len){
char *wr = buf + size - 1;
*wr = 0; //end flag
char *rd = (char*)bin + len - 1; //move to last byte
char tmp[3];
while (rd >= bin && wr > buf)
{
wr--;
int num = 0;
while (rd >= bin && num < 3)
{
tmp[2-num] = *rd;
rd--;
num++;
}
//fill
while (num < 3)
{
tmp[2-num] = '0';
++num;
}
if (strncmp(tmp, "000", 3) == 0)
*wr = '0';
else if (strncmp(tmp, "001", 3) == 0)
*wr = '1';
else if (strncmp(tmp, "010", 3) == 0)
*wr = '2';
else if (strncmp(tmp, "011", 3) == 0)
*wr = '3';
else if (strncmp(tmp, "100", 3) == 0)
*wr = '4';
else if (strncmp(tmp, "101", 3) == 0)
*wr = '5';
else if (strncmp(tmp, "110", 3) == 0)
*wr = '6';
else if (strncmp(tmp, "111", 3) == 0)
*wr = '7';
}
return wr;
}
long long bin2long_string(const char *bin, int len)
{
char *rd = (char *)bin + len - 1; //move to last byte
int dex = 0;
long long value = 0;
long long bv = 0;
while (rd >= bin)
{
if (*rd == '1')
{
bv = 1 << dex;
value += bv;
}
rd--;
++dex;
}
return value;
}
namespace pv {
namespace data {
namespace decode {
@ -35,7 +119,7 @@ namespace decode {
//a find talbe instance
AnnotationResTable *Annotation::m_resTable = new AnnotationResTable();
Annotation::Annotation(const srd_proto_data *const pdata) :
Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status) :
_start_sample(pdata->start_sample),
_end_sample(pdata->end_sample)
{
@ -45,7 +129,13 @@ Annotation::Annotation(const srd_proto_data *const pdata) :
assert(pda);
_format = pda->ann_class;
_type = pda->ann_type;
_type = pda->ann_type;
_status = status;
//have numerical
if (_type >= 100 && _type < 200){
status->m_bNumerical = true;
}
_strIndex = 0;
@ -105,7 +195,87 @@ int Annotation::type() const
const std::vector<QString>& Annotation::annotations() const
{
return Annotation::m_resTable->GetString(_strIndex);
assert(_status);
int fmt = _status->m_format;
const std::vector<QString>& vct = Annotation::m_resTable->GetString(_strIndex);
if (!(_type >= 100 && _type < 200) || fmt == DecoderDataFormat::ascii || fmt == DecoderDataFormat::hex){
return vct;
}
if (vct.size() != 1){
return vct;
}
//flow, convert to oct\dec\bin format
const char *data = vct[0].toStdString().c_str();
if (*data == 0 || *data == '['){
return vct;
}
//convert to bin format
char *buf = g_bin_format_tmp_buffer + FORMAT_TMP_BUFFER_SIZE;
*(buf + 1) = 0; //set the end flag
*buf = 0;
int len = strlen(data);
//buffer is not enough
if (len > DECODER_MAX_DATA_BLOCK_LEN){
return vct;
}
char *rd = (char*)data + len - 1; //move to last byte
char c = 0;
int dex = 0;
while (rd >= data)
{
c = *rd;
dex = (int)(c <= '9' ? (c - '0') : (c - 'A' + 10));
char *ptable = (char*)g_bin_cvt_table + dex * 4;
buf -= 4; //move to left for 4 bytes
buf[0] = ptable[0];
buf[1] = ptable[1];
buf[2] = ptable[2];
buf[3] = ptable[3];
rd--;
}
std::vector<QString> &vct2 = g_format_ret_vector;
if (vct2.size() == 0){
vct2.push_back(QString());
}
//get bin format
if (fmt == DecoderDataFormat::bin){
vct2[0].clear();
vct2[0].append(buf);
return vct2;
}
//get oct format
if (fmt == DecoderDataFormat::oct){
char *oct_buf = bin2oct_string(g_oct_format_tmp_buffer,
sizeof(g_oct_format_tmp_buffer), buf, len * 4);
vct2[0].clear();
vct2[0].append(oct_buf);
return vct2;
}
//64 bit integer
if (fmt == DecoderDataFormat::dec && len * 4 <= 64){
long long lv = bin2long_string(buf, len *4);
char vbuf[30] = {0};
sprintf(vbuf, "%lld", lv);
vct2[0].clear();
vct2[0].append(vbuf);
return vct2;
}
return vct2;
}

View File

@ -27,6 +27,7 @@
#include <QString>
class AnnotationResTable;
class DecoderStatus;
struct srd_proto_data;
@ -37,7 +38,7 @@ namespace decode {
class Annotation
{
public:
Annotation(const srd_proto_data *const pdata);
Annotation(const srd_proto_data *const pdata, DecoderStatus *status);
Annotation();
public:
@ -55,8 +56,9 @@ private:
uint64_t _start_sample;
uint64_t _end_sample;
short _format;
short _type;
short _type; //100-199: is a numerical value type,can show hex/oct format
short _strIndex;
DecoderStatus *_status;
static AnnotationResTable * m_resTable;
};

View File

@ -109,6 +109,7 @@ uint64_t Decoder::decode_end() const
return _decode_end;
}
//apply setting
bool Decoder::commit()
{
if (_setted) {

View File

@ -0,0 +1,38 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
class DecoderStatus
{
public:
DecoderStatus()
{
m_bNumerical = false;
m_format = 0;
sdr_decoder_handle = NULL;
}
public:
bool m_bNumerical; //when decoder get any numerical data,it will be set
int m_format; //protocol format code
void *sdr_decoder_handle;
};

View File

@ -36,12 +36,15 @@ class Row
{
public:
Row();
~Row();
Row(const srd_decoder *decoder,
const srd_decoder_annotation_row *row = NULL,
const int order = -1);
public:
~Row();
const srd_decoder* decoder() const;
const srd_decoder_annotation_row* row() const;

View File

@ -53,7 +53,7 @@ const unsigned int DecoderStack::DecodeNotifyPeriod = 1024;
boost::mutex DecoderStack::_global_decode_mutex;
DecoderStack::DecoderStack(pv::SigSession &session,
const srd_decoder *const dec) :
const srd_decoder *const dec, DecoderStatus *decoder_status) :
_session(session),
_sample_count(0),
_frame_complete(false),
@ -73,6 +73,8 @@ DecoderStack::DecoderStack(pv::SigSession &session,
_stack.push_back(boost::shared_ptr<decode::Decoder>(
new decode::Decoder(dec)));
_decoder_status = decoder_status;
build_row();
}
@ -612,6 +614,7 @@ uint64_t DecoderStack::sample_rate() const
return _samplerate;
}
//the decode callback, annotation object will be create
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
{
assert(pdata);
@ -626,7 +629,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
return;
}
const Annotation a(pdata);
const Annotation a(pdata, d->_decoder_status);
// Find the row
assert(pdata->pdo);

View File

@ -36,10 +36,12 @@
#include "../data/decode/rowdata.h"
#include "../data/signaldata.h"
class DecoderStatus;
namespace DecoderStackTest {
class TwoDecoderStack;
}
namespace pv {
class SigSession;
@ -78,7 +80,7 @@ public:
public:
DecoderStack(pv::SigSession &_session,
const srd_decoder *const decoder);
const srd_decoder *const decoder, DecoderStatus *decoder_status);
public:
@ -203,6 +205,7 @@ private:
bool _no_memory;
int64_t _mark_index;
DecoderStatus *_decoder_status;
friend class DecoderStackTest::TwoDecoderStack;
};

View File

@ -32,9 +32,10 @@
namespace pv {
namespace dialogs {
DSMessageBox::DSMessageBox(QWidget *parent) :
DSMessageBox::DSMessageBox(QWidget *parent,const char *title) :
QDialog(parent),
_moving(false)
_moving(false),
_clickType(0)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
@ -53,7 +54,14 @@ DSMessageBox::DSMessageBox(QWidget *parent) :
_msg->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
_titlebar = new toolbars::TitleBar(false, this);
_titlebar->setTitle(tr("Message"));
if (title){
_titlebar->setTitle(QString(title));
}
else{
_titlebar->setTitle(tr("Message"));
}
_titlebar->installEventFilter(this);
mlayout->addWidget(_titlebar);
@ -120,6 +128,8 @@ int DSMessageBox::exec()
void DSMessageBox::on_button(QAbstractButton *btn)
{
QMessageBox::ButtonRole role = _msg->buttonRole(btn);
_clickType = (int)role;
if (role == QMessageBox::AcceptRole)
accept();
else

View File

@ -38,10 +38,13 @@ class DSMessageBox : public QDialog
Q_OBJECT
public:
DSMessageBox(QWidget *parent);
DSMessageBox(QWidget *parent, const char *title=0);
QMessageBox *mBox();
int exec();
inline int GetLastClick(){return _clickType;}
protected:
void accept();
@ -60,6 +63,7 @@ private:
toolbars::TitleBar *_titlebar;
bool _moving;
QPoint _startPos;
int _clickType;
};
} // namespace dialogs

View File

@ -26,8 +26,7 @@
#include "../data/decodermodel.h"
#include "../data/decoderstack.h"
#include "../dialogs/protocollist.h"
#include "../dialogs/protocolexp.h"
#include "../dialogs/dsmessagebox.h"
#include "../dialogs/protocolexp.h"
#include "../view/view.h"
#include <QObject>
@ -44,14 +43,19 @@
#include <QProgressDialog>
#include <QtConcurrent/QtConcurrent>
#include <QSizePolicy>
#include <assert.h>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
#include <algorithm>
#include "../ui/msgbox.h"
#include "../dsvdef.h"
#include "../config/appconfig.h"
#include "../data/decode/decoderstatus.h"
namespace pv {
namespace dock {
ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &session) :
QScrollArea(parent),
_session(session),
@ -90,12 +94,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
hori_layout->addWidget(_del_all_button);
hori_layout->addWidget(_protocol_combobox);
hori_layout->addStretch(1);
connect(_add_button, SIGNAL(clicked()),
this, SLOT(add_protocol()));
connect(_del_all_button, SIGNAL(clicked()),
this, SLOT(del_protocol()));
_up_layout = new QVBoxLayout();
_up_layout->addLayout(hori_layout);
_up_layout->addStretch(1);
@ -111,18 +110,12 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
_dn_set_button = new QPushButton(_dn_widget);
_dn_set_button->setFlat(true);
connect(_dn_set_button, SIGNAL(clicked()),
this, SLOT(set_model()));
_dn_save_button = new QPushButton(_dn_widget);
_dn_save_button->setFlat(true);
connect(_dn_save_button, SIGNAL(clicked()),
this, SLOT(export_table_view()));
_dn_save_button->setFlat(true);
_dn_nav_button = new QPushButton(_dn_widget);
_dn_nav_button->setFlat(true);
connect(_dn_nav_button, SIGNAL(clicked()),
this, SLOT(nav_table_view()));
_dn_nav_button->setFlat(true);
QHBoxLayout *dn_title_layout = new QHBoxLayout();
_dn_title_label = new QLabel(_dn_widget);
@ -142,10 +135,6 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
_pre_button = new QPushButton(_dn_widget);
_nxt_button = new QPushButton(_dn_widget);
connect(_pre_button, SIGNAL(clicked()),
this, SLOT(search_pre()));
connect(_nxt_button, SIGNAL(clicked()),
this, SLOT(search_nxt()));
_search_button = new QPushButton(this);
_search_button->setFixedWidth(_search_button->height());
@ -194,6 +183,20 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
//_split_widget->setGeometry(0, 0, sizeHint().width(), 500);
_split_widget->setObjectName("protocolWidget");
connect(_dn_nav_button, SIGNAL(clicked()),this, SLOT(nav_table_view()));
connect(_dn_save_button, SIGNAL(clicked()),this, SLOT(export_table_view()));
connect(_dn_set_button, SIGNAL(clicked()),this, SLOT(set_model()));
connect(_pre_button, SIGNAL(clicked()),this, SLOT(search_pre()));
connect(_nxt_button, SIGNAL(clicked()),this, SLOT(search_nxt()));
connect(_add_button, SIGNAL(clicked()),this, SLOT(on_add_protocol()));
connect(_del_all_button, SIGNAL(clicked()),this, SLOT(on_del_all_protocol()));
connect(&_session, SIGNAL(decode_done()), this, SLOT(update_model()));
connect(this, SIGNAL(protocol_updated()), this, SLOT(update_model()));
connect(_table_view, SIGNAL(clicked(QModelIndex)), this, SLOT(item_clicked(QModelIndex)));
@ -206,6 +209,11 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
ProtocolDock::~ProtocolDock()
{
//destroy protocol item layers
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
delete (*it);
}
_protocolItems.clear();
}
void ProtocolDock::changeEvent(QEvent *event)
@ -237,21 +245,13 @@ void ProtocolDock::reStyle()
_nxt_button->setIcon(QIcon(iconPath+"/next.svg"));
_search_button->setIcon(QIcon(iconPath+"/search.svg"));
for (QVector <QPushButton *>::const_iterator i = _del_button_list.begin();
i != _del_button_list.end(); i++)
(*i)->setIcon(QIcon(iconPath+"/del.svg"));
for (QVector <QPushButton *>::const_iterator i = _set_button_list.begin();
i != _set_button_list.end(); i++)
(*i)->setIcon(QIcon(iconPath+"/gear.svg"));
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
(*it)->ResetStyle();
}
}
void ProtocolDock::paintEvent(QPaintEvent *)
{
// QStyleOption opt;
// opt.init(this);
// QPainter p(this);
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
{
}
void ProtocolDock::resizeEvent(QResizeEvent *event)
@ -298,179 +298,72 @@ bool ProtocolDock::sel_protocol(QString id)
return false;
}
void ProtocolDock::add_protocol()
void ProtocolDock::on_add_protocol()
{
add_protocol(false);
}
void ProtocolDock::add_protocol(bool silent)
{
if (_session.get_device()->dev_inst()->mode != LOGIC) {
dialogs::DSMessageBox msg(this);
msg.mBox()->setText(tr("Protocol Analyzer"));
msg.mBox()->setInformativeText(tr("Protocol Analyzer is only valid in Digital Mode!"));
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
} else {
srd_decoder *const decoder =
(srd_decoder*)(_protocol_combobox->itemData(_protocol_combobox->currentIndex())).value<void*>();
if (_session.add_decoder(decoder, silent)) {
//std::list <int > _sel_probes = dlg.get_sel_probes();
//QMap <QString, QVariant>& _options = dlg.get_options();
//QMap <QString, int> _options_index = dlg.get_options_index();
{
if (_session.get_device()->dev_inst()->mode != LOGIC) {
MsgBox::Show(NULL, "Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!", this);
return;
}
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QPushButton *_del_button = new QPushButton(_up_widget);
QPushButton *_set_button = new QPushButton(_up_widget);
_del_button->setFlat(true);
_del_button->setIcon(QIcon(iconPath+"/del.svg"));
_set_button->setFlat(true);
_set_button->setIcon(QIcon(iconPath+"/gear.svg"));
QLabel *_protocol_label = new QLabel(_up_widget);
QLabel *_progress_label = new QLabel(_up_widget);
srd_decoder *const decoder =
(srd_decoder *)(_protocol_combobox->itemData(_protocol_combobox->currentIndex())).value<void *>();
_del_button->setCheckable(true);
_protocol_label->setText(_protocol_combobox->currentText());
DecoderStatus *dstatus = new DecoderStatus();
dstatus->m_format = (int)DecoderDataFormat::hex;
connect(_del_button, SIGNAL(clicked()),
this, SLOT(del_protocol()));
connect(_set_button, SIGNAL(clicked()),
this, SLOT(rst_protocol()));
if (_session.add_decoder(decoder, silent, dstatus))
{
//crate item layer
QString protocolName = _protocol_combobox->currentText();
ProtocolItemLayer *layer = new ProtocolItemLayer(_up_widget, protocolName, this);
_protocolItems.push_back(layer);
_up_layout->insertLayout(_protocolItems.size(), layer);
layer->m_decoderStatus = dstatus;
_del_button_list.push_back(_del_button);
_set_button_list.push_back(_set_button);
_protocol_label_list.push_back(_protocol_label);
_progress_label_list.push_back(_progress_label);
_protocol_index_list.push_back(_protocol_combobox->currentIndex());
QHBoxLayout *hori_layout = new QHBoxLayout();
hori_layout->addWidget(_set_button);
hori_layout->addWidget(_del_button);
hori_layout->addWidget(_protocol_label);
hori_layout->addWidget(_progress_label);
hori_layout->addStretch(1);
_hori_layout_list.push_back(hori_layout);
_up_layout->insertLayout(_del_button_list.size(), hori_layout);
// progress connection
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
connect(decode_sigs.back().get(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progress(int)));
protocol_updated();
//set current protocol format
string fmt = AppConfig::Instance().GetProtocolFormat(protocolName.toStdString());
if (fmt != ""){
layer->SetProtocolFormat(fmt.c_str());
dstatus->m_format = DecoderDataFormat::Parse(fmt.c_str());
}
//progress connection
const std::vector<boost::shared_ptr<pv::view::DecodeTrace>> decode_sigs(_session.get_decode_signals());
connect(decode_sigs.back().get(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progress(int)));
protocol_updated();
}
}
void ProtocolDock::on_del_all_protocol(){
if (_protocolItems.size() == 0){
MsgBox::Show(NULL, "No Protocol Analyzer to delete!", this);
return;
}
void ProtocolDock::rst_protocol()
{
int rst_index = 0;
for (QVector <QPushButton *>::const_iterator i = _set_button_list.begin();
i != _set_button_list.end(); i++) {
QPushButton *button = qobject_cast<QPushButton *>(sender());
if ((*i) == button) {
//pv::decoder::DemoConfig dlg(this, _session.get_device(), _protocol_index_list.at(rst_index));
//dlg.set_config(_session.get_decode_probes(rst_index), _session.get_decode_options_index(rst_index));
//if (dlg.exec()) {
//std::list <int > _sel_probes = dlg.get_sel_probes();
//QMap <QString, QVariant>& _options = dlg.get_options();
//QMap <QString, int> _options_index = dlg.get_options_index();
//_session.rst_protocol_analyzer(rst_index, _sel_probes, _options, _options_index);
//}
_session.rst_decoder(rst_index);
break;
}
rst_index++;
if (MsgBox::Confirm("Are you sure to remove all protocol analyzer?", this)){
del_all_protocol();
}
protocol_updated();
}
void ProtocolDock::del_protocol()
{
if (_del_all_button->isChecked()) {
_del_all_button->setChecked(false);
if (_hori_layout_list.size() > 0) {
int del_index = 0;
for (QVector <QHBoxLayout *>::const_iterator i = _hori_layout_list.begin();
i != _hori_layout_list.end(); i++) {
_up_layout->removeItem((*i));
delete (*i);
delete _del_button_list.at(del_index);
delete _set_button_list.at(del_index);
delete _protocol_label_list.at(del_index);
delete _progress_label_list.at(del_index);
_session.remove_decode_signal(0);
del_index++;
}
_hori_layout_list.clear();
_del_button_list.clear();
_set_button_list.clear();
_protocol_label_list.clear();
_progress_label_list.clear();
_protocol_index_list.clear();
} else {
dialogs::DSMessageBox msg(NULL);
msg.mBox()->setText(tr("Protocol Analyzer"));
msg.mBox()->setInformativeText(tr("No Protocol Analyzer to delete!"));
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
}
} else {
int del_index = 0;
for (QVector <QPushButton *>::const_iterator i = _del_button_list.begin();
i != _del_button_list.end(); i++) {
if ((*i)->isChecked()) {
_up_layout->removeItem(_hori_layout_list.at(del_index));
delete _hori_layout_list.at(del_index);
delete _del_button_list.at(del_index);
delete _set_button_list.at(del_index);
delete _protocol_label_list.at(del_index);
delete _progress_label_list.at(del_index);
_hori_layout_list.remove(del_index);
_del_button_list.remove(del_index);
_set_button_list.remove(del_index);
_protocol_label_list.remove(del_index);
_progress_label_list.remove(del_index);
_protocol_index_list.remove(del_index);
_session.remove_decode_signal(del_index);
break;
}
del_index++;
}
}
protocol_updated();
}
}
void ProtocolDock::del_all_protocol()
{
if (_hori_layout_list.size() > 0) {
int del_index = 0;
for (QVector <QHBoxLayout *>::const_iterator i = _hori_layout_list.begin();
i != _hori_layout_list.end(); i++) {
_up_layout->removeItem((*i));
delete (*i);
delete _del_button_list.at(del_index);
delete _set_button_list.at(del_index);
delete _protocol_label_list.at(del_index);
delete _progress_label_list.at(del_index);
{
if (_protocolItems.size() > 0)
{
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++)
{
_up_layout->removeItem((*it));
delete (*it); //destory control
_session.remove_decode_signal(0);
del_index++;
}
_hori_layout_list.clear();
_del_button_list.clear();
_set_button_list.clear();
_protocol_label_list.clear();
_progress_label_list.clear();
_protocol_index_list.clear();
_protocolItems.clear();
protocol_updated();
}
}
@ -484,20 +377,33 @@ void ProtocolDock::decoded_progress(int progress)
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
int index = 0;
BOOST_FOREACH(boost::shared_ptr<pv::view::DecodeTrace> d, decode_sigs) {
pg = d->get_progress();
if (d->decoder()->out_of_memory())
err = tr("(Out of Memory)");
QString progress_str = QString::number(pg) + "%" + err;
if (pg == 100)
_progress_label_list.at(index)->setStyleSheet("color:green;");
else
_progress_label_list.at(index)->setStyleSheet("color:red;");
_progress_label_list.at(index)->setText(progress_str);
if (index < _protocolItems.size())
{
ProtocolItemLayer &lay = *(_protocolItems.at(index));
lay.SetProgress(pg, err);
//when decode complete, check data format
if (pg == 100)
{
// bool flag = ((DecoderStatus*)lay.m_decoderStatus)->m_bNumerical;
// lay.LoadFormatSelect(!flag);
// QString &protocolName = lay.GetProtocolName();
// lay.SetProtocolFormat(protocolName.toStdString().c_str());
}
}
index++;
}
if (pg == 0 || pg % 10 == 1)
update_model();
if (pg == 0 || pg % 10 == 1){
update_model();
}
}
void ProtocolDock::set_model()
@ -836,6 +742,52 @@ void ProtocolDock::search_update()
//search_done();
}
//-------------------IProtocolItemLayerCallback
void ProtocolDock::OnProtocolSetting(void *handle){
int dex = 0;
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
if ((*it) == handle){
_session.rst_decoder(dex);
protocol_updated();
break;
}
dex++;
}
}
void ProtocolDock::OnProtocolDelete(void *handle){
if (!MsgBox::Confirm("Are you sure to remove this protocol analyzer?", this)){
return;
}
int dex = 0;
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
if ((*it) == handle){
delete (*it);
_up_layout->removeItem((*it)); //remove child control
_protocolItems.remove(dex);
_session.remove_decode_signal(dex);
protocol_updated();
break;
}
dex++;
}
}
void ProtocolDock::OnProtocolFormatChanged(QString format, void *handle){
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
if ((*it) == handle){
QString &name = (*it)->GetProtocolName();
AppConfig::Instance().SetProtocolFormat(name.toStdString(), format.toStdString());
AppConfig::Instance().Save();
(*it)->m_decoderStatus->m_format = DecoderDataFormat::Parse(format.toStdString().c_str());
protocol_updated();
break;
}
}
}
//-------------------------
} // namespace dock
} // namespace pv

View File

@ -41,11 +41,11 @@
#include <boost/thread.hpp>
#include "../data/decodermodel.h"
#include "protocolitemlayer.h"
namespace pv {
class SigSession;
namespace data {
class DecoderModel;
}
@ -55,8 +55,8 @@ class View;
}
namespace dock {
class ProtocolDock : public QScrollArea
class ProtocolDock : public QScrollArea,public IProtocolItemLayerCallback
{
Q_OBJECT
@ -79,13 +79,18 @@ protected:
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
private:
//IProtocolItemLayerCallback
void OnProtocolSetting(void *handle);
void OnProtocolDelete(void *handle);
void OnProtocolFormatChanged(QString format, void *handle);
signals:
void protocol_updated();
private slots:
void add_protocol();
void rst_protocol();
void del_protocol();
void on_add_protocol();
void on_del_all_protocol();
void decoded_progress(int progress);
void set_model();
void update_model();
@ -125,19 +130,14 @@ private:
QPushButton *_add_button;
QPushButton *_del_all_button;
QComboBox *_protocol_combobox;
QVector <QPushButton *> _del_button_list;
QVector <QPushButton *> _set_button_list;
QVector <QLabel *> _protocol_label_list;
QVector <QLabel *> _progress_label_list;
QVector <int > _protocol_index_list;
QVector <QHBoxLayout *> _hori_layout_list;
QComboBox *_protocol_combobox;
QVector <int > _protocol_index_list;
QVBoxLayout *_up_layout;
QVector <ProtocolItemLayer*> _protocolItems; //protocol item layers
QPushButton *_dn_set_button;
QPushButton *_dn_save_button;
QPushButton *_dn_nav_button;
QPushButton *_search_button;
mutable boost::mutex _search_mutex;

View File

@ -0,0 +1,152 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "protocolitemlayer.h"
#include "../dsvdef.h"
#include <QtCore>
#include <assert.h>
namespace pv {
namespace dock {
ProtocolItemLayer::ProtocolItemLayer(QWidget *parent, QString protocolName, IProtocolItemLayerCallback *callback){
assert(parent);
assert(callback);
m_callback = callback;
_protocolName = protocolName;
m_bSetting = false;
_protocol_label = new QLabel(parent);
_progress_label = new QLabel(parent);
_set_button = new QPushButton(parent);
_del_button = new QPushButton(parent);
_format_combox = new QComboBox(parent);
QString iconPath = ":/icons/" + qApp->property("Style").toString();
_del_button->setFlat(true);
_del_button->setIcon(QIcon(iconPath + "/del.svg"));
_set_button->setFlat(true);
_set_button->setIcon(QIcon(iconPath + "/gear.svg"));
_protocol_label->setText(protocolName);
m_singleFlag = true;
m_decoderStatus = NULL;
LoadFormatSelect(false);
QHBoxLayout *hori_layout = this;
hori_layout->addWidget(_set_button);
hori_layout->addWidget(_del_button);
hori_layout->addWidget(_format_combox);
hori_layout->addWidget(_protocol_label);
hori_layout->addWidget(_progress_label);
hori_layout->addStretch(1);
connect(_del_button, SIGNAL(clicked()),this, SLOT(on_del_protocol()));
connect(_set_button, SIGNAL(clicked()),this, SLOT(on_set_protocol()));
connect(_format_combox, SIGNAL(currentIndexChanged(int)),this, SLOT(on_format_select_changed(int)));
}
ProtocolItemLayer::~ProtocolItemLayer(){
DESTROY_OBJECT(_set_button);
DESTROY_OBJECT(_del_button);
DESTROY_OBJECT(_protocol_label);
DESTROY_OBJECT(_progress_label);
DESTROY_OBJECT(_format_combox);
}
//-------------control event
void ProtocolItemLayer::on_set_protocol()
{
m_callback->OnProtocolSetting(this);
}
void ProtocolItemLayer::on_del_protocol(){
m_callback->OnProtocolDelete(this);
}
void ProtocolItemLayer::on_format_select_changed(int index){
if (index >= 0 && !m_bSetting){
QString text = _format_combox->currentText();
m_callback->OnProtocolFormatChanged(text, this);
}
}
//-----------------
void ProtocolItemLayer::SetProgress(int progress, QString text){
QString str = QString::number(progress) + "%" + text;
if (progress == 100)
_progress_label->setStyleSheet("color:green;");
else
_progress_label->setStyleSheet("color:red;");
_progress_label->setText(str);
}
void ProtocolItemLayer::ResetStyle(){
QString iconPath = ":/icons/" + qApp->property("Style").toString();
_del_button->setIcon(QIcon(iconPath + "/del.svg"));
_set_button->setIcon(QIcon(iconPath + "/gear.svg"));
}
void ProtocolItemLayer::LoadFormatSelect(bool bSingle)
{
if (bSingle == m_singleFlag){
return;
}
m_singleFlag = bSingle;
m_bSetting = true;
_format_combox->clear();
_format_combox->addItem("ascii");
int dex = 0;
if (!bSingle)
{
_format_combox->addItem("dec");
_format_combox->addItem("hex");
_format_combox->addItem("oct");
_format_combox->addItem("bin");
dex = 2;
}
_format_combox->setCurrentIndex(dex);
m_bSetting = false;
}
void ProtocolItemLayer::SetProtocolFormat(const char *format)
{
assert(format);
m_bSetting = true;
int dex = DecoderDataFormat::Parse(format);
if (dex < (int)_format_combox->count()){
_format_combox->setCurrentIndex(dex);
}
m_bSetting = false;
}
} //dock
} //pv

View File

@ -0,0 +1,79 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <QHBoxLayout>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QComboBox>
#include <QString>
class DecoderStatus;
namespace pv{
namespace dock{
class IProtocolItemLayerCallback
{
public:
virtual void OnProtocolSetting(void *handle)=0;
virtual void OnProtocolDelete(void *handle)=0;
virtual void OnProtocolFormatChanged(QString format, void *handle)=0;
};
class ProtocolItemLayer: public QHBoxLayout
{
Q_OBJECT
public:
ProtocolItemLayer(QWidget *parent, QString protocolName, IProtocolItemLayerCallback *callback);
~ProtocolItemLayer();
void SetProgress(int progress, QString text);
void ResetStyle();
void LoadFormatSelect(bool bSingle);
inline QString &GetProtocolName(){return _protocolName;}
void SetProtocolFormat(const char *format);
private slots:
void on_set_protocol();
void on_del_protocol();
void on_format_select_changed(int index);
public:
DecoderStatus *m_decoderStatus; //DecoderStatus
private:
QLabel *_protocol_label;
QLabel *_progress_label;
QPushButton *_set_button;
QPushButton *_del_button;
QComboBox *_format_combox;
IProtocolItemLayerCallback *m_callback;
QString _protocolName;
bool m_bSetting;
bool m_singleFlag;
};
} //dock
} //pv

46
DSView/pv/dsvdef.cpp Normal file
View File

@ -0,0 +1,46 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dsvdef.h"
#include <string.h>
namespace DecoderDataFormat
{
int Parse(const char *name){
if (strcmp(name, "ascii") == 0){
return (int)ascii;
}
if (strcmp(name, "dec") == 0){
return (int)dec;
}
if (strcmp(name, "hex") == 0){
return (int)hex;
}
if (strcmp(name, "oct") == 0){
return (int)oct;
}
if (strcmp(name, "bin") == 0){
return (int)bin;
}
return (int)ascii;
}
}

39
DSView/pv/dsvdef.h Normal file
View File

@ -0,0 +1,39 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#define DESTROY_OBJECT(p) if ((p)){delete (p); p = NULL;}
namespace DecoderDataFormat
{
enum _data_format
{
ascii = 0,
dec,
hex,
oct,
bin
};
int Parse(const char *name);
}

View File

@ -90,6 +90,7 @@
#include <glib.h>
#include <list>
#include <libusb.h>
#include "../ui/msgbox.h"
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
@ -938,12 +939,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev)
const sr_dev_inst *const sdi = _session.get_device()->dev_inst();
if ((!file_dev && strcmp(sdi->driver->name, sessionObj["Device"].toString().toUtf8()) != 0) ||
sdi->mode != sessionObj["DeviceMode"].toDouble()) {
dialogs::DSMessageBox msg(this);
msg.mBox()->setText(tr("Session Error"));
msg.mBox()->setInformativeText(tr("Session File is not compatible with current device or mode!"));
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
MsgBox::Show(NULL, "Session File is not compatible with current device or mode!", this);
return false;
}
@ -1128,12 +1124,6 @@ bool MainWindow::store_session(QString name)
{
QFile sessionFile(name);
if (!sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
// dialogs::DSMessageBox msg(this);
// msg.mBox()->setText(tr("File Error"));
// msg.mBox()->setInformativeText(tr("Couldn't open session file to write!"));
// msg.mBox()->setStandardButtons(QMessageBox::Ok);
// msg.mBox()->setIcon(QMessageBox::Warning);
// msg.exec();
qDebug("Warning: Couldn't open session file to write!");
return false;
}

View File

@ -56,12 +56,18 @@ void Binding::add_properties_to_form(QFormLayout *layout,
{
assert(p);
QWidget *const widget = p->get_widget(layout->parentWidget(),
auto_commit);
QWidget *const widget = p->get_widget(layout->parentWidget(), auto_commit);
if (p->labeled_widget())
layout->addRow(widget);
else
layout->addRow(p->label(), widget);
else{
const QString &lbstr = p->label();
//remove data format options
if (lbstr == "Data format"){
continue;
}
layout->addRow(p->label(), widget);
}
}
}

View File

@ -66,6 +66,7 @@
#include <QtConcurrent/QtConcurrent>
#include <boost/foreach.hpp>
#include "data/decode/decoderstatus.h"
//using boost::dynamic_pointer_cast;
//using boost::function;
@ -1366,8 +1367,8 @@ uint16_t SigSession::get_ch_num(int type)
}
#ifdef ENABLE_DECODE
bool SigSession::add_decoder(srd_decoder *const dec, bool silent)
{
bool SigSession::add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus)
{
bool ret = false;
map<const srd_channel*, int> probes;
boost::shared_ptr<data::DecoderStack> decoder_stack;
@ -1377,7 +1378,7 @@ bool SigSession::add_decoder(srd_decoder *const dec, bool silent)
// Create the decoder
decoder_stack = boost::shared_ptr<data::DecoderStack>(
new data::DecoderStack(*this, dec));
new data::DecoderStack(*this, dec, dstatus));
// Make a list of all the probes
std::vector<const srd_channel*> all_probes;

View File

@ -55,6 +55,8 @@
struct srd_decoder;
struct srd_channel;
class DecoderStatus;
namespace pv {
class DeviceManager;
@ -178,7 +180,7 @@ public:
get_group_signals();
#ifdef ENABLE_DECODE
bool add_decoder(srd_decoder *const dec, bool silent);
bool add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus);
std::vector< boost::shared_ptr<view::DecodeTrace> >
get_decode_signals() const;

View File

@ -346,7 +346,6 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
if (ret != SR_OK) {
if (!_has_error) {
_has_error = true;
auto err = m_zipDoc.GetError();
_error = tr("Failed to create zip file. Please check write permission of this path.");
}
progress_updated();

56
DSView/pv/ui/msgbox.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "msgbox.h"
#include "../dialogs/dsmessagebox.h"
#include <assert.h>
#include <QMessageBox>
#include <QString>
//QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
//QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes|QMessageBox::No);
//QMessageBox::information(NULL, "Title", "Content");
//QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes|QMessageBox::No|QMessageBox::Abort);
void MsgBox::Show(const char *title, const char *text, QWidget *parent)
{
assert(text);
pv::dialogs::DSMessageBox msg(parent, title);
msg.mBox()->setText(QString(text));
// msg.mBox()->setInformativeText(QString(text));
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
}
bool MsgBox::Confirm(const char *text, QWidget *parent)
{
assert(text);
pv::dialogs::DSMessageBox msg(parent, "Question");
msg.mBox()->setText(QString(text));
msg.mBox()->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msg.mBox()->setIcon(QMessageBox::Question);
msg.exec();
int click = msg.GetLastClick();
return (click == (int)QMessageBox::YesRole);
}

33
DSView/pv/ui/msgbox.h Normal file
View File

@ -0,0 +1,33 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
class QWidget;
class MsgBox
{
public:
static void Show(const char *title, const char *text, QWidget *parent=0);
static bool Confirm(const char *text, QWidget *parent=0);
};

View File

@ -52,10 +52,11 @@
#include "../device/devinst.h"
#include "../view/cursor.h"
#include "../toolbars/titlebar.h"
#include "../dsvdef.h"
using namespace boost;
using namespace std;
namespace pv {
namespace view {
@ -138,14 +139,20 @@ DecodeTrace::DecodeTrace(pv::SigSession &session,
this, SLOT(on_new_decode_data()));
connect(_decoder_stack.get(), SIGNAL(decode_done()),
this, SLOT(on_decode_done()));
_start_comboBox = NULL;
_end_comboBox = NULL;
_pub_input_layer = NULL;
}
DecodeTrace::~DecodeTrace()
{
if (_popup_form)
delete _popup_form;
if (_popup)
delete _popup;
DESTROY_OBJECT(_start_comboBox);
DESTROY_OBJECT(_end_comboBox);
DESTROY_OBJECT(_pub_input_layer);
DESTROY_OBJECT(_popup_form);
DESTROY_OBJECT(_popup);
_cur_row_headings.clear();
_decoder_forms.clear();
_probe_selectors.clear();
@ -342,6 +349,7 @@ void DecodeTrace::paint_fore(QPainter &p, int left, int right, QColor fore, QCol
(void)back;
}
//to show decoder's property setting dialog
bool DecodeTrace::create_popup()
{
int ret = false;
@ -363,10 +371,12 @@ bool DecodeTrace::create_popup()
}
}
delete _popup_form;
delete _popup;
_popup = NULL;
_popup_form = NULL;
//destroy object
DESTROY_OBJECT(_start_comboBox);
DESTROY_OBJECT(_end_comboBox);
DESTROY_OBJECT(_pub_input_layer);
DESTROY_OBJECT(_popup_form);
DESTROY_OBJECT(_popup);
return ret;
}
@ -409,7 +419,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
if (stack.empty()) {
QLabel *const l = new QLabel(
tr("<p><i>No decoders in the stack</i></p>"));
tr("<p><i>No decoders in the stack</i></p>"));
l->setAlignment(Qt::AlignCenter);
form->addRow(l);
} else {
@ -422,7 +432,11 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
tr("<i>* Required channels</i>"), parent));
}
// Add region combobox
//public input layer
// QFormLayout *publay = new QFormLayout();
// form->addRow(publay);
//Add region combobox
_start_comboBox = new QComboBox(parent);
_end_comboBox = new QComboBox(parent);
_start_comboBox->addItem(RegionStart);

View File

@ -213,6 +213,7 @@ private:
int _start_index, _end_index;
int _start_count, _end_count;
QComboBox *_start_comboBox, *_end_comboBox;
QFormLayout *_pub_input_layer;
int _progress;
std::list< boost::shared_ptr<pv::prop::binding::DecoderOptions> >