diff --git a/profiler_gui/blocks_tree_widget.cpp b/profiler_gui/blocks_tree_widget.cpp index a322912..a34a6c6 100644 --- a/profiler_gui/blocks_tree_widget.cpp +++ b/profiler_gui/blocks_tree_widget.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include + #include "blocks_tree_widget.h" ////////////////////////////////////////////////////////////////////////// @@ -64,6 +67,7 @@ ProfTreeWidgetItem::ProfTreeWidgetItem(const ::profiler::BlocksTree* _treeBlock, , m_customBGColor(0) , m_customTextColor(0) { + } ProfTreeWidgetItem::~ProfTreeWidgetItem() @@ -234,9 +238,23 @@ ProfTreeWidget::ProfTreeWidget(QWidget* _parent) : Parent(_parent), m_beginTime( header->setText(COL_NCALLS_TOTAL, "N Calls total"); setHeaderItem(header); - hideColumn(COL_END); - + //hideColumn(COL_END); 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) @@ -252,6 +270,7 @@ ProfTreeWidget::ProfTreeWidget(const unsigned int _blocksNumber, const ::profile ProfTreeWidget::~ProfTreeWidget() { + saveSettings(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -452,7 +471,11 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks auto item = new ProfTreeWidgetItem(block.tree, thread_item); 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->setTimeMs(COL_BEGIN, startTime - m_beginTime); item->setTimeMs(COL_END, endTime - m_beginTime); @@ -577,8 +600,12 @@ 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, child.node->getBlockName()); item->setTimeSmart(COL_DURATION, duration); item->setTimeMs(COL_BEGIN, startTime - 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 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); columnAction->setCheckable(true); - columnAction->setChecked(!isColumnHidden(i)); + columnAction->setChecked(!isColumnHidden(i)); connect(columnAction, &ProfHideShowColumnAction::clicked, this, &This::onHideShowColumn); hidemenu->addAction(columnAction); } + settings.endGroup(); + menu.exec(QCursor::pos()); _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(); +} diff --git a/profiler_gui/blocks_tree_widget.h b/profiler_gui/blocks_tree_widget.h index 4daa41b..6d921da 100644 --- a/profiler_gui/blocks_tree_widget.h +++ b/profiler_gui/blocks_tree_widget.h @@ -1,25 +1,25 @@ -/************************************************************************ -* file name : blocks_tree_widget.h -* ----------------- : -* creation time : 2016/06/26 -* copyright : (c) 2016 Victor Zarubkin -* author : Victor Zarubkin -* email : v.s.zarubkin@gmail.com -* ----------------- : -* description : The file contains declaration of TreeWidget and it's auxiliary classes -* : for displyaing easy_profiler blocks tree. -* ----------------- : -* change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h -* : and renamed classes from My* to Prof*. -* : +/************************************************************************ +* file name : blocks_tree_widget.h +* ----------------- : +* creation time : 2016/06/26 +* copyright : (c) 2016 Victor Zarubkin +* author : Victor Zarubkin +* email : v.s.zarubkin@gmail.com +* ----------------- : +* description : The file contains declaration of TreeWidget and it's auxiliary classes +* : for displyaing easy_profiler blocks tree. +* ----------------- : +* change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h +* : and renamed classes from My* to Prof*. +* : * : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows * : with profiler blocks' colors. * : * : * 2016/06/29 Victor Zarubkin: Added clearSilent() method. * : -* : * -* ----------------- : -* license : TODO: add license text +* : * +* ----------------- : +* license : TODO: add license text ************************************************************************/ #ifndef MY____TREE___VIEW_H @@ -91,10 +91,10 @@ public: \ connect(this, &QAction::triggered, this, &ClassName::onToggle); } \ virtual ~ClassName() {}\ 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(ProfHideShowColumnAction, int) signals: void clicked(int _item); }; +DECLARE_QACTION(ProfItemAction, ProfTreeWidgetItem*) signals: void clicked(ProfTreeWidgetItem* _item); }; +DECLARE_QACTION(ProfHideShowColumnAction, int) signals: void clicked(int _item); }; #undef DECLARE_QACTION @@ -165,6 +165,10 @@ private slots: void onHideShowColumn(int _column); +protected: + + void saveSettings(); + }; // END of class ProfTreeWidget. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/globals.h b/profiler_gui/globals.h index 8e73302..7682fc5 100644 --- a/profiler_gui/globals.h +++ b/profiler_gui/globals.h @@ -32,6 +32,9 @@ class ProfTreeWidgetItem; namespace profiler_gui { + const QString ORGANAZATION_NAME = "EasyProfiler"; + const QString APPLICATION_NAME = "Easy profiler gui application"; + ////////////////////////////////////////////////////////////////////////// class ProfGlobalSignals final : public QObject diff --git a/profiler_gui/main_window.cpp b/profiler_gui/main_window.cpp index 0c96772..578c3e5 100644 --- a/profiler_gui/main_window.cpp +++ b/profiler_gui/main_window.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include + #include "main_window.h" #include "blocks_tree_widget.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(); 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() @@ -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(); +} + diff --git a/profiler_gui/main_window.h b/profiler_gui/main_window.h index 4c16a91..abfc473 100644 --- a/profiler_gui/main_window.h +++ b/profiler_gui/main_window.h @@ -54,6 +54,9 @@ protected slots: private: void loadFile(const std::string& filename); + void closeEvent(QCloseEvent *close_event); + + void saveSettings(); }; // END of class ProfMainWindow.