ui: Indexing UI
* Added DialogView with QtDialogView implementation to handle information dialogs * Implemented QtIndexingDialog class that covers all different dialogs for indexing * Directly communicate with DialogView from Prpject and all Tasks involved in indexing * Block QtMainWindow UI while indexing
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
#include "qt/view/QtDialogView.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "qt/window/QtIndexingDialog.h"
|
||||
#include "qt/window/QtMainWindow.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
QtDialogView::QtDialogView(QtMainWindow* mainWindow)
|
||||
: m_mainWindow(mainWindow)
|
||||
, m_windowStack(this)
|
||||
{
|
||||
}
|
||||
|
||||
QtDialogView::~QtDialogView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtDialogView::showProgressDialog(const std::string& title, const std::string& message)
|
||||
{
|
||||
MessageStatus(title + ": " + message, false, true).dispatch();
|
||||
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtIndexingDialog* window = dynamic_cast<QtIndexingDialog*>(m_windowStack.getTopWindow());
|
||||
if (!window || window->getType() != QtIndexingDialog::DIALOG_PROGRESS)
|
||||
{
|
||||
m_windowStack.clearWindows();
|
||||
|
||||
window = createWindow<QtIndexingDialog>();
|
||||
window->setupProgress();
|
||||
}
|
||||
|
||||
window->updateTitle(title.c_str());
|
||||
window->updateMessage(message.c_str());
|
||||
|
||||
setUIBlocked(true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtDialogView::hideProgressDialog()
|
||||
{
|
||||
MessageStatus("", false, false).dispatch();
|
||||
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtIndexingDialog* window = dynamic_cast<QtIndexingDialog*>(m_windowStack.getTopWindow());
|
||||
if (window && window->getType() == QtIndexingDialog::DIALOG_PROGRESS)
|
||||
{
|
||||
m_windowStack.popWindow();
|
||||
}
|
||||
|
||||
setUIBlocked(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool QtDialogView::startIndexingDialog(size_t cleanFileCount, size_t indexFileCount)
|
||||
{
|
||||
bool result = false;
|
||||
bool done = false;
|
||||
|
||||
m_onQtThread(
|
||||
[=, &result, &done]()
|
||||
{
|
||||
QtIndexingDialog* window = createWindow<QtIndexingDialog>();
|
||||
window->setupStart(cleanFileCount, indexFileCount,
|
||||
[&](bool start)
|
||||
{
|
||||
result = start;
|
||||
done = true;
|
||||
|
||||
setUIBlocked(false);
|
||||
}
|
||||
);
|
||||
|
||||
setUIBlocked(true);
|
||||
}
|
||||
);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void QtDialogView::updateIndexingDialog(size_t fileCount, size_t totalFileCount, std::string sourcePath)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Indexing files: [";
|
||||
ss << fileCount << "/";
|
||||
ss << totalFileCount << "] ";
|
||||
ss << sourcePath;
|
||||
MessageStatus(ss.str(), false, true).dispatch();
|
||||
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtIndexingDialog* window = dynamic_cast<QtIndexingDialog*>(m_windowStack.getTopWindow());
|
||||
if (!window)
|
||||
{
|
||||
m_windowStack.clearWindows();
|
||||
|
||||
window = createWindow<QtIndexingDialog>();
|
||||
window->setupIndexing();
|
||||
}
|
||||
|
||||
if (window && window->getType() == QtIndexingDialog::DIALOG_INDEXING)
|
||||
{
|
||||
window->updateIndexingProgress(fileCount, totalFileCount, sourcePath);
|
||||
setUIBlocked(true);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtDialogView::finishedIndexingDialog(size_t fileCount, size_t totalFileCount, float time, ErrorCountInfo errorInfo)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Finished indexing: ";
|
||||
ss << fileCount << "/" << totalFileCount << " files; ";
|
||||
ss << utility::timeToString(time);
|
||||
ss << "; " << errorInfo.total << " error" << (errorInfo.total != 1 ? "s" : "");
|
||||
if (errorInfo.fatal > 0)
|
||||
{
|
||||
ss << " (" << errorInfo.fatal << " fatal)";
|
||||
}
|
||||
MessageStatus(ss.str(), false, false).dispatch();
|
||||
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_windowStack.clearWindows();
|
||||
|
||||
QtIndexingDialog* window = createWindow<QtIndexingDialog>();
|
||||
window->setupReport(fileCount, totalFileCount, time);
|
||||
window->updateErrorCount(errorInfo.total, errorInfo.fatal);
|
||||
|
||||
setUIBlocked(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
int QtDialogView::confirm(const std::string& message, const std::vector<std::string>& options)
|
||||
{
|
||||
int result = -1;
|
||||
bool done = false;
|
||||
|
||||
m_onQtThread(
|
||||
[=, &result, &done]()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(message.c_str());
|
||||
|
||||
for (const std::string& option : options)
|
||||
{
|
||||
msgBox.addButton(option.c_str(), QMessageBox::AcceptRole);
|
||||
}
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
for (int i = 0; i < msgBox.buttons().size(); i++)
|
||||
{
|
||||
if (msgBox.clickedButton() == msgBox.buttons().at(i))
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done = true;
|
||||
}
|
||||
);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void QtDialogView::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_onQtThread2(
|
||||
[=]()
|
||||
{
|
||||
QtIndexingDialog* window = dynamic_cast<QtIndexingDialog*>(m_windowStack.getTopWindow());
|
||||
if (window && window->getType() == QtIndexingDialog::DIALOG_INDEXING)
|
||||
{
|
||||
showProgressDialog("Interrupting Indexing", "Waiting for indexer threads to finish");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtDialogView::handleMessage(MessageShowErrors* message)
|
||||
{
|
||||
ErrorCountInfo errorInfo = message->errorCount;
|
||||
|
||||
m_onQtThread2(
|
||||
[=]()
|
||||
{
|
||||
updateErrorCount(errorInfo.total, errorInfo.fatal);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtDialogView::updateErrorCount(size_t errorCount, size_t fatalCount)
|
||||
{
|
||||
QtIndexingDialog* window = dynamic_cast<QtIndexingDialog*>(m_windowStack.getTopWindow());
|
||||
if (window)
|
||||
{
|
||||
window->updateErrorCount(errorCount, fatalCount);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* QtDialogView::createWindow()
|
||||
{
|
||||
T* window = new T(m_mainWindow);
|
||||
|
||||
connect(window, SIGNAL(canceled()), &m_windowStack, SLOT(popWindow()));
|
||||
connect(window, SIGNAL(finished()), &m_windowStack, SLOT(clearWindows()));
|
||||
|
||||
m_windowStack.pushWindow(window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void QtDialogView::setUIBlocked(bool blocked)
|
||||
{
|
||||
m_mainWindow->setEnabled(!blocked);
|
||||
|
||||
if (blocked)
|
||||
{
|
||||
QWidget* window = m_windowStack.getTopWindow();
|
||||
if (window)
|
||||
{
|
||||
window->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef QT_DIALOG_VIEW_H
|
||||
#define QT_DIALOG_VIEW_H
|
||||
|
||||
#include "component/view/DialogView.h"
|
||||
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
#include "qt/window/QtWindowStack.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageInterruptTasks.h"
|
||||
#include "utility/messaging/type/MessageShowErrors.h"
|
||||
|
||||
class QtMainWindow;
|
||||
|
||||
class QtDialogView
|
||||
: public QObject
|
||||
, public DialogView
|
||||
, public MessageListener<MessageInterruptTasks>
|
||||
, public MessageListener<MessageShowErrors>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtDialogView(QtMainWindow* mainWindow);
|
||||
virtual ~QtDialogView();
|
||||
|
||||
void showProgressDialog(const std::string& title, const std::string& message) override;
|
||||
void hideProgressDialog() override;
|
||||
|
||||
bool startIndexingDialog(size_t cleanFileCount, size_t indexFileCount) override;
|
||||
void updateIndexingDialog(size_t fileCount, size_t totalFileCount, std::string sourcePath) override;
|
||||
void finishedIndexingDialog(size_t fileCount, size_t totalFileCount, float time, ErrorCountInfo errorInfo) override;
|
||||
|
||||
int confirm(const std::string& message, const std::vector<std::string>& options) override;
|
||||
|
||||
private:
|
||||
void handleMessage(MessageInterruptTasks* message) override;
|
||||
void handleMessage(MessageShowErrors* message) override;
|
||||
|
||||
void updateErrorCount(size_t errorCount, size_t fatalCount);
|
||||
|
||||
template<typename T>
|
||||
T* createWindow();
|
||||
|
||||
void setUIBlocked(bool blocked);
|
||||
|
||||
QtMainWindow* m_mainWindow;
|
||||
|
||||
QtWindowStack m_windowStack;
|
||||
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
QtThreadedLambdaFunctor m_onQtThread2;
|
||||
};
|
||||
|
||||
#endif // QT_DIALOG_VIEW_H
|
||||
@@ -1,12 +1,5 @@
|
||||
#include "qt/view/QtMainView.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "qt/window/QtMainWindow.h"
|
||||
|
||||
QtMainView::QtMainView()
|
||||
@@ -18,7 +11,6 @@ QtMainView::QtMainView()
|
||||
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
|
||||
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
|
||||
, m_forceLicenseScreenFunctor(std::bind(&QtMainView::doForceLicenseScreen, this, std::placeholders::_1))
|
||||
, m_confirmFunctor(std::bind(&QtMainView::doConfirm, this, std::placeholders::_1, std::placeholders::_2))
|
||||
{
|
||||
m_window = std::make_shared<QtMainWindow>();
|
||||
m_window->show();
|
||||
@@ -28,6 +20,11 @@ QtMainView::~QtMainView()
|
||||
{
|
||||
}
|
||||
|
||||
QtMainWindow* QtMainView::getMainWindow() const
|
||||
{
|
||||
return m_window.get();
|
||||
}
|
||||
|
||||
void QtMainView::addView(View* view)
|
||||
{
|
||||
m_views.push_back(view);
|
||||
@@ -96,30 +93,6 @@ void QtMainView::updateRecentProjectMenu()
|
||||
m_updateRecentProjectMenuFunctor();
|
||||
}
|
||||
|
||||
int QtMainView::confirm(const std::string& message, const std::vector<std::string>& options)
|
||||
{
|
||||
m_confirmDone = false;
|
||||
|
||||
m_confirmFunctor(message, options);
|
||||
|
||||
while (true)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_confirmMutex);
|
||||
|
||||
if (m_confirmDone)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
return m_confirmResult;
|
||||
}
|
||||
|
||||
void QtMainView::handleMessage(MessageForceEnterLicense* message)
|
||||
{
|
||||
m_forceLicenseScreenFunctor(message->licenseExpired);
|
||||
@@ -185,30 +158,3 @@ void QtMainView::doForceLicenseScreen(bool expired)
|
||||
{
|
||||
m_window->forceEnterLicense(expired);
|
||||
}
|
||||
|
||||
void QtMainView::doConfirm(const std::string& message, const std::vector<std::string>& options)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(message.c_str());
|
||||
|
||||
for (const std::string& option : options)
|
||||
{
|
||||
msgBox.addButton(option.c_str(), QMessageBox::AcceptRole);
|
||||
}
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
m_confirmResult = -1;
|
||||
|
||||
for (int i = 0; i < msgBox.buttons().size(); i++)
|
||||
{
|
||||
if (msgBox.clickedButton() == msgBox.buttons().at(i))
|
||||
{
|
||||
m_confirmResult = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_confirmMutex);
|
||||
m_confirmDone = true;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
QtMainView();
|
||||
virtual ~QtMainView();
|
||||
|
||||
QtMainWindow* getMainWindow() const;
|
||||
|
||||
// ViewLayout implementation
|
||||
virtual void addView(View* view);
|
||||
virtual void removeView(View* view);
|
||||
@@ -48,8 +50,6 @@ public:
|
||||
virtual void activateWindow();
|
||||
virtual void updateRecentProjectMenu();
|
||||
|
||||
virtual int confirm(const std::string& message, const std::vector<std::string>& options);
|
||||
|
||||
private:
|
||||
void handleMessage(MessageForceEnterLicense* message);
|
||||
void handleMessage(MessageProjectEdit* message);
|
||||
@@ -65,8 +65,6 @@ private:
|
||||
void doUpdateRecentProjectMenu();
|
||||
void doForceLicenseScreen(bool expired);
|
||||
|
||||
void doConfirm(const std::string& message, const std::vector<std::string>& options);
|
||||
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
|
||||
@@ -78,11 +76,6 @@ private:
|
||||
QtThreadedFunctor<> m_activateWindowFunctor;
|
||||
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
|
||||
QtThreadedFunctor<bool> m_forceLicenseScreenFunctor;
|
||||
|
||||
QtThreadedFunctor<const std::string&, const std::vector<std::string>&> m_confirmFunctor;
|
||||
std::mutex m_confirmMutex;
|
||||
bool m_confirmDone;
|
||||
int m_confirmResult;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_VIEW_H
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "qt/view/QtCodeView.h"
|
||||
#include "qt/view/QtCompositeView.h"
|
||||
#include "qt/view/QtDialogView.h"
|
||||
#include "qt/view/QtGraphView.h"
|
||||
#include "qt/view/QtGraphViewStyleImpl.h"
|
||||
#include "qt/view/QtMainView.h"
|
||||
@@ -63,3 +64,8 @@ std::shared_ptr<UndoRedoView> QtViewFactory::createUndoRedoView(ViewLayout* view
|
||||
{
|
||||
return View::createInitAndAddToLayout<QtUndoRedoView>(viewLayout);
|
||||
}
|
||||
|
||||
std::shared_ptr<DialogView> QtViewFactory::createDialogView(ViewLayout* viewLayout) const
|
||||
{
|
||||
return std::make_shared<QtDialogView>(dynamic_cast<QtMainView*>(viewLayout)->getMainWindow());
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<StatusBarView> createStatusBarView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<UndoRedoView> createUndoRedoView(ViewLayout* viewLayout) const;
|
||||
|
||||
virtual std::shared_ptr<DialogView> createDialogView(ViewLayout* viewLayout) const;
|
||||
};
|
||||
|
||||
#endif // QT_VIEW_FACTORY_H
|
||||
|
||||
Reference in New Issue
Block a user