Add ordered list editor for configuring shader search paths in settings

This commit is contained in:
baldurk
2017-02-06 17:14:44 +00:00
parent 95d84f2da7
commit fb1dfbd184
8 changed files with 411 additions and 4 deletions
@@ -0,0 +1,203 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "OrderedListEditor.h"
#include <QKeyEvent>
#include <QToolButton>
#include "Code/QRDUtils.h"
#include "ui_OrderedListEditor.h"
OrderedListEditor::OrderedListEditor(const QString &windowName, const QString &itemName,
BrowseMode browse, QWidget *parent)
: QDialog(parent), ui(new Ui::OrderedListEditor)
{
ui->setupUi(this);
m_BrowseMode = browse;
setWindowTitle(windowName);
if(m_BrowseMode == BrowseMode::None)
{
ui->list->setColumnCount(1);
ui->list->setHorizontalHeaderLabels({itemName});
ui->list->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
else
{
QStringList labels;
labels << itemName << tr("Browse");
ui->list->setColumnCount(2);
ui->list->setHorizontalHeaderLabels(labels);
ui->list->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->list->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
}
QObject::connect(ui->list, &RDTableWidget::keyPress, this, &OrderedListEditor::list_keyPress);
}
OrderedListEditor::~OrderedListEditor()
{
delete ui;
}
QToolButton *OrderedListEditor::makeBrowseButton()
{
QToolButton *ret = new QToolButton(this);
ret->setIcon(QIcon(QPixmap(QString::fromUtf8(":/Resources/folder_page.png"))));
ret->setAutoRaise(true);
QObject::connect(ret, &QToolButton::clicked, this, &OrderedListEditor::browse_clicked);
return ret;
}
void OrderedListEditor::setItems(const QStringList &strings)
{
ui->list->setUpdatesEnabled(false);
ui->list->clearContents();
ui->list->setRowCount(strings.count());
for(int i = 0; i < strings.count(); i++)
{
ui->list->setItem(i, 0, new QTableWidgetItem(strings[i]));
if(m_BrowseMode != BrowseMode::None)
ui->list->setCellWidget(i, 1, makeBrowseButton());
}
// if we added any strings above the new item row was automatically
// appended. If not, add it explicitly here
if(strings.count() == 0)
addNewItemRow();
ui->list->resizeColumnToContents(0);
if(m_BrowseMode != BrowseMode::None)
ui->list->resizeColumnToContents(1);
ui->list->setUpdatesEnabled(true);
}
void OrderedListEditor::addNewItemRow()
{
ui->list->insertRow(ui->list->rowCount());
QTableWidgetItem *item = new QTableWidgetItem("");
item->setFlags(item->flags() & ~(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled));
ui->list->setItem(ui->list->rowCount() - 1, 0, item);
if(m_BrowseMode != BrowseMode::None)
{
item = new QTableWidgetItem("");
item->setFlags(item->flags() & ~(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled));
ui->list->setItem(ui->list->rowCount() - 1, 1, item);
ui->list->setCellWidget(ui->list->rowCount() - 1, 1, makeBrowseButton());
}
}
QStringList OrderedListEditor::getItems()
{
QStringList ret;
// don't include the last 'new item' entry
for(int i = 0; i < ui->list->rowCount() - 1; i++)
ret << ui->list->item(i, 0)->text();
return ret;
}
void OrderedListEditor::on_list_cellChanged(int row, int column)
{
// hack :(. Assume this will only be hit on single UI thread.
static bool recurse = false;
if(recurse)
return;
recurse = true;
// if the last row has something added to it, make a new final row
if(row == ui->list->rowCount() - 1)
{
if(!ui->list->item(row, column)->data(Qt::DisplayRole).toString().trimmed().isEmpty())
{
// enable dragging
ui->list->item(row, 0)->setFlags(ui->list->item(row, 0)->flags() |
(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled));
if(m_BrowseMode != BrowseMode::None)
delete ui->list->takeItem(row, 1);
addNewItemRow();
}
}
if(row > 0 && column == 0 &&
ui->list->item(row, column)->data(Qt::DisplayRole).toString().trimmed().isEmpty())
{
ui->list->removeRow(row);
}
recurse = false;
}
void OrderedListEditor::browse_clicked()
{
QWidget *tool = qobject_cast<QWidget *>(QObject::sender());
if(tool)
{
for(int i = 0; i < ui->list->rowCount(); i++)
{
QWidget *rowButton = ui->list->cellWidget(i, 1);
if(rowButton == tool)
{
QString sel;
if(m_BrowseMode == BrowseMode::Folder)
sel = RDDialog::getExistingDirectory(this, tr("Browse for a folder"));
else
sel = RDDialog::getOpenFileName(this, tr("Browse for a file"));
if(sel != "")
ui->list->item(i, 0)->setText(sel);
}
}
}
}
void OrderedListEditor::list_keyPress(QKeyEvent *event)
{
if(event->key() == Qt::Key_Delete)
{
int row = -1;
if(ui->list->selectionModel()->selectedIndexes().count() > 0)
row = ui->list->selectionModel()->selectedIndexes()[0].row();
if(row >= 0)
ui->list->removeRow(row);
}
}
@@ -0,0 +1,69 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include <QDialog>
namespace Ui
{
class OrderedListEditor;
}
class QTreeWidgetItem;
class QToolButton;
enum class BrowseMode
{
None,
Folder,
File,
};
class OrderedListEditor : public QDialog
{
Q_OBJECT
public:
explicit OrderedListEditor(const QString &windowName, const QString &itemName, BrowseMode browse,
QWidget *parent = 0);
~OrderedListEditor();
void setItems(const QStringList &strings);
QStringList getItems();
private slots:
// automatic slots
void on_list_cellChanged(int row, int column);
// manual slots
void browse_clicked();
void list_keyPress(QKeyEvent *event);
private:
Ui::OrderedListEditor *ui;
BrowseMode m_BrowseMode;
void addNewItemRow();
QToolButton *makeBrowseButton();
};
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OrderedListEditor</class>
<widget class="QDialog" name="OrderedListEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="RDTableWidget" name="list">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>50</number>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>RDTableWidget</class>
<extends>QTableWidget</extends>
<header>Widgets/Extended/RDTableWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OrderedListEditor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OrderedListEditor</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+12 -2
View File
@@ -26,6 +26,7 @@
#include "Code/CaptureContext.h"
#include "Code/PersistantConfig.h"
#include "Code/QRDUtils.h"
#include "Windows/Dialogs/OrderedListEditor.h"
#include "CaptureDialog.h"
#include "ui_SettingsDialog.h"
@@ -203,7 +204,16 @@ void SettingsDialog::on_AlwaysReplayLocally_toggled(bool checked)
// core
void SettingsDialog::on_chooseSearchPaths_clicked()
{
// TODO ordered list editor
OrderedListEditor listEd(tr("Shader debug info search paths"), tr("Search Path"),
BrowseMode::Folder, this);
listEd.setItems(m_Ctx->Config.GetConfigSetting("shader.debug.searchPaths")
.split(QChar(';'), QString::SkipEmptyParts));
int res = RDDialog::show(&listEd);
if(res)
m_Ctx->Config.SetConfigSetting("shader.debug.searchPaths", listEd.getItems().join(QChar(';')));
}
// texture viewer
@@ -320,7 +330,7 @@ void SettingsDialog::on_browseAdbPath_clicked()
m_Ctx->Config.Serialize();
}
void SettingsDialog::on_MaxConnectTimeout_valueChanged(double timeout)
void SettingsDialog::on_Android_MaxConnectTimeout_valueChanged(double timeout)
{
m_Ctx->Config.Android_MaxConnectTimeout = ui->Android_MaxConnectTimeout->value();
+1 -1
View File
@@ -84,7 +84,7 @@ private slots:
// android
void on_browseTempCaptureDirectory_clicked();
void on_browseAdbPath_clicked();
void on_MaxConnectTimeout_valueChanged(double timeout);
void on_Android_MaxConnectTimeout_valueChanged(double timeout);
void on_Android_AdbExecutablePath_textEdited(const QString &path);
// manual slots
+4 -1
View File
@@ -135,6 +135,7 @@ SOURCES += Code/qrenderdoc.cpp \
Windows/DebugMessageView.cpp \
Windows/StatisticsViewer.cpp \
Windows/Dialogs/SettingsDialog.cpp \
Windows/Dialogs/OrderedListEditor.cpp \
Widgets/Extended/RDTableWidget.cpp
HEADERS += Code/CaptureContext.h \
@@ -175,6 +176,7 @@ HEADERS += Code/CaptureContext.h \
Windows/DebugMessageView.h \
Windows/StatisticsViewer.h \
Windows/Dialogs/SettingsDialog.h \
Windows/Dialogs/OrderedListEditor.h \
Widgets/Extended/RDTableWidget.h
FORMS += Windows/Dialogs/AboutDialog.ui \
@@ -198,7 +200,8 @@ FORMS += Windows/Dialogs/AboutDialog.ui \
Windows/ShaderViewer.ui \
Windows/DebugMessageView.ui \
Windows/StatisticsViewer.ui \
Windows/Dialogs/SettingsDialog.ui
Windows/Dialogs/SettingsDialog.ui \
Windows/Dialogs/OrderedListEditor.ui
RESOURCES += resources.qrc
+5
View File
@@ -503,6 +503,7 @@
<ClCompile Include="generated\moc_EventBrowser.cpp" />
<ClCompile Include="generated\moc_GLPipelineStateViewer.cpp" />
<ClCompile Include="generated\moc_LiveCapture.cpp" />
<ClCompile Include="generated\moc_OrderedListEditor.cpp" />
<ClCompile Include="generated\moc_PipelineStateViewer.cpp" />
<ClCompile Include="generated\moc_QRDUtils.cpp" />
<ClCompile Include="generated\moc_RangeHistogram.cpp" />
@@ -553,6 +554,7 @@
<ClCompile Include="Windows\Dialogs\AboutDialog.cpp" />
<ClCompile Include="Windows\Dialogs\CaptureDialog.cpp" />
<ClCompile Include="Windows\Dialogs\LiveCapture.cpp" />
<ClCompile Include="Windows\Dialogs\OrderedListEditor.cpp" />
<ClCompile Include="Windows\Dialogs\SettingsDialog.cpp" />
<ClCompile Include="Windows\Dialogs\TextureSaveDialog.cpp" />
<ClCompile Include="Windows\EventBrowser.cpp" />
@@ -663,6 +665,7 @@
<ClInclude Include="generated\ui_GLPipelineStateViewer.h" />
<ClInclude Include="generated\ui_LiveCapture.h" />
<ClInclude Include="generated\ui_MainWindow.h" />
<ClInclude Include="generated\ui_OrderedListEditor.h" />
<ClInclude Include="generated\ui_PipelineStateViewer.h" />
<ClInclude Include="generated\ui_ResourcePreview.h" />
<ClInclude Include="generated\ui_SettingsDialog.h" />
@@ -694,6 +697,7 @@
<ClInclude Include="Windows\Dialogs\AboutDialog.h" />
<ClInclude Include="Windows\Dialogs\CaptureDialog.h" />
<ClInclude Include="Windows\Dialogs\LiveCapture.h" />
<ClInclude Include="Windows\Dialogs\OrderedListEditor.h" />
<ClInclude Include="Windows\Dialogs\SettingsDialog.h" />
<ClInclude Include="Windows\Dialogs\TextureSaveDialog.h" />
<ClInclude Include="Windows\EventBrowser.h" />
@@ -724,6 +728,7 @@
<None Include="Windows\Dialogs\AboutDialog.ui" />
<None Include="Windows\Dialogs\CaptureDialog.ui" />
<None Include="Windows\Dialogs\LiveCapture.ui" />
<None Include="Windows\Dialogs\OrderedListEditor.ui" />
<None Include="Windows\Dialogs\SettingsDialog.ui" />
<None Include="Windows\Dialogs\TextureSaveDialog.ui" />
<None Include="Windows\EventBrowser.ui" />
@@ -484,6 +484,12 @@
<ClCompile Include="generated\moc_SettingsDialog.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Windows\Dialogs\OrderedListEditor.cpp">
<Filter>Windows\Dialogs</Filter>
</ClCompile>
<ClCompile Include="generated\moc_OrderedListEditor.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Widgets\Extended\RDTableWidget.cpp">
<Filter>Widgets\Extended</Filter>
</ClCompile>
@@ -867,6 +873,12 @@
<ClInclude Include="generated\ui_SettingsDialog.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="Windows\Dialogs\OrderedListEditor.h">
<Filter>Windows\Dialogs</Filter>
</ClInclude>
<ClInclude Include="generated\ui_OrderedListEditor.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="Widgets\Extended\RDTableWidget.h">
<Filter>Widgets\Extended</Filter>
</ClInclude>
@@ -1111,6 +1123,9 @@
<None Include="Windows\Dialogs\SettingsDialog.ui">
<Filter>Windows\Dialogs</Filter>
</None>
<None Include="Windows\Dialogs\OrderedListEditor.ui">
<Filter>Windows\Dialogs</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="generated\ui_AboutDialog.h">