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

#106 [Core][UI] Fixed reading bookmarks with empty text; Fixed overriding and restoring mouse cursor shape when hovering bookmark at the Diagram widget;

#0 [UI] Waiting until saving file is finished when closing the UI.
This commit is contained in:
Victor Zarubkin 2018-06-14 02:57:12 +03:00
parent c85d15a4e2
commit f0a588eec5
4 changed files with 43 additions and 12 deletions

View File

@ -1016,12 +1016,25 @@ extern "C" PROFILER_API profiler::block_index_t fillTreesFromStream(std::atomic<
}
usedMemorySize -= static_cast<uint16_t>(profiler::Bookmark::BaseSize) - 1;
if (usedMemorySize > 1)
if (usedMemorySize > 0)
{
stringBuffer.resize(usedMemorySize);
read(inStream, stringBuffer.data(), usedMemorySize);
inStream.read(stringBuffer.data(), usedMemorySize);
bookmark.text = stringBuffer.data();
if (stringBuffer.back() != 0)
{
stringBuffer.resize(stringBuffer.size() + 1);
stringBuffer.back() = 0;
_log << "Bad bookmark description:\n\"" << const_cast<const char*>(stringBuffer.data())
<< "\"\nWhich is not zero terminated string.\nLast symbol is: '"
<< const_cast<const char*>(stringBuffer.data() + stringBuffer.size() - 2) << "'";
return 0;
}
if (usedMemorySize != 1)
bookmark.text = stringBuffer.data();
}
else
{

View File

@ -413,15 +413,20 @@ bool BackgroundItem::mouseMove(const QPointF& scenePos)
if (prev != m_bookmark)
{
if (m_bookmark < bookmarks.size())
qApp->setOverrideCursor(QCursor(Qt::PointingHandCursor));
if (!profiler_gui::is_max(m_bookmark))
{
if (qApp->overrideCursor() == nullptr || qApp->overrideCursor()->shape() != Qt::PointingHandCursor)
qApp->setOverrideCursor(QCursor(Qt::PointingHandCursor));
}
else
{
qApp->restoreOverrideCursor();
}
emit bookmarkChanged(m_bookmark);
update();
}
if (m_bookmark < bookmarks.size())
if (!profiler_gui::is_max(m_bookmark))
{
if (!m_idleTimer.isActive())
m_idleTimer.start();
@ -455,7 +460,7 @@ bool BackgroundItem::mouseMove(const QPointF& scenePos)
bool BackgroundItem::mousePress(const QPointF& scenePos)
{
m_bButtonPressed = m_bookmark < EASY_GLOBALS.bookmarks.size() && contains(scenePos);
m_bButtonPressed = !profiler_gui::is_max(m_bookmark) && contains(scenePos);
delete m_tooltip;
m_tooltip = nullptr;
@ -470,7 +475,7 @@ bool BackgroundItem::mouseRelease(const QPointF& scenePos)
m_bButtonPressed = false;
if (m_bookmark < EASY_GLOBALS.bookmarks.size())
if (!profiler_gui::is_max(m_bookmark))
{
auto& bookmarks = EASY_GLOBALS.bookmarks;
std::sort(bookmarks.begin(), bookmarks.end(),
@ -492,7 +497,7 @@ bool BackgroundItem::mouseDoubleClick(const QPointF& scenePos)
if (!contains(scenePos))
return false;
if (m_bookmark < EASY_GLOBALS.bookmarks.size())
if (!profiler_gui::is_max(m_bookmark))
{
qApp->restoreOverrideCursor();
auto editor = new BookmarkEditor(m_bookmark, false, sceneView->parentWidget());
@ -515,7 +520,7 @@ bool BackgroundItem::mouseDoubleClick(const QPointF& scenePos)
mouseMove(scenePos);
if (m_bookmark < bookmarks.size())
if (!profiler_gui::is_max(m_bookmark))
{
qApp->restoreOverrideCursor();
auto editor = new BookmarkEditor(m_bookmark, true, sceneView->parentWidget());
@ -534,7 +539,7 @@ void BackgroundItem::mouseLeave()
if (m_idleTimer.isActive())
m_idleTimer.stop();
if (m_bookmark < EASY_GLOBALS.bookmarks.size())
if (!profiler_gui::is_max(m_bookmark))
{
profiler_gui::set_max(m_bookmark);
qApp->restoreOverrideCursor();

View File

@ -1509,7 +1509,7 @@ void MainWindow::showEvent(QShowEvent* show_event)
void MainWindow::closeEvent(QCloseEvent* close_event)
{
if (m_bNetworkFileRegime || EASY_GLOBALS.has_local_changes)
if (!m_bCloseAfterSave && (m_bNetworkFileRegime || EASY_GLOBALS.has_local_changes))
{
// Warn user about unsaved network information and suggest to save
const auto result = Dialog::question(this, "Unsaved session"
@ -1518,6 +1518,13 @@ void MainWindow::closeEvent(QCloseEvent* close_event)
if (result == QMessageBox::Yes)
{
onSaveFileClicked(true);
if (m_reader.isSaving() && m_progress != nullptr)
{
// Wait until finish and close
m_bCloseAfterSave = true;
close_event->ignore();
return;
}
}
else if (result == QMessageBox::Cancel)
{
@ -2156,6 +2163,11 @@ void MainWindow::onFileReaderTimeout()
{
onSavingFinish();
closeProgressDialogAndClearReader();
if (m_bCloseAfterSave)
{
setEnabled(false);
QTimer::singleShot(1500, this, &This::close);
}
}
else
{

View File

@ -302,6 +302,7 @@ protected:
uint16_t m_lastPort = 0;
bool m_bNetworkFileRegime = false;
bool m_bOpenedCacheFile = false;
bool m_bCloseAfterSave = false;
public: