Add filter to UI

This commit is contained in:
Diegoisawesome 2018-10-02 21:46:08 -05:00
parent 9f55dbfa23
commit 6269d4822a
16 changed files with 219 additions and 47 deletions

View file

@ -26,28 +26,144 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QTreeView" name="mapList"> <widget class="QWidget" name="mapListContainer" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <layout class="QVBoxLayout" name="verticalLayout">
<size> <property name="spacing">
<width>100</width> <number>0</number>
<height>0</height> </property>
</size> <property name="leftMargin">
</property> <number>0</number>
<property name="selectionMode"> </property>
<enum>QAbstractItemView::SingleSelection</enum> <property name="topMargin">
</property> <number>0</number>
<property name="selectionBehavior"> </property>
<enum>QAbstractItemView::SelectItems</enum> <property name="rightMargin">
</property> <number>0</number>
<attribute name="headerVisible"> </property>
<bool>false</bool> <property name="bottomMargin">
</attribute> <number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_MapSortOrder">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/sort_alphabet.ico</normaloff>:/icons/sort_alphabet.ico</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonIconOnly</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>24</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_filterBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter maps...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="mapList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget> </widget>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="enabled"> <property name="enabled">
@ -73,7 +189,7 @@
<string/> <string/>
</property> </property>
<attribute name="icon"> <attribute name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/map.ico</normaloff>:/icons/map.ico</iconset> <normaloff>:/icons/map.ico</normaloff>:/icons/map.ico</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
@ -177,7 +293,7 @@
<string>Paint</string> <string>Paint</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset> <normaloff>:/icons/pencil.ico</normaloff>:/icons/pencil.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -203,7 +319,7 @@
<string>Select</string> <string>Select</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset> <normaloff>:/icons/cursor.ico</normaloff>:/icons/cursor.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -220,7 +336,7 @@
<string>Fill</string> <string>Fill</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset> <normaloff>:/icons/fill_color.ico</normaloff>:/icons/fill_color.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -237,7 +353,7 @@
<string>Dropper</string> <string>Dropper</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset> <normaloff>:/icons/pipette.ico</normaloff>:/icons/pipette.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -254,7 +370,7 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/move.ico</normaloff>:/icons/move.ico</iconset> <normaloff>:/icons/move.ico</normaloff>:/icons/move.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -271,7 +387,7 @@
<string>Shift</string> <string>Shift</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/shift.ico</normaloff>:/icons/shift.ico</iconset> <normaloff>:/icons/shift.ico</normaloff>:/icons/shift.ico</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -1355,7 +1471,7 @@
<string>New Object</string> <string>New Object</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/add.ico</normaloff>:/icons/add.ico</iconset> <normaloff>:/icons/add.ico</normaloff>:/icons/add.ico</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -1384,7 +1500,7 @@
<string>Delete</string> <string>Delete</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="../resources/images.qrc">
<normaloff>:/icons/delete.ico</normaloff>:/icons/delete.ico</iconset> <normaloff>:/icons/delete.ico</normaloff>:/icons/delete.ico</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -2295,7 +2411,7 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="resources/images.qrc"/> <include location="../resources/images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View file

@ -0,0 +1,17 @@
#ifndef FILTERCHILDRENPROXYMODEL_H
#define FILTERCHILDRENPROXYMODEL_H
#include <QSortFilterProxyModel>
class FilterChildrenProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit FilterChildrenProxyModel(QObject *parent = nullptr);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
};
#endif // FILTERCHILDRENPROXYMODEL_H

View file

@ -130,6 +130,7 @@ private:
QMap<QString, QModelIndex> mapListIndexes; QMap<QString, QModelIndex> mapListIndexes;
Editor *editor = nullptr; Editor *editor = nullptr;
QIcon* mapIcon; QIcon* mapIcon;
QIcon* mapEditedIcon;
void setMap(QString, bool scrollTreeView = false); void setMap(QString, bool scrollTreeView = false);
void redrawMapScene(); void redrawMapScene();
void loadDataStructures(); void loadDataStructures();

View file

@ -17,6 +17,7 @@ ICON = resources/icons/porymap-icon-1.ico
SOURCES += src/core/block.cpp \ SOURCES += src/core/block.cpp \
src/core/blockdata.cpp \ src/core/blockdata.cpp \
src/core/event.cpp \ src/core/event.cpp \
src/core/filterchildrenproxymodel.cpp \
src/core/heallocation.cpp \ src/core/heallocation.cpp \
src/core/historyitem.cpp \ src/core/historyitem.cpp \
src/core/map.cpp \ src/core/map.cpp \
@ -50,6 +51,7 @@ SOURCES += src/core/block.cpp \
HEADERS += include/core/block.h \ HEADERS += include/core/block.h \
include/core/blockdata.h \ include/core/blockdata.h \
include/core/event.h \ include/core/event.h \
include/core/filterchildrenproxymodel.h \
include/core/heallocation.h \ include/core/heallocation.h \
include/core/history.h \ include/core/history.h \
include/core/historyitem.h \ include/core/historyitem.h \

View file

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -3,9 +3,7 @@
<file>icons/folder.ico</file> <file>icons/folder.ico</file>
<file>icons/folder_closed.ico</file> <file>icons/folder_closed.ico</file>
<file>icons/folder_closed_map.ico</file> <file>icons/folder_closed_map.ico</file>
<file>icons/folder_image.ico</file>
<file>icons/folder_map.ico</file> <file>icons/folder_map.ico</file>
<file>icons/image.ico</file>
<file>icons/map.ico</file> <file>icons/map.ico</file>
<file>icons/cursor.ico</file> <file>icons/cursor.ico</file>
<file>icons/fill_color.ico</file> <file>icons/fill_color.ico</file>
@ -23,5 +21,12 @@
<file>icons/shift.ico</file> <file>icons/shift.ico</file>
<file>icons/shift_cursor.ico</file> <file>icons/shift_cursor.ico</file>
<file>icons/porymap-icon-1.ico</file> <file>icons/porymap-icon-1.ico</file>
<file>icons/folder_map_edited.ico</file>
<file>icons/folder_map_opened.ico</file>
<file>icons/map_edited.ico</file>
<file>icons/map_opened.ico</file>
<file>icons/sort_alphabet.ico</file>
<file>icons/sort_map.ico</file>
<file>icons/sort_number.ico</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -0,0 +1,35 @@
#include "filterchildrenproxymodel.h"
FilterChildrenProxyModel::FilterChildrenProxyModel(QObject *parent) :
QSortFilterProxyModel(parent)
{
}
bool FilterChildrenProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
// custom behaviour :
if(filterRegExp().isEmpty() == false)
{
// get source-model index for current row
QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ;
if(source_index.isValid())
{
// if any of children matches the filter, then current index matches the filter as well
int i, nb = sourceModel()->rowCount(source_index);
for (i = 0; i < nb; ++i)
{
if (filterAcceptsRow(i, source_index))
{
return true;
}
}
// check current index itself
QString key = sourceModel()->data(source_index, filterRole()).toString();
QString parentKey = sourceModel()->data(source_parent, filterRole()).toString();
return key.contains(filterRegExp()) || parentKey.contains(filterRegExp());
}
}
// parent call for initial behaviour
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}

View file

@ -180,6 +180,10 @@ void MainWindow::setMap(QString map_name, bool scrollTreeView) {
if (map_name.isNull()) { if (map_name.isNull()) {
return; return;
} }
if (editor->map != nullptr && !editor->map->name.isNull()) {
ui->mapList->setExpanded(mapListIndexes.value(editor->map->name), false);
}
ui->mapList->setExpanded(mapListIndexes.value(map_name), true);
editor->setMap(map_name); editor->setMap(map_name);
redrawMapScene(); redrawMapScene();
displayMapProperties(); displayMapProperties();
@ -418,26 +422,19 @@ void MainWindow::populateMapList() {
QIcon folderIcon; QIcon folderIcon;
folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off); folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On);
mapIcon = new QIcon; mapIcon = new QIcon;
mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off); mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
mapIcon->addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On); mapIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal, QIcon::On);
mapEditedIcon = new QIcon;
mapEditedIcon->addFile(QStringLiteral(":/icons/map_edited.ico"), QSize(), QIcon::Normal, QIcon::Off);
mapEditedIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal , QIcon::On);
mapListModel = new QStandardItemModel; mapListModel = new QStandardItemModel;
mapGroupsModel = new QList<QStandardItem*>; mapGroupsModel = new QList<QStandardItem*>;
QStandardItem *entry = new QStandardItem;
entry->setText(project->getProjectTitle());
entry->setIcon(folderIcon);
entry->setEditable(false);
mapListModel->appendRow(entry);
QStandardItem *maps = new QStandardItem;
maps->setText("maps");
maps->setIcon(folderIcon);
maps->setEditable(false);
entry->appendRow(maps);
project->readMapGroups(); project->readMapGroups();
for (int i = 0; i < project->groupNames->length(); i++) { for (int i = 0; i < project->groupNames->length(); i++) {
QString group_name = project->groupNames->value(i); QString group_name = project->groupNames->value(i);
@ -448,7 +445,7 @@ void MainWindow::populateMapList() {
group->setData(group_name, Qt::UserRole); group->setData(group_name, Qt::UserRole);
group->setData("map_group", MapListUserRoles::TypeRole); group->setData("map_group", MapListUserRoles::TypeRole);
group->setData(i, MapListUserRoles::GroupRole); group->setData(i, MapListUserRoles::GroupRole);
maps->appendRow(group); mapListModel->appendRow(group);
mapGroupsModel->append(group); mapGroupsModel->append(group);
QStringList names = project->groupedMapNames.value(i); QStringList names = project->groupedMapNames.value(i);
for (int j = 0; j < names.length(); j++) { for (int j = 0; j < names.length(); j++) {
@ -466,7 +463,7 @@ void MainWindow::populateMapList() {
ui->mapList->setModel(mapListModel); ui->mapList->setModel(mapListModel);
ui->mapList->setUpdatesEnabled(true); ui->mapList->setUpdatesEnabled(true);
ui->mapList->expandToDepth(2); ui->mapList->expandToDepth(0);
ui->mapList->repaint(); ui->mapList->repaint();
} }
@ -563,10 +560,9 @@ void MainWindow::markEdited(QModelIndex index) {
QString map_name = data.toString(); QString map_name = data.toString();
if (editor->project) { if (editor->project) {
if (editor->project->map_cache->contains(map_name)) { if (editor->project->map_cache->contains(map_name)) {
// Just mark anything that's been opened for now. if (editor->project->map_cache->value(map_name)->hasUnsavedChanges()) {
// TODO if (project->getMap()->saved) mapListModel->itemFromIndex(mapListIndexes.value(map_name))->setIcon(*mapEditedIcon);
//ui->mapList->setExpanded(index, true); }
ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges());
} }
} }
} }