Set up map list tool bar to record setting states
This commit is contained in:
parent
ab8eb7c7e4
commit
f90dae0da0
4 changed files with 56 additions and 35 deletions
|
@ -9,7 +9,7 @@ class FilterChildrenProxyModel : public QSortFilterProxyModel
|
|||
|
||||
public:
|
||||
explicit FilterChildrenProxyModel(QObject *parent = nullptr);
|
||||
bool toggleHideEmpty() { return this->hideEmpty = !this->hideEmpty; }
|
||||
void setHideEmpty(bool hidden) { this->hideEmpty = hidden; }
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
|
||||
private:
|
||||
|
|
|
@ -22,12 +22,15 @@ public:
|
|||
MapTree* list() const { return m_list; }
|
||||
void setList(MapTree *list);
|
||||
|
||||
void setEditsAllowedButtonHidden(bool hidden);
|
||||
void setEditsAllowedButtonVisible(bool visible);
|
||||
void setEditsAllowed(bool allowed);
|
||||
void toggleEditsAllowed();
|
||||
|
||||
void setEmptyFoldersVisible(bool visible);
|
||||
void toggleEmptyFolders();
|
||||
|
||||
void expandList();
|
||||
void collapseList();
|
||||
void toggleEditsAllowed();
|
||||
|
||||
void applyFilter(const QString &filterText);
|
||||
void clearFilter();
|
||||
|
@ -42,8 +45,8 @@ private:
|
|||
Ui::MapListToolBar *ui;
|
||||
QPointer<MapTree> m_list;
|
||||
bool m_filterLocked = false;
|
||||
|
||||
void setEditsAllowed(bool allowed);
|
||||
bool m_editsAllowed = false;
|
||||
bool m_emptyFoldersVisible = true;
|
||||
};
|
||||
|
||||
#endif // MAPLISTTOOLBAR_H
|
||||
|
|
|
@ -414,8 +414,8 @@ void MainWindow::initMapList() {
|
|||
connect(ui->layoutList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu);
|
||||
|
||||
// Only the groups list allows reorganizing folder contents, editing folder names, etc.
|
||||
ui->mapListToolBar_Areas->setEditsAllowedButtonHidden(true);
|
||||
ui->mapListToolBar_Layouts->setEditsAllowedButtonHidden(true);
|
||||
ui->mapListToolBar_Areas->setEditsAllowedButtonVisible(false);
|
||||
ui->mapListToolBar_Layouts->setEditsAllowedButtonVisible(false);
|
||||
|
||||
// When map list search filter is cleared we want the current map/layout in the editor to be visible in the list.
|
||||
connect(ui->mapListToolBar_Groups, &MapListToolBar::filterCleared, this, &MainWindow::scrollMapListToCurrentMap);
|
||||
|
|
|
@ -4,18 +4,32 @@
|
|||
|
||||
#include <QToolTip>
|
||||
|
||||
/*
|
||||
TODO: The button states for each tool bar (just the two toggleable buttons, hide empty folders and allow editing)
|
||||
should be saved in the config. This will be cleaner/easier once the config is JSON, so holding off on that for now.
|
||||
*/
|
||||
|
||||
MapListToolBar::MapListToolBar(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, ui(new Ui::MapListToolBar)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->button_ToggleEmptyFolders, &QAbstractButton::clicked, this, &MapListToolBar::toggleEmptyFolders);
|
||||
ui->button_ToggleEmptyFolders->setChecked(!m_emptyFoldersVisible);
|
||||
ui->button_ToggleEdit->setChecked(m_editsAllowed);
|
||||
|
||||
connect(ui->button_AddFolder, &QAbstractButton::clicked, this, &MapListToolBar::addFolderClicked); // TODO: Tool tip
|
||||
connect(ui->button_ExpandAll, &QAbstractButton::clicked, this, &MapListToolBar::expandList);
|
||||
connect(ui->button_CollapseAll, &QAbstractButton::clicked, this, &MapListToolBar::collapseList);
|
||||
connect(ui->button_ToggleEdit, &QAbstractButton::clicked, this, &MapListToolBar::toggleEditsAllowed);
|
||||
connect(ui->lineEdit_filterBox, &QLineEdit::textChanged, this, &MapListToolBar::applyFilter);
|
||||
connect(ui->button_ToggleEmptyFolders, &QAbstractButton::clicked, [this] {
|
||||
toggleEmptyFolders();
|
||||
|
||||
// Display message to let user know what just happened (if there are no empty folders visible it's not obvious).
|
||||
const QString message = QString("%1 empty folders!").arg(m_emptyFoldersVisible ? "Showing" : "Hiding");
|
||||
QToolTip::showText(ui->button_ToggleEmptyFolders->mapToGlobal(QPoint(0, 0)), message);
|
||||
});
|
||||
}
|
||||
|
||||
MapListToolBar::~MapListToolBar()
|
||||
|
@ -26,16 +40,28 @@ MapListToolBar::~MapListToolBar()
|
|||
void MapListToolBar::setList(MapTree *list) {
|
||||
m_list = list;
|
||||
|
||||
// Sync list with current button states
|
||||
setEditsAllowed(ui->button_ToggleEdit->isChecked());
|
||||
// TODO: Empty folders
|
||||
// Sync list with current settings
|
||||
setEditsAllowed(m_editsAllowed);
|
||||
setEmptyFoldersVisible(m_emptyFoldersVisible);
|
||||
}
|
||||
|
||||
void MapListToolBar::setEditsAllowedButtonHidden(bool hidden) {
|
||||
ui->button_ToggleEdit->setVisible(!hidden);
|
||||
void MapListToolBar::setEditsAllowedButtonVisible(bool visible) {
|
||||
ui->button_ToggleEdit->setVisible(visible);
|
||||
}
|
||||
|
||||
void MapListToolBar::toggleEditsAllowed() {
|
||||
if (m_list) {
|
||||
m_list->clearSelection();
|
||||
}
|
||||
setEditsAllowed(!m_editsAllowed);
|
||||
}
|
||||
|
||||
void MapListToolBar::setEditsAllowed(bool allowed) {
|
||||
m_editsAllowed = allowed;
|
||||
|
||||
const QSignalBlocker b(ui->button_ToggleEdit);
|
||||
ui->button_ToggleEdit->setChecked(allowed);
|
||||
|
||||
if (!m_list)
|
||||
return;
|
||||
|
||||
|
@ -56,26 +82,27 @@ void MapListToolBar::setEditsAllowed(bool allowed) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Sync the UI in each of these
|
||||
|
||||
void MapListToolBar::toggleEmptyFolders() {
|
||||
if (!m_list)
|
||||
return;
|
||||
setEmptyFoldersVisible(!m_emptyFoldersVisible);
|
||||
}
|
||||
|
||||
auto model = static_cast<FilterChildrenProxyModel*>(m_list->model());
|
||||
if (!model)
|
||||
return;
|
||||
void MapListToolBar::setEmptyFoldersVisible(bool visible) {
|
||||
m_emptyFoldersVisible = visible;
|
||||
|
||||
bool hidden = model->toggleHideEmpty();
|
||||
model->setFilterRegularExpression(ui->lineEdit_filterBox->text());
|
||||
if (m_list) {
|
||||
auto model = static_cast<FilterChildrenProxyModel*>(m_list->model());
|
||||
if (model) {
|
||||
model->setHideEmpty(!visible);
|
||||
model->setFilterRegularExpression(ui->lineEdit_filterBox->text());
|
||||
}
|
||||
}
|
||||
|
||||
// Update tool tip to reflect what will happen if the button is pressed.
|
||||
const QString toolTip = QString("%1 empty folders in the list.").arg(hidden ? "Show" : "Hide");
|
||||
const QString toolTip = QString("%1 empty folders in the list.").arg(visible ? "Hide" : "Show");
|
||||
ui->button_ToggleEmptyFolders->setToolTip(toolTip);
|
||||
|
||||
// Display message to let user know what just happened (if there are no empty folders visible it's not obvious).
|
||||
const QString message = QString("%1 empty folders!").arg(hidden ? "Hiding" : "Showing");
|
||||
QToolTip::showText(ui->button_ToggleEmptyFolders->mapToGlobal(QPoint(0, 0)), message);
|
||||
const QSignalBlocker b(ui->button_ToggleEmptyFolders);
|
||||
ui->button_ToggleEmptyFolders->setChecked(!visible);
|
||||
}
|
||||
|
||||
void MapListToolBar::expandList() {
|
||||
|
@ -89,15 +116,6 @@ void MapListToolBar::collapseList() {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Save this state in porymapConfig?
|
||||
// TODO: This isn't actually toggling anything, it's just updating based on the button
|
||||
void MapListToolBar::toggleEditsAllowed() {
|
||||
if (m_list) {
|
||||
m_list->clearSelection();
|
||||
}
|
||||
setEditsAllowed(ui->button_ToggleEdit->isChecked());
|
||||
}
|
||||
|
||||
void MapListToolBar::applyFilter(const QString &filterText) {
|
||||
if (!m_list || m_filterLocked)
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue