mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
Add layout loading/saving to main window
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaObject>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
#include "Windows/MainWindow.h"
|
||||
|
||||
@@ -67,6 +68,17 @@ bool CaptureContext::isRunning()
|
||||
return m_MainWindow && m_MainWindow->isVisible();
|
||||
}
|
||||
|
||||
QString CaptureContext::ConfigFile(const QString &filename)
|
||||
{
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
|
||||
QDir dir(path);
|
||||
if(!dir.exists())
|
||||
dir.mkdir(".");
|
||||
|
||||
return QDir::cleanPath(dir.absoluteFilePath(filename));
|
||||
}
|
||||
|
||||
void CaptureContext::LoadLogfile(QString logFile, bool temporary)
|
||||
{
|
||||
LoadLogfile(-1, "", logFile, temporary);
|
||||
|
||||
@@ -61,6 +61,10 @@ public:
|
||||
|
||||
bool isRunning();
|
||||
|
||||
QString ConfigFile(const QString &filename);
|
||||
|
||||
QString TempLogFilename(QString appname);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control functions
|
||||
|
||||
@@ -73,8 +77,6 @@ public:
|
||||
|
||||
void CloseLogfile();
|
||||
|
||||
QString TempLogFilename(QString appname);
|
||||
|
||||
void SetEventID(ILogViewerForm *exclude, uint32_t eventID);
|
||||
|
||||
void AddLogProgressListener(ILogLoadProgressListener *p);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include "Code/CaptureContext.h"
|
||||
#include "Windows/AboutDialog.h"
|
||||
#include "EventBrowser.h"
|
||||
@@ -35,18 +36,72 @@ MainWindow::MainWindow(CaptureContext *ctx) : QMainWindow(NULL), ui(new Ui::Main
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
EventBrowser *eventbrowser = new EventBrowser(ctx);
|
||||
QObject::connect(ui->action_Load_Default_Layout, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_1, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_2, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_3, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_4, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_5, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
QObject::connect(ui->action_Load_Layout_6, &QAction::triggered, this,
|
||||
&MainWindow::loadLayout_triggered);
|
||||
|
||||
ui->toolWindowManager->addToolWindow(eventbrowser, ToolWindowManager::EmptySpace);
|
||||
|
||||
TextureViewer *textureviewer = new TextureViewer(ctx);
|
||||
|
||||
ui->toolWindowManager->addToolWindow(
|
||||
textureviewer,
|
||||
ToolWindowManager::AreaReference(ToolWindowManager::RightOf,
|
||||
ui->toolWindowManager->areaOf(eventbrowser), 0.75f));
|
||||
QObject::connect(ui->action_Save_Default_Layout, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_1, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_2, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_3, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_4, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_5, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
QObject::connect(ui->action_Save_Layout_6, &QAction::triggered, this,
|
||||
&MainWindow::saveLayout_triggered);
|
||||
|
||||
ui->toolWindowManager->setRubberBandLineWidth(50);
|
||||
ui->toolWindowManager->setToolWindowCreateCallback([this](const QString &objectName) -> QWidget * {
|
||||
if(objectName == "textureViewer")
|
||||
{
|
||||
TextureViewer *textureViewer = new TextureViewer(m_Ctx);
|
||||
textureViewer->setObjectName("textureViewer");
|
||||
return textureViewer;
|
||||
}
|
||||
else if(objectName == "eventBrowser")
|
||||
{
|
||||
EventBrowser *eventBrowser = new EventBrowser(m_Ctx);
|
||||
eventBrowser->setObjectName("eventBrowser");
|
||||
return eventBrowser;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
});
|
||||
|
||||
bool loaded = LoadLayout(0);
|
||||
|
||||
// create default layout if layout failed to load
|
||||
if(!loaded)
|
||||
{
|
||||
EventBrowser *eventBrowser = new EventBrowser(m_Ctx);
|
||||
eventBrowser->setObjectName("eventBrowser");
|
||||
|
||||
ui->toolWindowManager->addToolWindow(eventBrowser, ToolWindowManager::EmptySpace);
|
||||
|
||||
TextureViewer *textureViewer = new TextureViewer(m_Ctx);
|
||||
textureViewer->setObjectName("textureViewer");
|
||||
|
||||
ui->toolWindowManager->addToolWindow(
|
||||
textureViewer,
|
||||
ToolWindowManager::AreaReference(ToolWindowManager::RightOf,
|
||||
ui->toolWindowManager->areaOf(eventBrowser), 0.75f));
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -54,6 +109,16 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString MainWindow::GetLayoutPath(int layout)
|
||||
{
|
||||
QString filename = "DefaultLayout.config";
|
||||
|
||||
if(layout > 0)
|
||||
filename = QString("Layout%1.config").arg(layout);
|
||||
|
||||
return m_Ctx->ConfigFile(filename);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Exit_triggered()
|
||||
{
|
||||
this->close();
|
||||
@@ -80,3 +145,175 @@ void MainWindow::on_action_About_triggered()
|
||||
AboutDialog about(this);
|
||||
RDDialog::show(&about);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Mesh_Output_triggered()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Event_Viewer_triggered()
|
||||
{
|
||||
EventBrowser *eventBrowser = new EventBrowser(m_Ctx);
|
||||
eventBrowser->setObjectName("eventBrowser");
|
||||
|
||||
ui->toolWindowManager->addToolWindow(eventBrowser, ToolWindowManager::EmptySpace);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Texture_Viewer_triggered()
|
||||
{
|
||||
TextureViewer *textureViewer = new TextureViewer(m_Ctx);
|
||||
textureViewer->setObjectName("textureViewer");
|
||||
|
||||
ui->toolWindowManager->addToolWindow(textureViewer, ToolWindowManager::EmptySpace);
|
||||
}
|
||||
|
||||
void MainWindow::saveLayout_triggered()
|
||||
{
|
||||
LoadSaveLayout(qobject_cast<QAction *>(QObject::sender()), true);
|
||||
}
|
||||
|
||||
void MainWindow::loadLayout_triggered()
|
||||
{
|
||||
LoadSaveLayout(qobject_cast<QAction *>(QObject::sender()), false);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
SaveLayout(0);
|
||||
}
|
||||
|
||||
void MainWindow::LoadSaveLayout(QAction *action, bool save)
|
||||
{
|
||||
if(action == NULL)
|
||||
{
|
||||
qWarning() << "NULL action passed to LoadSaveLayout - bad signal?";
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
||||
if(action == ui->action_Save_Default_Layout)
|
||||
{
|
||||
success = SaveLayout(0);
|
||||
}
|
||||
else if(action == ui->action_Load_Default_Layout)
|
||||
{
|
||||
success = LoadLayout(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString name = action->objectName();
|
||||
name.remove(0, name.size() - 1);
|
||||
int idx = name.toInt();
|
||||
|
||||
if(idx > 0)
|
||||
{
|
||||
if(save)
|
||||
success = SaveLayout(idx);
|
||||
else
|
||||
success = LoadLayout(idx);
|
||||
}
|
||||
}
|
||||
|
||||
if(!success)
|
||||
{
|
||||
if(save)
|
||||
RDDialog::critical(this, "Error saving layout", "Couldn't save layout");
|
||||
else
|
||||
RDDialog::critical(this, "Error loading layout", "Couldn't load layout");
|
||||
}
|
||||
}
|
||||
|
||||
QVariantMap MainWindow::saveState()
|
||||
{
|
||||
QVariantMap state = ui->toolWindowManager->saveState();
|
||||
|
||||
// marker that this is indeed a valid state to load from
|
||||
state["renderdocLayoutData"] = 1;
|
||||
|
||||
state["mainWindowGeometry"] = saveGeometry().toBase64();
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
bool MainWindow::restoreState(QVariantMap &state)
|
||||
{
|
||||
restoreGeometry(QByteArray::fromBase64(state["mainWindowGeometry"].toByteArray()));
|
||||
|
||||
ui->toolWindowManager->restoreState(state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MainWindow::SaveLayout(int layout)
|
||||
{
|
||||
QString path = GetLayoutPath(layout);
|
||||
|
||||
QVariantMap state = saveState();
|
||||
|
||||
QFile f(path);
|
||||
if(f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromVariant(state);
|
||||
|
||||
if(doc.isEmpty() || doc.isNull())
|
||||
{
|
||||
qCritical() << "Failed to convert state data to JSON document";
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray jsontext = doc.toJson(QJsonDocument::Indented);
|
||||
|
||||
qint64 ret = f.write(jsontext);
|
||||
|
||||
if(ret != jsontext.size())
|
||||
{
|
||||
qCritical() << "Failed to write JSON data to file: " << ret << " " << f.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
qWarning() << "Couldn't write to " << path << " " << f.errorString();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MainWindow::LoadLayout(int layout)
|
||||
{
|
||||
QString path = GetLayoutPath(layout);
|
||||
|
||||
QFile f(path);
|
||||
if(f.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QByteArray json = f.readAll();
|
||||
|
||||
if(json.isEmpty())
|
||||
{
|
||||
qCritical() << "Read invalid empty JSON data from file " << f.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json);
|
||||
|
||||
if(doc.isEmpty() || doc.isNull())
|
||||
{
|
||||
qCritical() << "Failed to convert file to JSON document";
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariantMap state = doc.toVariant().toMap();
|
||||
|
||||
if(state.isEmpty() || !state.contains("renderdocLayoutData"))
|
||||
{
|
||||
qCritical() << "Converted state data is invalid or unrecognised";
|
||||
return false;
|
||||
}
|
||||
|
||||
return restoreState(state);
|
||||
}
|
||||
|
||||
qInfo() << "Couldn't load layout from " << path << " " << f.errorString();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,13 +45,31 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
// automatic slots
|
||||
void on_action_Exit_triggered();
|
||||
void on_action_About_triggered();
|
||||
void on_action_Open_Log_triggered();
|
||||
void on_action_Mesh_Output_triggered();
|
||||
void on_action_Event_Viewer_triggered();
|
||||
void on_action_Texture_Viewer_triggered();
|
||||
|
||||
// manual slots
|
||||
void saveLayout_triggered();
|
||||
void loadLayout_triggered();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
CaptureContext *m_Ctx;
|
||||
|
||||
QVariantMap saveState();
|
||||
bool restoreState(QVariantMap &state);
|
||||
|
||||
QString GetLayoutPath(int layout);
|
||||
void LoadSaveLayout(QAction *action, bool save);
|
||||
bool LoadLayout(int layout);
|
||||
bool SaveLayout(int layout);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1300</width>
|
||||
<width>1200</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -80,39 +80,39 @@
|
||||
<property name="title">
|
||||
<string>&Save Layout</string>
|
||||
</property>
|
||||
<addaction name="action_Default_Layout"/>
|
||||
<addaction name="action_Save_Default_Layout"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLayout_2"/>
|
||||
<addaction name="actionLayout_3"/>
|
||||
<addaction name="actionLayout_4"/>
|
||||
<addaction name="actionLayout_5"/>
|
||||
<addaction name="actionLayout_6"/>
|
||||
<addaction name="actionLayout_7"/>
|
||||
<addaction name="action_Save_Layout_1"/>
|
||||
<addaction name="action_Save_Layout_2"/>
|
||||
<addaction name="action_Save_Layout_3"/>
|
||||
<addaction name="action_Save_Layout_4"/>
|
||||
<addaction name="action_Save_Layout_5"/>
|
||||
<addaction name="action_Save_Layout_6"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Load_Layout">
|
||||
<property name="title">
|
||||
<string>&Load Layout</string>
|
||||
</property>
|
||||
<addaction name="action_Default_Layout_2"/>
|
||||
<addaction name="action_Load_Default_Layout"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLayout_8"/>
|
||||
<addaction name="actionLayout_9"/>
|
||||
<addaction name="actionLayout_10"/>
|
||||
<addaction name="actionLayout_11"/>
|
||||
<addaction name="actionLayout_12"/>
|
||||
<addaction name="actionLayout_13"/>
|
||||
<addaction name="action_Load_Layout_1"/>
|
||||
<addaction name="action_Load_Layout_2"/>
|
||||
<addaction name="action_Load_Layout_3"/>
|
||||
<addaction name="action_Load_Layout_4"/>
|
||||
<addaction name="action_Load_Layout_5"/>
|
||||
<addaction name="action_Load_Layout_6"/>
|
||||
</widget>
|
||||
<addaction name="menu_Save_Layout"/>
|
||||
<addaction name="menu_Load_Layout"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionP_ython_Shell"/>
|
||||
<addaction name="action_Python_Shell"/>
|
||||
<addaction name="action_Event_Viewer"/>
|
||||
<addaction name="action_Texture_Viewer"/>
|
||||
<addaction name="action_Pipeline_State"/>
|
||||
<addaction name="action_API_Inspector"/>
|
||||
<addaction name="action_Mesh_Output"/>
|
||||
<addaction name="actionLog_Errors_and_Warnings"/>
|
||||
<addaction name="actionT_imeline"/>
|
||||
<addaction name="action_Errors_and_Warnings"/>
|
||||
<addaction name="action_Timeline"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
@@ -194,7 +194,7 @@
|
||||
<string>Alt+F4</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionP_ython_Shell">
|
||||
<action name="action_Python_Shell">
|
||||
<property name="text">
|
||||
<string>P&ython Shell</string>
|
||||
</property>
|
||||
@@ -224,12 +224,12 @@
|
||||
<string>&Mesh Output</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLog_Errors_and_Warnings">
|
||||
<action name="action_Errors_and_Warnings">
|
||||
<property name="text">
|
||||
<string>Log Errors and &Warnings</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionT_imeline">
|
||||
<action name="action_Timeline">
|
||||
<property name="text">
|
||||
<string>T&imeline</string>
|
||||
</property>
|
||||
@@ -239,32 +239,32 @@
|
||||
<string>Layout 1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Default_Layout">
|
||||
<action name="action_Save_Default_Layout">
|
||||
<property name="text">
|
||||
<string>&Default Layout</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Default_Layout_2">
|
||||
<action name="action_Load_Default_Layout">
|
||||
<property name="text">
|
||||
<string>&Default Layout</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_2">
|
||||
<action name="action_Save_Layout_1">
|
||||
<property name="text">
|
||||
<string>Layout &1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_3">
|
||||
<action name="action_Save_Layout_2">
|
||||
<property name="text">
|
||||
<string>Layout &2</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_4">
|
||||
<action name="action_Save_Layout_3">
|
||||
<property name="text">
|
||||
<string>Layout &3</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_5">
|
||||
<action name="action_Save_Layout_4">
|
||||
<property name="text">
|
||||
<string>Layout &4</string>
|
||||
</property>
|
||||
@@ -274,42 +274,42 @@
|
||||
<string>Layout &5</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_6">
|
||||
<action name="action_Save_Layout_5">
|
||||
<property name="text">
|
||||
<string>Layout &5</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_7">
|
||||
<action name="action_Save_Layout_6">
|
||||
<property name="text">
|
||||
<string>Layout &6</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_8">
|
||||
<action name="action_Load_Layout_1">
|
||||
<property name="text">
|
||||
<string>Layout &1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_9">
|
||||
<action name="action_Load_Layout_2">
|
||||
<property name="text">
|
||||
<string>Layout &2</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_10">
|
||||
<action name="action_Load_Layout_3">
|
||||
<property name="text">
|
||||
<string>Layout &3</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_11">
|
||||
<action name="action_Load_Layout_4">
|
||||
<property name="text">
|
||||
<string>Layout &4</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_12">
|
||||
<action name="action_Load_Layout_5">
|
||||
<property name="text">
|
||||
<string>Layout &5</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLayout_13">
|
||||
<action name="action_Load_Layout_6">
|
||||
<property name="text">
|
||||
<string>Layout &6</string>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user