mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'editor_columns_filtering' into 'master'
Toggling table columns visibility. Partially implements #890 Closes #890 See merge request OpenMW/openmw!1232
This commit is contained in:
commit
ade6cd0127
@ -71,7 +71,7 @@ opencs_units (view/world
|
||||
cellcreator pathgridcreator referenceablecreator startscriptcreator referencecreator scenesubview
|
||||
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
|
||||
dialoguespinbox recordbuttonbar tableeditidaction scripterrortable extendedcommandconfigurator
|
||||
bodypartcreator landtexturecreator landcreator
|
||||
bodypartcreator landtexturecreator landcreator tableheadermouseeventhandler
|
||||
)
|
||||
|
||||
opencs_units (view/world
|
||||
|
@ -32,7 +32,6 @@ namespace CSVWidget
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class Table;
|
||||
class TableBottomBox;
|
||||
class CreatorFactoryBase;
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "../../model/prefs/shortcut.hpp"
|
||||
|
||||
#include "tableeditidaction.hpp"
|
||||
#include "tableheadermouseeventhandler.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||
@ -422,6 +423,8 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
|
||||
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
|
||||
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
|
||||
CSMPrefs::get()["ID Tables"].update();
|
||||
|
||||
new TableHeaderMouseEventHandler(this);
|
||||
}
|
||||
|
||||
void CSVWorld::Table::setEditLock (bool locked)
|
||||
|
64
apps/opencs/view/world/tableheadermouseeventhandler.cpp
Normal file
64
apps/opencs/view/world/tableheadermouseeventhandler.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "tableheadermouseeventhandler.hpp"
|
||||
#include "dragrecordtable.hpp"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QPoint>
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
|
||||
TableHeaderMouseEventHandler::TableHeaderMouseEventHandler(DragRecordTable * parent)
|
||||
: QWidget(parent)
|
||||
, table(*parent)
|
||||
, header(*table.horizontalHeader())
|
||||
{
|
||||
header.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||
connect(
|
||||
&header, &QHeaderView::customContextMenuRequested, [=](const QPoint & position) { showContextMenu(position); });
|
||||
|
||||
header.viewport()->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool TableHeaderMouseEventHandler::eventFilter(QObject * tableWatched, QEvent * event)
|
||||
{
|
||||
if (event->type() == QEvent::Type::MouseButtonPress)
|
||||
{
|
||||
auto & clickEvent = static_cast<QMouseEvent &>(*event);
|
||||
if ((clickEvent.button() == Qt::MiddleButton))
|
||||
{
|
||||
const auto & index = table.indexAt(clickEvent.pos());
|
||||
table.setColumnHidden(index.column(), true);
|
||||
clickEvent.accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TableHeaderMouseEventHandler::showContextMenu(const QPoint & position)
|
||||
{
|
||||
auto & menu{createContextMenu()};
|
||||
menu.popup(header.viewport()->mapToGlobal(position));
|
||||
}
|
||||
|
||||
QMenu & TableHeaderMouseEventHandler::createContextMenu()
|
||||
{
|
||||
auto * menu = new QMenu(this);
|
||||
for (int i = 0; i < table.model()->columnCount(); ++i)
|
||||
{
|
||||
const auto & name = table.model()->headerData(i, Qt::Horizontal, Qt::DisplayRole);
|
||||
QAction * action{new QAction(name.toString(), this)};
|
||||
action->setCheckable(true);
|
||||
action->setChecked(!table.isColumnHidden(i));
|
||||
menu->addAction(action);
|
||||
|
||||
connect(action, &QAction::triggered, [=]() {
|
||||
table.setColumnHidden(i, !action->isChecked());
|
||||
action->setChecked(!action->isChecked());
|
||||
action->toggle();
|
||||
});
|
||||
}
|
||||
return *menu;
|
||||
}
|
||||
|
||||
} // namespace CSVWorld
|
25
apps/opencs/view/world/tableheadermouseeventhandler.hpp
Normal file
25
apps/opencs/view/world/tableheadermouseeventhandler.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QtGui>
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class DragRecordTable;
|
||||
|
||||
class TableHeaderMouseEventHandler : public QWidget
|
||||
{
|
||||
public:
|
||||
explicit TableHeaderMouseEventHandler(DragRecordTable * parent);
|
||||
|
||||
void showContextMenu(const QPoint &);
|
||||
|
||||
private:
|
||||
DragRecordTable & table;
|
||||
QHeaderView & header;
|
||||
|
||||
QMenu & createContextMenu();
|
||||
bool eventFilter(QObject *, QEvent *) override;
|
||||
|
||||
}; // class TableHeaderMouseEventHandler
|
||||
} // namespace CSVWorld
|
Loading…
x
Reference in New Issue
Block a user