Commit adf428ff authored by DreamSourceLab's avatar DreamSourceLab

Add protocol list viewer and export support

parent f3138d93
......@@ -56,5 +56,6 @@
<file>icons/start_dis.png</file>
<file>icons/start_dis_cn.png</file>
<file>icons/settings.png</file>
<file>darkstyle/style.qss</file>
</qresource>
</RCC>
This diff is collapsed.
......@@ -147,7 +147,8 @@ int main(int argc, char *argv[])
// Initialise the main window
pv::MainWindow w(device_manager, open_file);
QFile qss(":/stylesheet.qss");
//QFile qss(":/stylesheet.qss");
QFile qss(":qdarkstyle/style.qss");
qss.open(QFile::ReadOnly);
a.setStyleSheet(qss.readAll());
qss.close();
......
......@@ -49,6 +49,12 @@ Annotation::Annotation(const srd_proto_data *const pdata) :
}
}
Annotation::Annotation()
{
_start_sample = 0;
_end_sample = 0;
}
Annotation::~Annotation()
{
_annotations.clear();
......
......@@ -35,6 +35,7 @@ class Annotation
{
public:
Annotation(const srd_proto_data *const pdata);
Annotation();
~Annotation();
uint64_t start_sample() const;
......
......@@ -68,8 +68,8 @@ const QString Row::title() const
bool Row::operator<(const Row &other) const
{
return (_decoder < other._decoder) ||
(_decoder == other._decoder && _row < other._row);
return (_decoder->name < other._decoder->name) ||
(_decoder->name == other._decoder->name && _row->desc < other._row->desc);
}
} // decode
......
......@@ -46,7 +46,7 @@ public:
const QString title() const;
bool operator<(const Row &other) const;
bool operator<(const Row &other) const;
private:
const srd_decoder *_decoder;
......
......@@ -23,6 +23,7 @@
#include "rowdata.h"
using std::max;
using std::min;
using std::vector;
namespace pv {
......@@ -30,7 +31,8 @@ namespace data {
namespace decode {
RowData::RowData() :
_max_annotation(0)
_max_annotation(0),
_min_annotation(UINT64_MAX)
{
}
......@@ -51,6 +53,11 @@ uint64_t RowData::get_max_annotation() const
return _max_annotation;
}
uint64_t RowData::get_min_annotation() const
{
return _min_annotation;
}
void RowData::get_annotation_subset(
vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample) const
......@@ -62,10 +69,33 @@ void RowData::get_annotation_subset(
dest.push_back(*i);
}
void RowData::push_annotation(const Annotation &a)
bool RowData::push_annotation(const Annotation &a)
{
try {
_annotations.push_back(a);
_max_annotation = max(_max_annotation, a.end_sample() - a.start_sample());
if (a.end_sample() != a.start_sample())
_min_annotation = min(_min_annotation, a.end_sample() - a.start_sample());
return true;
} catch (const std::bad_alloc&) {
return false;
}
}
uint64_t RowData::get_annotation_size() const
{
return _annotations.size();
}
bool RowData::get_annotation(Annotation &ann,
uint64_t index) const
{
_annotations.push_back(a);
_max_annotation = max(_max_annotation, a.end_sample() - a.start_sample());
if (index < _annotations.size()) {
ann = _annotations[index];
return true;
} else {
return false;
}
}
} // decode
......
......@@ -39,6 +39,7 @@ public:
uint64_t get_max_sample() const;
uint64_t get_max_annotation() const;
uint64_t get_min_annotation() const;
/**
* Extracts sorted annotations between two period into a vector.
*/
......@@ -46,10 +47,16 @@ public:
std::vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample) const;
void push_annotation(const Annotation &a);
bool push_annotation(const Annotation &a);
uint64_t get_annotation_size() const;
bool get_annotation(pv::data::decode::Annotation &ann,
uint64_t index) const;
private:
uint64_t _max_annotation;
uint64_t _min_annotation;
std::vector<Annotation> _annotations;
};
......
/*
* This file is part of the DSView project.
*
* Copyright (C) 2016 Andy Deng <andy@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 <libsigrokdecode/libsigrokdecode.h>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <pv/data/decode/annotation.h>
#include <pv/data/decode/rowdata.h>
#include "decoderstack.h"
#include "decodermodel.h"
using namespace boost;
using namespace std;
namespace pv {
namespace data {
DecoderModel::DecoderModel(QObject *parent)
: QAbstractTableModel(parent),
_decoder_stack(NULL)
{
}
void DecoderModel::setDecoderStack(boost::shared_ptr<pv::data::DecoderStack> decoder_stack)
{
beginResetModel();
_decoder_stack = decoder_stack;
endResetModel();
}
const boost::shared_ptr<pv::data::DecoderStack>& DecoderModel::getDecoderStack() const
{
return _decoder_stack;
}
int DecoderModel::rowCount(const QModelIndex & /* parent */) const
{
if (_decoder_stack)
return _decoder_stack->list_annotation_size();
else
return 100;
}
int DecoderModel::columnCount(const QModelIndex & /* parent */) const
{
if (_decoder_stack)
return _decoder_stack->list_rows_size();
else
return 1;
}
QVariant DecoderModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole) {
return int(Qt::AlignLeft | Qt::AlignVCenter);
} else if (role == Qt::DisplayRole) {
if (_decoder_stack) {
pv::data::decode::Annotation ann;
if (_decoder_stack->list_annotation(ann, index.column(), index.row())) {
return ann.annotations().at(0);
}
}
}
return QVariant();
}
QVariant DecoderModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Vertical)
return section;
if (_decoder_stack) {
QString title;
if (_decoder_stack->list_row_title(section, title))
return title;
}
return QVariant();
}
} // namespace data
} // namespace pv
/*
* This file is part of the DSView project.
*
* Copyright (C) 2016 Andy Deng <andy@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
*/
#ifndef DSVIEW_PV_DATA_DECODERMODEL_H
#define DSVIEW_PV_DATA_DECODERMODEL_H
#include <QAbstractTableModel>
#include <boost/shared_ptr.hpp>
#include <pv/data/decode/rowdata.h>
namespace pv {
namespace data {
class DecoderStack;
namespace decode {
class Annotation;
class Decoder;
class Row;
}
class DecoderModel : public QAbstractTableModel
{
public:
DecoderModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
void setDecoderStack(boost::shared_ptr<pv::data::DecoderStack> decoder_stack);
const boost::shared_ptr<pv::data::DecoderStack>& getDecoderStack() const;
private:
boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
};
} // namespace data
} // namespace pv
#endif // DSVIEW_PV_DATA_DECODERMODEL_H
This diff is collapsed.
......@@ -86,14 +86,13 @@ public:
virtual ~DecoderStack();
const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
void push(boost::shared_ptr<decode::Decoder> decoder);
void remove(int index);
void remove(boost::shared_ptr<decode::Decoder>& decoder);
void build_row();
int64_t samples_decoded() const;
std::vector< std::pair<decode::Row, bool> > get_visible_rows() const;
/**
* Extracts sorted annotations between two period into a vector.
*/
......@@ -103,9 +102,23 @@ public:
uint64_t end_sample) const;
uint64_t get_max_annotation(const decode::Row &row);
uint64_t get_min_annotation(const decode::Row &row); // except instant(end=start) annotation
std::map<const decode::Row, bool> &get_rows_gshow();
std::map<const decode::Row, bool> &get_rows_lshow();
void set_rows_gshow(const decode::Row row, bool show);
void set_rows_lshow(const decode::Row row, bool show);
bool has_annotations(const decode::Row &row) const;
uint64_t list_annotation_size() const;
bool list_annotation(decode::Annotation &ann,
uint16_t row_index, uint64_t col_index) const;
bool list_row_title(int row, QString &title) const;
QString error_message();
void clear();
......@@ -116,11 +129,13 @@ public:
void stop_decode();
int cur_rows_size();
int list_rows_size();
void options_changed(bool changed);
bool options_changed() const;
void set_options_changed(bool changed);
uint64_t sample_count() const;
uint64_t sample_rate() const;
private:
boost::optional<uint64_t> wait_for_data() const;
......@@ -170,9 +185,10 @@ private:
mutable boost::mutex _output_mutex;
int64_t _samples_decoded;
std::map<const decode::Row, decode::RowData> _rows;
std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
std::map<const decode::Row, decode::RowData> _rows;
std::map<const decode::Row, bool> _rows_gshow;
std::map<const decode::Row, bool> _rows_lshow;
std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
QString _error_message;
......@@ -180,6 +196,7 @@ private:
decode_state _decode_state;
bool _options_changed;
bool _no_memory;
friend class DecoderStackTest::TwoDecoderStack;
};
......
/*
* 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 <dreamsourcelab@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 "protocolexp.h"
#include <boost/foreach.hpp>
#include <QFormLayout>
#include <QListWidget>
#include <QMessageBox>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QProgressDialog>
#include <QFuture>
#include <QtConcurrent/QtConcurrent>
#include "../sigsession.h"
#include "../data/decoderstack.h"
#include "../data/decode/row.h"
#include "../data/decode/annotation.h"
#include "../view/decodetrace.h"
#include "../data/decodermodel.h"
using namespace boost;
using namespace std;
namespace pv {
namespace dialogs {
ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) :
QDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this),
_export_cancel(false)
{
_format_combobox = new QComboBox(this);
_format_combobox->addItem(tr("Comma-Separated Values (*.csv)"));
_format_combobox->addItem(tr("Text files (*.txt)"));
_flayout = new QFormLayout();
_flayout->addRow(new QLabel(tr("Export Format: "), this), _format_combobox);
pv::data::DecoderModel* decoder_model = _session.get_decoder_model();
const boost::shared_ptr<pv::data::DecoderStack>& decoder_stack = decoder_model->getDecoderStack();
if (decoder_stack) {
int row_index = 0;
const std::map<const pv::data::decode::Row, bool>& rows(decoder_stack->get_rows_lshow());
for (std::map<const pv::data::decode::Row, bool>::const_iterator i = rows.begin();
i != rows.end(); i++) {
if ((*i).second) {
QLabel *row_label = new QLabel((*i).first.title(), this);
QRadioButton *row_sel = new QRadioButton(this);
if (row_index == 0) {
row_sel->setChecked(true);
}
_row_label_list.push_back(row_label);
_row_sel_list.push_back(row_sel);
_flayout->addRow(row_label, row_sel);
row_sel->setProperty("index", row_index);
row_sel->setProperty("title", (*i).first.title());
row_index++;
}
}
}
_layout = new QVBoxLayout(this);
_layout->addLayout(_flayout);
_layout->addWidget(&_button_box);
setLayout(_layout);
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
}
void ProtocolExp::accept()
{
using namespace Qt;
using namespace pv::data::decode;
QDialog::accept();
if (!_row_sel_list.empty()) {
QList<QString> supportedFormats;
for (int i = _format_combobox->count() - 1; i >= 0; i--) {
supportedFormats.push_back(_format_combobox->itemText(i));
}
QString filter;
for(int i = 0; i < supportedFormats.count();i++){
filter.append(supportedFormats[i]);
if(i < supportedFormats.count() - 1)
filter.append(";;");
}
QString default_filter = _format_combobox->currentText();
QString file_name = QFileDialog::getSaveFileName(
this, tr("Export Data"), "",filter,&default_filter);
if (!file_name.isEmpty()) {
QFileInfo f(file_name);
QStringList list = default_filter.split('.').last().split(')');
QString ext = list.first();
if(f.suffix().compare(ext))
file_name+=tr(".")+ext;
QFile file(file_name);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
QFuture<void> future;
future = QtConcurrent::run([&]{
_export_cancel = false;
QString title;
int index;
for (std::list<QRadioButton *>::const_iterator i = _row_sel_list.begin();
i != _row_sel_list.end(); i++) {
if ((*i)->isChecked()) {
title = (*i)->property("title").toString();
index = (*i)->property("index").toULongLong();
break;
}
}
out << QString("%1;%2;%3\n")
.arg("ID")
.arg("Time[s]")
.arg(title);
pv::data::DecoderModel* decoder_model = _session.get_decoder_model();
const boost::shared_ptr<pv::data::DecoderStack>& decoder_stack = decoder_model->getDecoderStack();
int row_index = 0;
Row row;
const std::map<const Row, bool>& rows_lshow(decoder_stack->get_rows_lshow());
for (std::map<const Row, bool>::const_iterator i = rows_lshow.begin();
i != rows_lshow.end(); i++) {
if ((*i).second) {
if (index == row_index) {
row = (*i).first;
break;
}
row_index++;
}
}
uint64_t exported = 0;
double time_pre_samples = 1.0 / decoder_stack->samplerate();
vector<Annotation> annotations;
decoder_stack->get_annotation_subset(annotations, row,
0, decoder_stack->sample_count()-1);
if (!annotations.empty()) {
BOOST_FOREACH(const Annotation &a, annotations) {
out << QString("%1;%2;%3\n")
.arg(QString::number(exported))
.arg(QString::number(a.start_sample()*time_pre_samples))
.arg(a.annotations().at(0));
exported++;
emit export_progress(exported*100/annotations.size());
if (_export_cancel)
break;
}
}
});
Qt::WindowFlags flags = Qt::CustomizeWindowHint;
QProgressDialog dlg(tr("Export Protocol List Result... It can take a while."),
tr("Cancel"),0,100,this,flags);
dlg.setWindowModality(Qt::WindowModal);
dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
QFutureWatcher<void> watcher;
connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel()));
connect(this,SIGNAL(export_progress(int)),&dlg,SLOT(setValue(int)));
connect(&dlg,SIGNAL(canceled()),this,SLOT(cancel_export()));
watcher.setFuture(future);
dlg.exec();
future.waitForFinished();
file.close();
}
}
}
void ProtocolExp::reject()
{
using namespace Qt;
QDialog::reject();
}
void ProtocolExp::cancel_export()
{
_export_cancel = true;
}
} // namespace dialogs
} // namespace pv
/*
* 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 <dreamsourcelab@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
*/
#ifndef DSVIEW_PV_PROTOCOLEXP_H
#define DSVIEW_PV_PROTOCOLEXP_H
#include <QDialog>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QRadioButton>
#include <QComboBox>
#include <boost/shared_ptr.hpp>
#include "../device/devinst.h"
#include "../prop/binding/deviceoptions.h"
namespace pv {
class SigSession;
namespace data {
namespace decode {
class Row;
}
}
namespace dialogs {
class ProtocolExp : public QDialog
{
Q_OBJECT
public:
ProtocolExp(QWidget *parent, SigSession &session);
protected:
void accept();
void reject();
signals:
void export_progress(int percent);
private slots:
void cancel_export();
private:
SigSession &_session;
QComboBox *_format_combobox;
std::list<QRadioButton *> _row_sel_list;
std::list<QLabel *> _row_label_list;
QFormLayout *_flayout;
QVBoxLayout *_layout;
QDialogButtonBox _button_box;
bool _export_cancel;