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

(profiler GUI) Store settings for application. Now is main geometry and

columns settings in blocks tree widget and colorized settings.
This commit is contained in:
Sergey Yagovtsev 2016-08-04 23:12:41 +03:00
parent 57d8bc85e3
commit 8346e50688
5 changed files with 116 additions and 27 deletions

View File

@ -28,6 +28,9 @@
#include <QMenu> #include <QMenu>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QSignalBlocker> #include <QSignalBlocker>
#include <QSettings>
#include <qtextcodec.h>
#include "blocks_tree_widget.h" #include "blocks_tree_widget.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -64,6 +67,7 @@ ProfTreeWidgetItem::ProfTreeWidgetItem(const ::profiler::BlocksTree* _treeBlock,
, m_customBGColor(0) , m_customBGColor(0)
, m_customTextColor(0) , m_customTextColor(0)
{ {
} }
ProfTreeWidgetItem::~ProfTreeWidgetItem() ProfTreeWidgetItem::~ProfTreeWidgetItem()
@ -234,9 +238,23 @@ ProfTreeWidget::ProfTreeWidget(QWidget* _parent) : Parent(_parent), m_beginTime(
header->setText(COL_NCALLS_TOTAL, "N Calls total"); header->setText(COL_NCALLS_TOTAL, "N Calls total");
setHeaderItem(header); setHeaderItem(header);
hideColumn(COL_END); //hideColumn(COL_END);
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::ProfGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange); connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::ProfGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME);
settings.beginGroup("tree_widget");
auto color_rows_set = settings.value("color_rows");
if (!color_rows_set.isNull())
m_bColorRows = color_rows_set.toBool();
for (int i = 0; i < columnCount(); i++)
{
if (settings.value(QString("Column") + QString::number(i)).toBool())
hideColumn(i);
}
settings.endGroup();
} }
ProfTreeWidget::ProfTreeWidget(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, QWidget* _parent) : This(_parent) ProfTreeWidget::ProfTreeWidget(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, QWidget* _parent) : This(_parent)
@ -252,6 +270,7 @@ ProfTreeWidget::ProfTreeWidget(const unsigned int _blocksNumber, const ::profile
ProfTreeWidget::~ProfTreeWidget() ProfTreeWidget::~ProfTreeWidget()
{ {
saveSettings();
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -452,7 +471,11 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks
auto item = new ProfTreeWidgetItem(block.tree, thread_item); auto item = new ProfTreeWidgetItem(block.tree, thread_item);
duration = endTime - startTime; duration = endTime - startTime;
item->setText(COL_NAME, block.tree->node->getBlockName()); /*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->setTimeSmart(COL_DURATION, duration); item->setTimeSmart(COL_DURATION, duration);
item->setTimeMs(COL_BEGIN, startTime - m_beginTime); item->setTimeMs(COL_BEGIN, startTime - m_beginTime);
item->setTimeMs(COL_END, endTime - m_beginTime); item->setTimeMs(COL_END, endTime - m_beginTime);
@ -577,8 +600,12 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler::BlocksTree::children_t&
continue; continue;
} }
/*QByteArray msg(child.node->getBlockName());
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QString strf = codec->toUnicode(msg);*/
auto item = new ProfTreeWidgetItem(&child, _parent); auto item = new ProfTreeWidgetItem(&child, _parent);
item->setText(COL_NAME, child.node->getBlockName()); item->setText(COL_NAME, child.node->getBlockName());
item->setTimeSmart(COL_DURATION, duration); item->setTimeSmart(COL_DURATION, duration);
item->setTimeMs(COL_BEGIN, startTime - m_beginTime); item->setTimeMs(COL_BEGIN, startTime - m_beginTime);
item->setTimeMs(COL_END, endTime - m_beginTime); item->setTimeMs(COL_END, endTime - m_beginTime);
@ -736,15 +763,21 @@ void ProfTreeWidget::contextMenuEvent(QContextMenuEvent* _event)
auto hidemenu = menu.addMenu("Select columns"); auto hidemenu = menu.addMenu("Select columns");
auto hdr = headerItem(); auto hdr = headerItem();
for (int i = 0; i < COL_COLUMNS_NUMBER; ++i)
QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME);
settings.beginGroup("tree_widget");
for (int i = 0; i < COL_COLUMNS_NUMBER; ++i)
{ {
auto columnAction = new ProfHideShowColumnAction(hdr->text(i), i); auto columnAction = new ProfHideShowColumnAction(hdr->text(i), i);
columnAction->setCheckable(true); columnAction->setCheckable(true);
columnAction->setChecked(!isColumnHidden(i)); columnAction->setChecked(!isColumnHidden(i));
connect(columnAction, &ProfHideShowColumnAction::clicked, this, &This::onHideShowColumn); connect(columnAction, &ProfHideShowColumnAction::clicked, this, &This::onHideShowColumn);
hidemenu->addAction(columnAction); hidemenu->addAction(columnAction);
} }
settings.endGroup();
menu.exec(QCursor::pos()); menu.exec(QCursor::pos());
_event->accept(); _event->accept();
@ -873,3 +906,18 @@ void ProfTreeWidget::onHideShowColumn(int _column)
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ProfTreeWidget::saveSettings()
{
QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME);
settings.beginGroup("tree_widget");
settings.setValue("color_rows", m_bColorRows);
for (int i = 0; i < columnCount(); i++)
{
settings.setValue(QString("Column") + QString::number(i) , isColumnHidden(i));
}
settings.endGroup();
}

View File

@ -1,25 +1,25 @@
/************************************************************************ /************************************************************************
* file name : blocks_tree_widget.h * file name : blocks_tree_widget.h
* ----------------- : * ----------------- :
* creation time : 2016/06/26 * creation time : 2016/06/26
* copyright : (c) 2016 Victor Zarubkin * copyright : (c) 2016 Victor Zarubkin
* author : Victor Zarubkin * author : Victor Zarubkin
* email : v.s.zarubkin@gmail.com * email : v.s.zarubkin@gmail.com
* ----------------- : * ----------------- :
* description : The file contains declaration of TreeWidget and it's auxiliary classes * description : The file contains declaration of TreeWidget and it's auxiliary classes
* : for displyaing easy_profiler blocks tree. * : for displyaing easy_profiler blocks tree.
* ----------------- : * ----------------- :
* change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h * change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h
* : and renamed classes from My* to Prof*. * : and renamed classes from My* to Prof*.
* : * :
* : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows * : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows
* : with profiler blocks' colors. * : with profiler blocks' colors.
* : * :
* : * 2016/06/29 Victor Zarubkin: Added clearSilent() method. * : * 2016/06/29 Victor Zarubkin: Added clearSilent() method.
* : * :
* : * * : *
* ----------------- : * ----------------- :
* license : TODO: add license text * license : TODO: add license text
************************************************************************/ ************************************************************************/
#ifndef MY____TREE___VIEW_H #ifndef MY____TREE___VIEW_H
@ -91,10 +91,10 @@ public: \
connect(this, &QAction::triggered, this, &ClassName::onToggle); } \ connect(this, &QAction::triggered, this, &ClassName::onToggle); } \
virtual ~ClassName() {}\ virtual ~ClassName() {}\
private: \ private: \
void onToggle(bool) { emit clicked(m_item); } void onToggle(bool) { emit clicked(m_item); }
DECLARE_QACTION(ProfItemAction, ProfTreeWidgetItem*) signals: void clicked(ProfTreeWidgetItem* _item); }; DECLARE_QACTION(ProfItemAction, ProfTreeWidgetItem*) signals: void clicked(ProfTreeWidgetItem* _item); };
DECLARE_QACTION(ProfHideShowColumnAction, int) signals: void clicked(int _item); }; DECLARE_QACTION(ProfHideShowColumnAction, int) signals: void clicked(int _item); };
#undef DECLARE_QACTION #undef DECLARE_QACTION
@ -165,6 +165,10 @@ private slots:
void onHideShowColumn(int _column); void onHideShowColumn(int _column);
protected:
void saveSettings();
}; // END of class ProfTreeWidget. }; // END of class ProfTreeWidget.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View File

@ -32,6 +32,9 @@ class ProfTreeWidgetItem;
namespace profiler_gui { namespace profiler_gui {
const QString ORGANAZATION_NAME = "EasyProfiler";
const QString APPLICATION_NAME = "Easy profiler gui application";
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
class ProfGlobalSignals final : public QObject class ProfGlobalSignals final : public QObject

View File

@ -28,6 +28,9 @@
#include <QMenu> #include <QMenu>
#include <QMenuBar> #include <QMenuBar>
#include <QCoreApplication> #include <QCoreApplication>
#include <qevent.h>
#include <QSettings>
#include "main_window.h" #include "main_window.h"
#include "blocks_tree_widget.h" #include "blocks_tree_widget.h"
#include "blocks_graphics_view.h" #include "blocks_graphics_view.h"
@ -90,6 +93,17 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
auto opened_filename = QCoreApplication::arguments().at(1).toStdString(); auto opened_filename = QCoreApplication::arguments().at(1).toStdString();
loadFile(opened_filename); loadFile(opened_filename);
} }
QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME);
settings.beginGroup("main");
auto geometry = settings.value("geometry").toByteArray();
if (!geometry.isEmpty()){
restoreGeometry(geometry);
}
settings.endGroup();
} }
ProfMainWindow::~ProfMainWindow() ProfMainWindow::~ProfMainWindow()
@ -176,6 +190,23 @@ void ProfMainWindow::onTestViewportClicked(bool)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ProfMainWindow::closeEvent(QCloseEvent *close_event)
{
saveSettings();
close_event->setAccepted(true);
QMainWindow::closeEvent(close_event);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ProfMainWindow::saveSettings()
{
QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME);
settings.beginGroup("main");
settings.setValue("geometry", this->saveGeometry());
settings.endGroup();
}

View File

@ -54,6 +54,9 @@ protected slots:
private: private:
void loadFile(const std::string& filename); void loadFile(const std::string& filename);
void closeEvent(QCloseEvent *close_event);
void saveSettings();
}; // END of class ProfMainWindow. }; // END of class ProfMainWindow.