0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 16:11:02 +08:00

Merge branch 'develop' of https://github.com/yse/easy_profiler into develop

This commit is contained in:
Victor Zarubkin 2016-08-09 01:16:16 +03:00
commit c28b720c71
6 changed files with 154 additions and 23 deletions

View File

@ -409,7 +409,8 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
}
else
{
_painter->drawText(rect, 0, item.block->node->getBlockName());
_painter->drawText(rect, 0, ::profiler_gui::toUnicode(item.block->node->getBlockName()));
}
// restore previous pen color
@ -434,7 +435,7 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
pen.setWidth(2);
_painter->setPen(pen);
brush.setColor(previousColor);
brush.setColor(previousColor);
_painter->setBrush(brush);
rect.setRect(item.left() * currentScale - dx, item.top(), ::std::max(item.width() * currentScale, 1.0), item.totalHeight);
@ -446,6 +447,11 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
_painter->restore();
}
QRect ProfGraphicsItem::getRect() const
{
return view()->mapFromScene(m_boundingRect).boundingRect();
}
//////////////////////////////////////////////////////////////////////////
void ProfGraphicsItem::getBlocks(qreal _left, qreal _right, ::profiler_gui::TreeBlocks& _blocks) const
@ -1225,6 +1231,11 @@ void ProfGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr
scaleTo(BASE_SCALE);
}
const ProfGraphicsView::Items &ProfGraphicsView::getItems() const
{
return m_items;
}
qreal ProfGraphicsView::setTree(ProfGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level)
{
static const qreal MIN_DURATION = 0.25;
@ -1814,26 +1825,29 @@ ProfGraphicsViewWidget::ProfGraphicsViewWidget(bool _test)
: QWidget(nullptr)
, m_scrollbar(new ProfGraphicsScrollbar(nullptr))
, m_view(new ProfGraphicsView(_test))
//, m_threadWidget(new ProfThreadViewWidget(this,m_view))
{
auto lay = new QVBoxLayout(this);
lay->setContentsMargins(1, 0, 1, 0);
lay->addWidget(m_view);
lay->setSpacing(1);
lay->addWidget(m_scrollbar);
setLayout(lay);
m_view->setScrollbar(m_scrollbar);
initWidget();
}
ProfGraphicsViewWidget::ProfGraphicsViewWidget(const ::profiler::thread_blocks_tree_t& _blocksTree)
: QWidget(nullptr)
, m_scrollbar(new ProfGraphicsScrollbar(nullptr))
, m_view(new ProfGraphicsView(_blocksTree))
//, m_threadWidget(new ProfThreadViewWidget(this,m_view))
{
auto lay = new QVBoxLayout(this);
initWidget();
}
void ProfGraphicsViewWidget::initWidget()
{
auto lay = new QGridLayout(this);
lay->setContentsMargins(1, 0, 1, 0);
lay->addWidget(m_view);
lay->addWidget(m_view,0,1);
lay->setSpacing(1);
lay->addWidget(m_scrollbar);
lay->addWidget(m_scrollbar,1,1);
//lay->setSpacing(1);
//lay->addWidget(m_threadWidget,0,0);
setLayout(lay);
m_view->setScrollbar(m_scrollbar);
}
@ -1850,3 +1864,48 @@ ProfGraphicsView* ProfGraphicsViewWidget::view()
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
ProfThreadViewWidget::ProfThreadViewWidget(QWidget *parent, ProfGraphicsView* view):QWidget(parent),
m_view(view)
, m_label(new QLabel("",this))
{
m_layout = new QHBoxLayout;
//QPushButton *button1 = new QPushButton();
//m_layout->addWidget(m_label);
//setLayout(m_layout);
//show();
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::ProfGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
}
ProfThreadViewWidget::~ProfThreadViewWidget()
{
}
void ProfThreadViewWidget::onSelectedThreadChange()
{
/*
auto threadName = ::profiler_gui::EASY_GLOBALS.profiler_blocks[::profiler_gui::EASY_GLOBALS.selected_thread].thread_name;
if(threadName[0]!=0)
{
m_label->setText(threadName);
}
else
{
m_label->setText(QString("Thread %1").arg(::profiler_gui::EASY_GLOBALS.selected_thread));
}
*/
QLayoutItem *ditem;
while ((ditem = m_layout->takeAt(0)))
delete ditem;
const auto& items = m_view->getItems();
for(const auto& item: items)
{
m_layout->addWidget(new QLabel(QString("Thread %1").arg(item->threadId())));
m_layout->setSpacing(1);
}
setLayout(m_layout);
}

View File

@ -30,6 +30,8 @@
#include <QFont>
#include <QPoint>
#include <QTimer>
#include <QLabel>
#include <QLayout>
#include <stdlib.h>
#include "graphics_scrollbar.h"
#include "profiler/reader.h"
@ -64,12 +66,15 @@ public:
// Public virtual methods
QRectF boundingRect() const override;
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
public:
// Public non-virtual methods
QRect getRect() const;
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
void setBoundingRect(const QRectF& _rect);
@ -263,6 +268,8 @@ public:
void test(unsigned int _frames_number, unsigned int _total_items_number_estimate, int _rows);
void setTree(const ::profiler::thread_blocks_tree_t& _blocksTree);
const Items& getItems() const;
signals:
// Signals
@ -341,6 +348,24 @@ private:
}; // END of class ProfGraphicsView.
class ProfThreadViewWidget : public QWidget
{
Q_OBJECT
private:
ProfGraphicsView* m_view;
QLabel* m_label;
typedef ProfThreadViewWidget This;
QHBoxLayout *m_layout;
public:
ProfThreadViewWidget(QWidget *parent, ProfGraphicsView* view);
virtual ~ProfThreadViewWidget();
public slots:
void onSelectedThreadChange();
};
//////////////////////////////////////////////////////////////////////////
class ProfGraphicsViewWidget : public QWidget
@ -351,6 +376,7 @@ private:
ProfGraphicsView* m_view;
ProfGraphicsScrollbar* m_scrollbar;
//ProfThreadViewWidget* m_threadWidget;
public:
@ -362,8 +388,11 @@ public:
private:
void initWidget();
}; // END of class ProfGraphicsViewWidget.
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

View File

@ -522,11 +522,7 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks
auto item = new ProfTreeWidgetItem(block.tree, thread_item);
duration = endTime - startTime;
/*QByteArray msg(block.tree->node->getBlockName());
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QString strf = codec->toUnicode(msg);
*/
item->setText(COL_NAME, block.tree->node->getBlockName());
item->setText(COL_NAME, ::profiler_gui::toUnicode(block.tree->node->getBlockName()));
item->setTimeSmart(COL_DURATION, duration);
item->setTimeMs(COL_BEGIN, startTime - m_beginTime);
item->setTimeMs(COL_END, endTime - m_beginTime);
@ -672,12 +668,8 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler::BlocksTree::children_t&
continue;
}
/*QByteArray msg(child.node->getBlockName());
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QString strf = codec->toUnicode(msg);*/
auto item = new ProfTreeWidgetItem(&child, _parent);
item->setText(COL_NAME, child.node->getBlockName());
item->setText(COL_NAME, ::profiler_gui::toUnicode(child.node->getBlockName()));
item->setTimeSmart(COL_DURATION, duration);
item->setTimeMs(COL_BEGIN, startTime - m_beginTime);
item->setTimeMs(COL_END, endTime - m_beginTime);

View File

@ -21,6 +21,7 @@
#include <string>
#include <QObject>
#include <QColor>
#include <QTextCodec>
#include "common_types.h"
#include "globals_qobjects.h"
@ -56,6 +57,12 @@ namespace profiler_gui {
typedef ::std::vector<ProfBlock> ProfBlocks;
template <class T>
inline QString toUnicode(const T& _inputString)
{
return QTextCodec::codecForLocale()->toUnicode(_inputString);
}
//////////////////////////////////////////////////////////////////////////
struct ProfGlobals final

View File

@ -34,7 +34,7 @@
#include "blocks_tree_widget.h"
#include "blocks_graphics_view.h"
#include "globals.h"
#include <QTextCodec>
//////////////////////////////////////////////////////////////////////////
ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graphicsView(nullptr)
@ -84,6 +84,40 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
menu->addAction(actionTestView);
menuBar()->addMenu(menu);
QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
settings.beginGroup("main");
QString encoding = settings.value("encoding","UTF-8").toString();
auto default_codec_mib = QTextCodec::codecForName(encoding.toStdString().c_str())->mibEnum() ;
auto default_codec = QTextCodec::codecForMib(default_codec_mib);
QTextCodec::setCodecForLocale(default_codec);
settings.endGroup();
menu = new QMenu("Settings");
auto encodingMenu = menu->addMenu(tr("&Encoding"));
QActionGroup* codecs_actions = new QActionGroup(this);
codecs_actions->setExclusive(true);
foreach (int mib, QTextCodec::availableMibs())
{
auto codec = QTextCodec::codecForMib(mib)->name();
QAction* action = new QAction(codec,codecs_actions);
action->setCheckable(true);
if(mib == default_codec_mib)
{
action->setChecked(true);
}
encodingMenu->addAction(action);
connect(action, &QAction::triggered, this, &This::onEncodingChanged);
}
menuBar()->addMenu(menu);
connect(graphicsView->view(), &ProfGraphicsView::intervalChanged, treeWidget, &ProfTreeWidget::setTreeBlocks);
loadSettings();
@ -179,6 +213,14 @@ void ProfMainWindow::onTestViewportClicked(bool)
//view->test(3, 300, 1);
}
void ProfMainWindow::onEncodingChanged(bool)
{
auto _sender = qobject_cast<QAction*>(sender());
auto name = _sender->text();
QTextCodec *codec = QTextCodec::codecForName(name.toStdString().c_str());
QTextCodec::setCodecForLocale(codec);
}
//////////////////////////////////////////////////////////////////////////
void ProfMainWindow::closeEvent(QCloseEvent* close_event)
@ -216,6 +258,7 @@ void ProfMainWindow::saveSettings()
settings.setValue("geometry", this->saveGeometry());
settings.setValue("last_file", m_lastFile.c_str());
settings.setValue("encoding", QTextCodec::codecForLocale()->name());
settings.endGroup();
}

View File

@ -54,6 +54,7 @@ protected slots:
void onReloadFileClicked(bool);
void onExitClicked(bool);
void onTestViewportClicked(bool);
void onEncodingChanged(bool);
private: