parent
45b944de1c
commit
56c7f41faa
|
@ -54,6 +54,8 @@ set(PROJECT_SOURCES
|
||||||
globals/global_configs.cpp
|
globals/global_configs.cpp
|
||||||
|
|
||||||
customs/logfile_treewidgetitem.h
|
customs/logfile_treewidgetitem.h
|
||||||
|
customs/models/logfields_listmodel.h
|
||||||
|
customs/models/logfields_listmodel.cpp
|
||||||
|
|
||||||
utilities/bwlists.h
|
utilities/bwlists.h
|
||||||
utilities/bwutils.cpp
|
utilities/bwutils.cpp
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
|
||||||
|
#include "logfields_listmodel.h"
|
||||||
|
|
||||||
|
#include "modules/shared.h"
|
||||||
|
|
||||||
|
#include "modules/crapview/lib.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
LogFieldsListModel::LogFieldsListModel( real_data_t&& new_data, QObject* parent )
|
||||||
|
: QAbstractListModel{ parent }
|
||||||
|
, real_data{ std::move(new_data) }
|
||||||
|
, view_data( this->real_data.size() )
|
||||||
|
{
|
||||||
|
this->translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogFieldsListModel::translate()
|
||||||
|
{
|
||||||
|
if ( this->real_data.empty() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::transform( this->real_data.cbegin(), this->real_data.cend(), this->view_data.begin(),
|
||||||
|
[](const data_pair_t& p){ return TR::tr( p.second.c_str() ); } );
|
||||||
|
}
|
||||||
|
|
||||||
|
int LogFieldsListModel::rowCount( const QModelIndex& parent ) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return this->view_data.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant LogFieldsListModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( !index.isValid() || index.row() >= this->view_data.count() ) {
|
||||||
|
return QVariant{};
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( role ) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return this->view_data.at( index.row() );
|
||||||
|
case Qt::UserRole:
|
||||||
|
return QVariant::fromValue<LogField>( this->real_data.at( index.row() ).first );
|
||||||
|
default:
|
||||||
|
return QVariant{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DaytimeLogFieldsListModel::DaytimeLogFieldsListModel( QObject* parent )
|
||||||
|
: LogFieldsListModel(
|
||||||
|
{
|
||||||
|
{LogField::Protocol, FIELDS__PROTOCOL},
|
||||||
|
{LogField::Method, FIELDS__METHOD},
|
||||||
|
{LogField::Uri, FIELDS__URI},
|
||||||
|
{LogField::Query, FIELDS__QUERY},
|
||||||
|
{LogField::ResponseCode, FIELDS__RESPONSE_CODE},
|
||||||
|
{LogField::UserAgent, FIELDS__USER_AGENT},
|
||||||
|
{LogField::Client, FIELDS__CLIENT},
|
||||||
|
{LogField::Cookie, FIELDS__COOKIE},
|
||||||
|
{LogField::Referrer, FIELDS__REFERRER}
|
||||||
|
},
|
||||||
|
parent )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RelationslLogFieldsListModel::RelationslLogFieldsListModel( QObject* parent )
|
||||||
|
: LogFieldsListModel(
|
||||||
|
{
|
||||||
|
{LogField::Protocol, FIELDS__PROTOCOL},
|
||||||
|
{LogField::Method, FIELDS__METHOD},
|
||||||
|
{LogField::Uri, FIELDS__URI},
|
||||||
|
{LogField::Query, FIELDS__QUERY},
|
||||||
|
{LogField::ResponseCode, FIELDS__RESPONSE_CODE},
|
||||||
|
{LogField::TimeTaken, FIELDS__TIME_TAKEN},
|
||||||
|
{LogField::BytesSent, FIELDS__BYTES_SENT},
|
||||||
|
{LogField::BytesReceived, FIELDS__BYTES_RECEIVED},
|
||||||
|
{LogField::UserAgent, FIELDS__USER_AGENT},
|
||||||
|
{LogField::Client, FIELDS__CLIENT},
|
||||||
|
{LogField::Cookie, FIELDS__COOKIE},
|
||||||
|
{LogField::Referrer, FIELDS__REFERRER}
|
||||||
|
},
|
||||||
|
parent )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef LOGDOCTOR__CUSTOMS__LOGFIELDS_LISTMODEL_H
|
||||||
|
#define LOGDOCTOR__CUSTOMS__LOGFIELDS_LISTMODEL_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
enum class LogField;
|
||||||
|
|
||||||
|
|
||||||
|
class LogFieldsListModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
protected:
|
||||||
|
using data_pair_t = std::pair<LogField, std::string>;
|
||||||
|
using real_data_t = std::vector<data_pair_t>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LogFieldsListModel( real_data_t&& new_data, QObject* parent=nullptr );
|
||||||
|
virtual ~LogFieldsListModel() = default;
|
||||||
|
|
||||||
|
void translate();
|
||||||
|
|
||||||
|
int rowCount( const QModelIndex& parent=QModelIndex() ) const override;
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
real_data_t real_data;
|
||||||
|
QVector<QString> view_data;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DaytimeLogFieldsListModel final : public LogFieldsListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DaytimeLogFieldsListModel( QObject* parent=nullptr );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class RelationslLogFieldsListModel final : public LogFieldsListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
RelationslLogFieldsListModel( QObject* parent=nullptr );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__CUSTOMS__LOGFIELDS_LISTMODEL_H
|
Loading…
Reference in New Issue