allow clicking on results row to show dir

This commit is contained in:
Stephen Birarda 2017-04-17 13:29:44 -07:00
parent cdd9990fe8
commit cbd6f6417c
4 changed files with 54 additions and 5 deletions

View file

@ -226,7 +226,7 @@ void DomainBakeWidget::bakeButtonClicked() {
// add a pending row to the results window to show that this bake is in process
auto resultsWindow = qApp->getMainWindow()->showResultsWindow();
auto resultsRowName = _domainNameLineEdit->text().isEmpty() ? fileToBakeURL.fileName() : _domainNameLineEdit->text();
auto resultsRow = resultsWindow->addPendingResultRow(resultsRowName);
auto resultsRow = resultsWindow->addPendingResultRow(resultsRowName, outputDirectory);
// keep the unique ptr to the domain baker and the index to the row representing it in the results table
_bakers.emplace_back(std::move(domainBaker), resultsRow);

View file

@ -205,7 +205,7 @@ void ModelBakeWidget::bakeButtonClicked() {
// add a pending row to the results window to show that this bake is in process
auto resultsWindow = qApp->getMainWindow()->showResultsWindow();
auto resultsRow = resultsWindow->addPendingResultRow(modelToBakeURL.fileName());
auto resultsRow = resultsWindow->addPendingResultRow(modelToBakeURL.fileName(), outputDirectory);
// keep a unique_ptr to this baker
// and remember the row that represents it in the results table

View file

@ -9,7 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtCore/QDebug>
#include <QtCore/QProcess>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QVBoxLayout>
@ -50,12 +50,53 @@ void ResultsWindow::setupUI() {
_resultsTable->horizontalHeader()->resizeSection(0, 0.25 * FIXED_WINDOW_WIDTH);
_resultsTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
// make sure we hear about cell clicks so that we can show the output directory for the given row
connect(_resultsTable, &QTableWidget::cellClicked, this, &ResultsWindow::handleCellClicked);
// set the layout of this widget to the created layout
setLayout(resultsLayout);
}
void revealDirectory(const QDir& dirToReveal) {
int ResultsWindow::addPendingResultRow(const QString& fileName) {
// See http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
// for details
// Mac, Windows support folder or file.
#if defined(Q_OS_WIN)
const QString explorer = Environment::systemEnvironment().searchInPath(QLatin1String("explorer.exe"));
if (explorer.isEmpty()) {
QMessageBox::warning(parent,
tr("Launching Windows Explorer failed"),
tr("Could not find explorer.exe in path to launch Windows Explorer."));
return;
}
QString param = QLatin1String("/select,") + QDir::toNativeSeparators(dirToReveal.absolutePath());
QString command = explorer + " " + param;
QProcess::startDetached(command);
#elif defined(Q_OS_MAC)
QStringList scriptArgs;
scriptArgs << QLatin1String("-e")
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(dirToReveal.absolutePath());
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
scriptArgs.clear();
scriptArgs << QLatin1String("-e") << QLatin1String("tell application \"Finder\" to activate");
QProcess::execute("/usr/bin/osascript", scriptArgs);
#endif
}
void ResultsWindow::handleCellClicked(int rowIndex, int columnIndex) {
// use revealDirectory to show the output directory for this row
revealDirectory(_outputDirectories[rowIndex]);
}
int ResultsWindow::addPendingResultRow(const QString& fileName, const QDir& outputDirectory) {
int rowIndex = _resultsTable->rowCount();
_resultsTable->insertRow(rowIndex);
@ -69,6 +110,9 @@ int ResultsWindow::addPendingResultRow(const QString& fileName) {
statusItem->setFlags(statusItem->flags() & ~Qt::ItemIsEditable);
_resultsTable->setItem(rowIndex, 1, statusItem);
// push an output directory to our list so we can show it if the user clicks on this bake in the results table
_outputDirectories.push_back(outputDirectory);
return rowIndex;
}

View file

@ -12,6 +12,7 @@
#ifndef hifi_ResultsWindow_h
#define hifi_ResultsWindow_h
#include <QtCore/QDir>
#include <QtWidgets/QWidget>
class QTableWidget;
@ -24,11 +25,15 @@ public:
void setupUI();
int addPendingResultRow(const QString& fileName);
int addPendingResultRow(const QString& fileName, const QDir& outputDirectory);
void changeStatusForRow(int rowIndex, const QString& result);
private slots:
void handleCellClicked(int rowIndex, int columnIndex);
private:
QTableWidget* _resultsTable { nullptr };
QList<QDir> _outputDirectories;
};
#endif // hifi_ResultsWindow_h