mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 00:27:55 +08:00
(profiler_gui) Small design tweaking;
(profiler_gui) Added possibility to change where chronometer (time-meter) item text will be painted: at the top of the scene, in the center or at the bottom of the scene. See menu View -> Chronometer text.
This commit is contained in:
parent
bb7e288c1c
commit
3a2c8aaef1
@ -58,7 +58,7 @@ const qreal MIN_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT_INV, 70);
|
||||
const qreal MAX_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT, 30); // ~800
|
||||
const qreal BASE_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT_INV, 25); // ~0.003
|
||||
|
||||
const unsigned short GRAPHICS_ROW_SIZE = 16;
|
||||
const unsigned short GRAPHICS_ROW_SIZE = 18;
|
||||
const unsigned short GRAPHICS_ROW_SPACING = 2;
|
||||
const unsigned short GRAPHICS_ROW_SIZE_FULL = GRAPHICS_ROW_SIZE + GRAPHICS_ROW_SPACING;
|
||||
const unsigned short THREADS_ROW_SPACING = 8;
|
||||
@ -76,6 +76,7 @@ const unsigned int TEST_PROGRESSION_BASE = 4;
|
||||
const int FLICKER_INTERVAL = 16; // 60Hz
|
||||
|
||||
const auto CHRONOMETER_FONT = QFont("CourierNew", 16, 2);
|
||||
const auto ITEMS_FONT = QFont("CourierNew", 10);// , 2);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -143,6 +144,7 @@ void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
|
||||
_painter->save();
|
||||
_painter->setFont(ITEMS_FONT);
|
||||
|
||||
// Reset indices of first visible item for each layer
|
||||
const auto levelsNumber = levels();
|
||||
@ -861,15 +863,29 @@ void EasyChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
rect.setWidth((sceneRight - offset) * currentScale - rect.left());
|
||||
}
|
||||
|
||||
if (!m_bMain)
|
||||
int textFlags = 0;
|
||||
switch (::profiler_gui::EASY_GLOBALS.chrono_text_position)
|
||||
{
|
||||
rect.setTop(rect.top() + textRect.height() * 1.5);
|
||||
case ::profiler_gui::ChronoTextPosition_Top:
|
||||
textFlags = Qt::AlignTop | Qt::AlignHCenter;
|
||||
if (!m_bMain) rect.setTop(rect.top() + textRect.height() * 0.75);
|
||||
break;
|
||||
|
||||
case ::profiler_gui::ChronoTextPosition_Center:
|
||||
textFlags = Qt::AlignCenter;
|
||||
if (!m_bMain) rect.setTop(rect.top() + textRect.height() * 1.5);
|
||||
break;
|
||||
|
||||
case ::profiler_gui::ChronoTextPosition_Bottom:
|
||||
textFlags = Qt::AlignBottom | Qt::AlignHCenter;
|
||||
if (!m_bMain) rect.setHeight(rect.height() - textRect.height() * 0.75);
|
||||
break;
|
||||
}
|
||||
|
||||
if (textRect.width() < rect.width())
|
||||
{
|
||||
// Text will be drawed inside rectangle
|
||||
_painter->drawText(rect, Qt::AlignCenter, text);
|
||||
_painter->drawText(rect, textFlags, text);
|
||||
_painter->restore();
|
||||
return;
|
||||
}
|
||||
@ -877,18 +893,20 @@ void EasyChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
|
||||
if (m_right + textRect.width() < sceneRight)
|
||||
{
|
||||
// Text will be drawed to the right of rectangle
|
||||
_painter->drawText(QPointF(rect.right(), rect.top() + rect.height() * 0.5 + textRect.height() * 0.33), text);
|
||||
rect.translate(rect.width(), 0);
|
||||
textFlags &= ~Qt::AlignHCenter;
|
||||
textFlags |= Qt::AlignLeft;
|
||||
}
|
||||
else if (m_left - textRect.width() > sceneLeft)
|
||||
{
|
||||
// Text will be drawed to the left of rectangle
|
||||
_painter->drawText(QPointF(rect.left() - textRect.width(), rect.top() + rect.height() * 0.5 + textRect.height() * 0.33), text);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Text will be drawed inside rectangle
|
||||
_painter->drawText(rect, Qt::AlignCenter | Qt::TextDontClip, text);
|
||||
rect.translate(-rect.width(), 0);
|
||||
textFlags &= ~Qt::AlignHCenter;
|
||||
textFlags |= Qt::AlignRight;
|
||||
}
|
||||
//else // Text will be drawed inside rectangle
|
||||
|
||||
_painter->drawText(rect, textFlags | Qt::TextDontClip, text);
|
||||
|
||||
_painter->restore();
|
||||
// END Paint!~~~~~~~~~~~~~~~~~~~~~~
|
||||
@ -1980,9 +1998,13 @@ void EasyGraphicsView::initMode()
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &This::onScrollbarValueChange);
|
||||
connect(&m_flickerTimer, &QTimer::timeout, this, &This::onFlickerTimeout);
|
||||
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
||||
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange);
|
||||
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::itemsExpandStateChanged, this, &This::onItemsEspandStateChange);
|
||||
|
||||
auto globalSignals = &::profiler_gui::EASY_GLOBALS.events;
|
||||
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
||||
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange);
|
||||
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::itemsExpandStateChanged, this, &This::onItemsEspandStateChange);
|
||||
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::drawBordersChanged, this, &This::updateScene);
|
||||
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::chronoPositionChanged, this, &This::updateScene);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -322,7 +322,6 @@ private:
|
||||
void initMode();
|
||||
void updateVisibleSceneRect();
|
||||
void updateTimelineStep(qreal _windowWidth);
|
||||
void updateScene();
|
||||
void scaleTo(qreal _scale);
|
||||
void onWheel(qreal _mouseX, int _wheelDelta);
|
||||
qreal setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, qreal _y, short _level);
|
||||
@ -331,6 +330,7 @@ private slots:
|
||||
|
||||
// Private Slots
|
||||
|
||||
void updateScene();
|
||||
void onGraphicsScrollbarWheel(qreal _mouseX, int _wheelDelta);
|
||||
void onScrollbarValueChange(int);
|
||||
void onGraphicsScrollbarValueChange(qreal);
|
||||
|
@ -32,7 +32,8 @@ namespace profiler_gui {
|
||||
|
||||
EasyGlobals::EasyGlobals()
|
||||
: selected_thread(0)
|
||||
, selected_block(-1)
|
||||
, selected_block(::profiler_gui::numeric_max<decltype(selected_block)>())
|
||||
, chrono_text_position(ChronoTextPosition_Center)
|
||||
, draw_graphics_items_borders(true)
|
||||
, display_only_relevant_stats(true)
|
||||
, collapse_items_on_tree_close(false)
|
||||
|
@ -63,6 +63,16 @@ namespace profiler_gui {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum ChronometerTextPosition
|
||||
{
|
||||
ChronoTextPosition_Center = 0,
|
||||
ChronoTextPosition_Top,
|
||||
ChronoTextPosition_Bottom,
|
||||
|
||||
}; // END of enum ChronometerTextPosition.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct EasyGlobals final
|
||||
{
|
||||
static EasyGlobals& instance();
|
||||
@ -72,6 +82,7 @@ namespace profiler_gui {
|
||||
EasyBlocks gui_blocks; ///< Profiler graphics blocks builded by GUI
|
||||
::profiler::thread_id_t selected_thread; ///< Current selected thread id
|
||||
unsigned int selected_block; ///< Current selected profiler block index
|
||||
ChronometerTextPosition chrono_text_position; ///<
|
||||
bool draw_graphics_items_borders; ///< Draw borders for graphics blocks or not
|
||||
bool display_only_relevant_stats; ///< Display only relevant information in ProfTreeWidget (excludes min, max, average times if there are only 1 calls number)
|
||||
bool collapse_items_on_tree_close; ///< Collapse all items which were displayed in the hierarchy tree after tree close/reset
|
||||
@ -82,7 +93,9 @@ namespace profiler_gui {
|
||||
private:
|
||||
|
||||
EasyGlobals();
|
||||
};
|
||||
|
||||
}; // END of struct EasyGlobals.
|
||||
|
||||
#ifndef IGNORE_GLOBALS_DECLARATION
|
||||
static EasyGlobals& EASY_GLOBALS = EasyGlobals::instance();
|
||||
#endif
|
||||
|
@ -20,6 +20,8 @@ namespace profiler_gui {
|
||||
void selectedThreadChanged(::profiler::thread_id_t _id);
|
||||
void selectedBlockChanged(unsigned int _block_index);
|
||||
void itemsExpandStateChanged();
|
||||
void drawBordersChanged();
|
||||
void chronoPositionChanged();
|
||||
|
||||
}; // END of class EasyGlobalSignals.
|
||||
|
||||
|
@ -326,6 +326,7 @@ EasyGraphicsScrollbar::EasyGraphicsScrollbar(QWidget* _parent)
|
||||
m_slider->setPos(0, 0);
|
||||
m_slider->setColor(0x40c0c0c0);
|
||||
selfScene->addItem(m_slider);
|
||||
m_slider->hide();
|
||||
|
||||
centerOn(0, 0);
|
||||
}
|
||||
@ -430,6 +431,7 @@ void EasyGraphicsScrollbar::hideChrono()
|
||||
void EasyGraphicsScrollbar::setMinimapFrom(::profiler::thread_id_t _thread_id, const ::profiler_gui::ProfItems* _items)
|
||||
{
|
||||
m_minimap->setSource(_thread_id, _items);
|
||||
m_slider->setVisible(m_minimap->isVisible());
|
||||
scene()->update();
|
||||
}
|
||||
|
||||
|
@ -118,26 +118,55 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_treeWidget(nullptr), m_graphicsVi
|
||||
action->setChecked(::profiler_gui::EASY_GLOBALS.bind_scene_and_tree_expand_status);
|
||||
connect(action, &QAction::triggered, this, &This::onBindExpandStatusChange);
|
||||
|
||||
menu->addSeparator();
|
||||
auto submenu = menu->addMenu("Chronometer text");
|
||||
auto actionGroup = new QActionGroup(this);
|
||||
actionGroup->setExclusive(true);
|
||||
|
||||
action = new QAction("At top", actionGroup);
|
||||
action->setCheckable(true);
|
||||
action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Top));
|
||||
if (::profiler_gui::EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Top)
|
||||
action->setChecked(true);
|
||||
submenu->addAction(action);
|
||||
connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
|
||||
|
||||
action = new QAction("At center", actionGroup);
|
||||
action->setCheckable(true);
|
||||
action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Center));
|
||||
if (::profiler_gui::EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Center)
|
||||
action->setChecked(true);
|
||||
submenu->addAction(action);
|
||||
connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
|
||||
|
||||
action = new QAction("At bottom", actionGroup);
|
||||
action->setCheckable(true);
|
||||
action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Bottom));
|
||||
if (::profiler_gui::EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Bottom)
|
||||
action->setChecked(true);
|
||||
submenu->addAction(action);
|
||||
connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
|
||||
|
||||
menuBar()->addMenu(menu);
|
||||
|
||||
menu = new QMenu("&Settings");
|
||||
auto encodingMenu = menu->addMenu(tr("&Encoding"));
|
||||
|
||||
QActionGroup* codecs_actions = new QActionGroup(this);
|
||||
codecs_actions->setExclusive(true);
|
||||
|
||||
menu = new QMenu("&Settings");
|
||||
submenu = menu->addMenu("&Encoding");
|
||||
actionGroup = new QActionGroup(this);
|
||||
actionGroup->setExclusive(true);
|
||||
|
||||
auto default_codec_mib = QTextCodec::codecForLocale()->mibEnum();
|
||||
foreach (int mib, QTextCodec::availableMibs())
|
||||
{
|
||||
auto codec = QTextCodec::codecForMib(mib)->name();
|
||||
|
||||
QAction* action = new QAction(codec,codecs_actions);
|
||||
|
||||
action = new QAction(codec, actionGroup);
|
||||
action->setCheckable(true);
|
||||
if(mib == default_codec_mib)
|
||||
{
|
||||
if (mib == default_codec_mib)
|
||||
action->setChecked(true);
|
||||
}
|
||||
encodingMenu->addAction(action);
|
||||
|
||||
submenu->addAction(action);
|
||||
connect(action, &QAction::triggered, this, &This::onEncodingChanged);
|
||||
}
|
||||
|
||||
@ -238,9 +267,17 @@ void EasyMainWindow::onEncodingChanged(bool)
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
}
|
||||
|
||||
void EasyMainWindow::onChronoTextPosChanged(bool)
|
||||
{
|
||||
auto _sender = qobject_cast<QAction*>(sender());
|
||||
::profiler_gui::EASY_GLOBALS.chrono_text_position = static_cast<::profiler_gui::ChronometerTextPosition>(_sender->data().toInt());
|
||||
emit ::profiler_gui::EASY_GLOBALS.events.chronoPositionChanged();
|
||||
}
|
||||
|
||||
void EasyMainWindow::onDrawBordersChanged(bool _checked)
|
||||
{
|
||||
::profiler_gui::EASY_GLOBALS.draw_graphics_items_borders = _checked;
|
||||
emit ::profiler_gui::EASY_GLOBALS.events.drawBordersChanged();
|
||||
}
|
||||
|
||||
void EasyMainWindow::onCollapseItemsAfterCloseChanged(bool _checked)
|
||||
@ -305,6 +342,14 @@ void EasyMainWindow::loadSettings()
|
||||
m_lastFile = last_file.toString();
|
||||
}
|
||||
|
||||
|
||||
auto val = settings.value("chrono_text_position");
|
||||
if (!val.isNull())
|
||||
{
|
||||
::profiler_gui::EASY_GLOBALS.chrono_text_position = static_cast<::profiler_gui::ChronometerTextPosition>(val.toInt());
|
||||
}
|
||||
|
||||
|
||||
auto flag = settings.value("draw_graphics_items_borders");
|
||||
if (!flag.isNull())
|
||||
{
|
||||
@ -354,6 +399,7 @@ void EasyMainWindow::saveSettingsAndGeometry()
|
||||
|
||||
settings.setValue("geometry", this->saveGeometry());
|
||||
settings.setValue("last_file", m_lastFile);
|
||||
settings.setValue("chrono_text_position", static_cast<int>(::profiler_gui::EASY_GLOBALS.chrono_text_position));
|
||||
settings.setValue("draw_graphics_items_borders", ::profiler_gui::EASY_GLOBALS.draw_graphics_items_borders);
|
||||
settings.setValue("collapse_items_on_tree_close", ::profiler_gui::EASY_GLOBALS.collapse_items_on_tree_close);
|
||||
settings.setValue("all_items_expanded_by_default", ::profiler_gui::EASY_GLOBALS.all_items_expanded_by_default);
|
||||
|
@ -90,6 +90,7 @@ protected slots:
|
||||
void onReloadFileClicked(bool);
|
||||
void onExitClicked(bool);
|
||||
void onEncodingChanged(bool);
|
||||
void onChronoTextPosChanged(bool);
|
||||
void onDrawBordersChanged(bool);
|
||||
void onCollapseItemsAfterCloseChanged(bool);
|
||||
void onAllItemsExpandedByDefaultChange(bool);
|
||||
|
Loading…
x
Reference in New Issue
Block a user