From a80151e3c038bc7d24924c367497a01bd5e633e0 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 15 Oct 2021 17:26:50 +0800 Subject: [PATCH] able to specify the protocol's data display format, for bin/ocx/hex/dec/ascii.. --- DSView/main.cpp | 3 + DSView/pv/config/appconfig.cpp | 186 ++++++++++++++ DSView/pv/config/appconfig.h | 75 ++++++ DSView/pv/data/decode/annotation.cpp | 178 ++++++++++++- DSView/pv/data/decode/annotation.h | 6 +- DSView/pv/data/decode/decoder.cpp | 1 + DSView/pv/data/decode/decoderstatus.h | 38 +++ DSView/pv/data/decode/row.h | 5 +- DSView/pv/data/decoderstack.cpp | 7 +- DSView/pv/data/decoderstack.h | 7 +- DSView/pv/dialogs/dsmessagebox.cpp | 16 +- DSView/pv/dialogs/dsmessagebox.h | 6 +- DSView/pv/dock/protocoldock.cpp | 344 +++++++++++--------------- DSView/pv/dock/protocoldock.h | 30 +-- DSView/pv/dock/protocolitemlayer.cpp | 152 ++++++++++++ DSView/pv/dock/protocolitemlayer.h | 79 ++++++ DSView/pv/dsvdef.cpp | 46 ++++ DSView/pv/dsvdef.h | 39 +++ DSView/pv/mainwindow.cpp | 14 +- DSView/pv/prop/binding/binding.cpp | 14 +- DSView/pv/sigsession.cpp | 7 +- DSView/pv/sigsession.h | 4 +- DSView/pv/storesession.cpp | 1 - DSView/pv/ui/msgbox.cpp | 56 +++++ DSView/pv/ui/msgbox.h | 33 +++ DSView/pv/view/decodetrace.cpp | 36 ++- DSView/pv/view/decodetrace.h | 1 + 27 files changed, 1126 insertions(+), 258 deletions(-) create mode 100644 DSView/pv/config/appconfig.cpp create mode 100644 DSView/pv/config/appconfig.h create mode 100644 DSView/pv/data/decode/decoderstatus.h create mode 100644 DSView/pv/dock/protocolitemlayer.cpp create mode 100644 DSView/pv/dock/protocolitemlayer.h create mode 100644 DSView/pv/dsvdef.cpp create mode 100644 DSView/pv/dsvdef.h create mode 100644 DSView/pv/ui/msgbox.cpp create mode 100644 DSView/pv/ui/msgbox.h diff --git a/DSView/main.cpp b/DSView/main.cpp index fa87b03c..1a51a86f 100755 --- a/DSView/main.cpp +++ b/DSView/main.cpp @@ -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 diff --git a/DSView/pv/config/appconfig.cpp b/DSView/pv/config/appconfig.cpp new file mode 100644 index 00000000..ac5d1c28 --- /dev/null +++ b/DSView/pv/config/appconfig.cpp @@ -0,0 +1,186 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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 +#include +#include +#include +#include +#include +#include + +#define MAX_PROTOCOL_FORMAT_LIST 15 + +StringPair::StringPair(const string &key, const string &value) +{ + m_key = key; + m_value = value; +} + +//------------function +QString FormatArrayToString(vector &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 &protocolFormats){ + QStringList arr = str.split(";"); + for (int i=0; i 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 ""; +} diff --git a/DSView/pv/config/appconfig.h b/DSView/pv/config/appconfig.h new file mode 100644 index 00000000..ec2b2ee1 --- /dev/null +++ b/DSView/pv/config/appconfig.h @@ -0,0 +1,75 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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 +#include + +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 m_protocolFormats; +}; diff --git a/DSView/pv/data/decode/annotation.cpp b/DSView/pv/data/decode/annotation.cpp index 1a0c0fce..c0838d04 100755 --- a/DSView/pv/data/decode/annotation.cpp +++ b/DSView/pv/data/decode/annotation.cpp @@ -27,7 +27,91 @@ #include "annotation.h" #include "AnnotationResTable.h" #include - +#include +#include +#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 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& Annotation::annotations() const { - return Annotation::m_resTable->GetString(_strIndex); + assert(_status); + + int fmt = _status->m_format; + const std::vector& 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 &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; } diff --git a/DSView/pv/data/decode/annotation.h b/DSView/pv/data/decode/annotation.h index f55035b0..d45d0e5b 100755 --- a/DSView/pv/data/decode/annotation.h +++ b/DSView/pv/data/decode/annotation.h @@ -27,6 +27,7 @@ #include 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; }; diff --git a/DSView/pv/data/decode/decoder.cpp b/DSView/pv/data/decode/decoder.cpp index 486340cc..94d1efe3 100755 --- a/DSView/pv/data/decode/decoder.cpp +++ b/DSView/pv/data/decode/decoder.cpp @@ -109,6 +109,7 @@ uint64_t Decoder::decode_end() const return _decode_end; } +//apply setting bool Decoder::commit() { if (_setted) { diff --git a/DSView/pv/data/decode/decoderstatus.h b/DSView/pv/data/decode/decoderstatus.h new file mode 100644 index 00000000..d80780b3 --- /dev/null +++ b/DSView/pv/data/decode/decoderstatus.h @@ -0,0 +1,38 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab + * + * 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; +}; \ No newline at end of file diff --git a/DSView/pv/data/decode/row.h b/DSView/pv/data/decode/row.h index 1b2fb84f..d6fa4ac6 100755 --- a/DSView/pv/data/decode/row.h +++ b/DSView/pv/data/decode/row.h @@ -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; diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 1c4f6602..7f946dd1 100755 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -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( 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); diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index 091a9d96..311a819f 100755 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -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; }; diff --git a/DSView/pv/dialogs/dsmessagebox.cpp b/DSView/pv/dialogs/dsmessagebox.cpp index 70445d7e..6a2a225d 100755 --- a/DSView/pv/dialogs/dsmessagebox.cpp +++ b/DSView/pv/dialogs/dsmessagebox.cpp @@ -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 diff --git a/DSView/pv/dialogs/dsmessagebox.h b/DSView/pv/dialogs/dsmessagebox.h index 5fc2ea30..fa6a8dfb 100755 --- a/DSView/pv/dialogs/dsmessagebox.h +++ b/DSView/pv/dialogs/dsmessagebox.h @@ -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 diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index 2039c9da..a811218e 100755 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -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 @@ -44,14 +43,19 @@ #include #include #include +#include #include #include #include +#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 ::const_iterator i = _del_button_list.begin(); - i != _del_button_list.end(); i++) - (*i)->setIcon(QIcon(iconPath+"/del.svg")); - - for (QVector ::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(); - if (_session.add_decoder(decoder, silent)) { - //std::list _sel_probes = dlg.get_sel_probes(); - //QMap & _options = dlg.get_options(); - //QMap _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(); - _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 > 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> 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 ::const_iterator i = _set_button_list.begin(); - i != _set_button_list.end(); i++) { - QPushButton *button = qobject_cast(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 _sel_probes = dlg.get_sel_probes(); - //QMap & _options = dlg.get_options(); - //QMap _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 ::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 ::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 ::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 > decode_sigs( _session.get_decode_signals()); int index = 0; + BOOST_FOREACH(boost::shared_ptr 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 diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index f5bc4534..d0d35af8 100755 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -41,11 +41,11 @@ #include #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 _del_button_list; - QVector _set_button_list; - QVector _protocol_label_list; - QVector _progress_label_list; - QVector _protocol_index_list; - QVector _hori_layout_list; + QComboBox *_protocol_combobox; + QVector _protocol_index_list; QVBoxLayout *_up_layout; + QVector _protocolItems; //protocol item layers QPushButton *_dn_set_button; QPushButton *_dn_save_button; QPushButton *_dn_nav_button; - QPushButton *_search_button; mutable boost::mutex _search_mutex; diff --git a/DSView/pv/dock/protocolitemlayer.cpp b/DSView/pv/dock/protocolitemlayer.cpp new file mode 100644 index 00000000..1a0996e1 --- /dev/null +++ b/DSView/pv/dock/protocolitemlayer.cpp @@ -0,0 +1,152 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2013 DreamSourceLab + * + * 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 +#include + +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 diff --git a/DSView/pv/dock/protocolitemlayer.h b/DSView/pv/dock/protocolitemlayer.h new file mode 100644 index 00000000..9f4c8b62 --- /dev/null +++ b/DSView/pv/dock/protocolitemlayer.h @@ -0,0 +1,79 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2013 DreamSourceLab + * + * 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 +#include +#include +#include +#include +#include + +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 diff --git a/DSView/pv/dsvdef.cpp b/DSView/pv/dsvdef.cpp new file mode 100644 index 00000000..c6478b51 --- /dev/null +++ b/DSView/pv/dsvdef.cpp @@ -0,0 +1,46 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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 + +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; + } +} diff --git a/DSView/pv/dsvdef.h b/DSView/pv/dsvdef.h new file mode 100644 index 00000000..2647f613 --- /dev/null +++ b/DSView/pv/dsvdef.h @@ -0,0 +1,39 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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); +} diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index b585a0f9..06c30bc9 100755 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -90,6 +90,7 @@ #include #include #include +#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; } diff --git a/DSView/pv/prop/binding/binding.cpp b/DSView/pv/prop/binding/binding.cpp index c5252716..db9a0453 100755 --- a/DSView/pv/prop/binding/binding.cpp +++ b/DSView/pv/prop/binding/binding.cpp @@ -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); + } } } diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index df1afdc0..1912088f 100755 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -66,6 +66,7 @@ #include #include +#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 probes; boost::shared_ptr decoder_stack; @@ -1377,7 +1378,7 @@ bool SigSession::add_decoder(srd_decoder *const dec, bool silent) // Create the decoder decoder_stack = boost::shared_ptr( - new data::DecoderStack(*this, dec)); + new data::DecoderStack(*this, dec, dstatus)); // Make a list of all the probes std::vector all_probes; diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 0f9d46ca..c895c07e 100755 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -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 > get_decode_signals() const; diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 18ad1bd5..e77345bd 100755 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -346,7 +346,6 @@ void StoreSession::save_proc(shared_ptr 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(); diff --git a/DSView/pv/ui/msgbox.cpp b/DSView/pv/ui/msgbox.cpp new file mode 100644 index 00000000..4c9a6357 --- /dev/null +++ b/DSView/pv/ui/msgbox.cpp @@ -0,0 +1,56 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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 +#include +#include + +//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); +} diff --git a/DSView/pv/ui/msgbox.h b/DSView/pv/ui/msgbox.h new file mode 100644 index 00000000..7b725158 --- /dev/null +++ b/DSView/pv/ui/msgbox.h @@ -0,0 +1,33 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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); +}; \ No newline at end of file diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 733497fb..e44f1dce 100755 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -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("

No decoders in the stack

")); + tr("

No decoders in the stack

")); l->setAlignment(Qt::AlignCenter); form->addRow(l); } else { @@ -422,7 +432,11 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) tr("* Required channels"), 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); diff --git a/DSView/pv/view/decodetrace.h b/DSView/pv/view/decodetrace.h index 1fcb1257..924cf333 100755 --- a/DSView/pv/view/decodetrace.h +++ b/DSView/pv/view/decodetrace.h @@ -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 >