diff --git a/qrenderdoc/Widgets/Extended/RDTableWidget.cpp b/qrenderdoc/Widgets/Extended/RDTableWidget.cpp new file mode 100644 index 000000000..d4e20783d --- /dev/null +++ b/qrenderdoc/Widgets/Extended/RDTableWidget.cpp @@ -0,0 +1,86 @@ +/****************************************************************************** + * 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 "RDTableWidget.h" +#include + +RDTableWidget::RDTableWidget(QWidget *parent) : QTableWidget(parent) +{ +} + +void RDTableWidget::dropEvent(QDropEvent *event) +{ + if(event->source() == this && model()->supportedDropActions() & event->dropAction()) + { + QModelIndex index; + if(viewport()->rect().contains(event->pos())) + index = indexAt(event->pos()); + + // ignore no-op drops (same source and dest row) + if(selectedIndexes().contains(index)) + return; + + QRect rect = visualRect(index); + + int halfway = rect.top() + rect.height() / 2; + + // only allow below or above dropping + int row = index.row(); + if(event->pos().y() > halfway) + row++; + + // verify we can drop past this row (bit of a hack) + { + QTableWidgetItem *src = item(qMin(row, rowCount() - 1), 0); + if(src && !(src->flags() & Qt::ItemIsDropEnabled)) + return; + } + + insertRow(row); + + int srcRow = selectedIndexes()[0].row(); + + // copy data across + for(int i = 0; i < columnCount(); i++) + { + QTableWidgetItem *src = item(srcRow, i); + if(src) + setItem(row, i, new QTableWidgetItem(*item(srcRow, i))); + else + setCellWidget(row, i, cellWidget(srcRow, i)); + } + + removeRow(srcRow); + + return; + } + + return QTableWidget::dropEvent(event); +} + +void RDTableWidget::keyPressEvent(QKeyEvent *e) +{ + QTableView::keyPressEvent(e); + emit(keyPress(e)); +} diff --git a/qrenderdoc/Widgets/Extended/RDTableWidget.h b/qrenderdoc/Widgets/Extended/RDTableWidget.h new file mode 100644 index 000000000..1002dd650 --- /dev/null +++ b/qrenderdoc/Widgets/Extended/RDTableWidget.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * 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. + ******************************************************************************/ + +#pragma once + +#include + +class RDTableWidget : public QTableWidget +{ + Q_OBJECT +public: + explicit RDTableWidget(QWidget *parent = 0); + +signals: + void keyPress(QKeyEvent *e); + +private: + // implement reordering row drag-drop behaviour + void dropEvent(QDropEvent *event) override; + void keyPressEvent(QKeyEvent *e) override; +}; diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index d5fdbdf1a..3b1161055 100644 --- a/qrenderdoc/qrenderdoc.pro +++ b/qrenderdoc/qrenderdoc.pro @@ -134,7 +134,8 @@ SOURCES += Code/qrenderdoc.cpp \ Widgets/Extended/RDTableView.cpp \ Windows/DebugMessageView.cpp \ Windows/StatisticsViewer.cpp \ - Windows/Dialogs/SettingsDialog.cpp + Windows/Dialogs/SettingsDialog.cpp \ + Widgets/Extended/RDTableWidget.cpp HEADERS += Code/CaptureContext.h \ Code/qprocessinfo.h \ @@ -173,7 +174,8 @@ HEADERS += Code/CaptureContext.h \ Widgets/Extended/RDTableView.h \ Windows/DebugMessageView.h \ Windows/StatisticsViewer.h \ - Windows/Dialogs/SettingsDialog.h + Windows/Dialogs/SettingsDialog.h \ + Widgets/Extended/RDTableWidget.h FORMS += Windows/Dialogs/AboutDialog.ui \ Windows/MainWindow.ui \ diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index 0f6b898b3..be66486fd 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -513,6 +513,7 @@ + @@ -534,6 +535,7 @@ + @@ -674,6 +676,7 @@ + diff --git a/qrenderdoc/qrenderdoc_local.vcxproj.filters b/qrenderdoc/qrenderdoc_local.vcxproj.filters index bf05f31c8..c899cb68b 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj.filters +++ b/qrenderdoc/qrenderdoc_local.vcxproj.filters @@ -484,6 +484,12 @@ Generated Files + + Widgets\Extended + + + Generated Files + @@ -861,6 +867,9 @@ Generated Files + + Widgets\Extended +