Skip to content

Commit

Permalink
Implemented "Show Edited Cells" filter toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frodo45127 committed Oct 9, 2024
1 parent cdf27f7 commit b41a54c
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 49 deletions.
Binary file modified 3rdparty/builds/qt_rpfm_extensions.lib
Binary file not shown.
4 changes: 3 additions & 1 deletion 3rdparty/src/qt_rpfm_extensions/include/tableview_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extern "C" void trigger_tableview_filter(
QList<int> case_sensitive = QList<int>(),
QList<int> show_blank_cells = QList<int>(),
QList<int> match_groups_per_column = QList<int>(),
QList<int> variant_to_search = QList<int>()
QList<int> variant_to_search = QList<int>(),
QList<int> show_edited_cells = QList<int>()
);

class QTableViewSortFilterProxyModel : public QSortFilterProxyModel
Expand All @@ -33,6 +34,7 @@ class QTableViewSortFilterProxyModel : public QSortFilterProxyModel
QList<int> show_blank_cells;
QList<int> match_groups_per_column;
QList<int> variant_to_search;
QList<int> show_edited_cells;

explicit QTableViewSortFilterProxyModel(QObject *parent = nullptr);
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
Expand Down
15 changes: 13 additions & 2 deletions 3rdparty/src/qt_rpfm_extensions/src/tableview_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ extern "C" void trigger_tableview_filter(
QList<int> case_sensitive,
QList<int> show_blank_cells,
QList<int> match_groups_per_column,
QList<int> variant_to_search
QList<int> variant_to_search,
QList<int> show_edited_cells
) {
QTableViewSortFilterProxyModel* filter2 = static_cast<QTableViewSortFilterProxyModel*>(filter);
filter2->columns = columns;
Expand All @@ -32,6 +33,7 @@ extern "C" void trigger_tableview_filter(
filter2->show_blank_cells = show_blank_cells;
filter2->match_groups_per_column = match_groups_per_column;
filter2->variant_to_search = variant_to_search;
filter2->show_edited_cells = show_edited_cells;
filter2->setFilterKeyColumn(0);
}

Expand Down Expand Up @@ -74,6 +76,7 @@ bool QTableViewSortFilterProxyModel::filterAcceptsRow(int source_row, const QMod
QString pattern = patterns.at(match);
Qt::CaseSensitivity case_sensitivity = static_cast<Qt::CaseSensitivity>(case_sensitive.at(match));
bool show_blank_cells_in_column = show_blank_cells.at(match) == 1 ? true: false;
bool show_edited_cells_in_column = show_edited_cells.at(match) == 1 ? true: false;

QVector<int>* variants = new QVector<int>();
if (variant_to_search.at(match) == 0) {
Expand All @@ -88,12 +91,20 @@ bool QTableViewSortFilterProxyModel::filterAcceptsRow(int source_row, const QMod
QModelIndex currntIndex = sourceModel()->index(source_row, column, source_parent);
QStandardItem *currntData = static_cast<QStandardItemModel*>(sourceModel())->itemFromIndex(currntIndex);

QVariant isModifiedFromVanillaVariant = currntData->data(24);
bool isModifiedFromVanilla = !isModifiedFromVanillaVariant.isNull() ? isModifiedFromVanillaVariant.toBool(): false;

if (currntIndex.isValid()) {

// If the variant is modified and we want to show modified cells, we let it pass the filters.
if (show_edited_cells_in_column && isModifiedFromVanilla) {
continue;
}

// Checkbox matches.
//
// NOTE: isCheckable is broken if the cell is not editable.
if (currntData->data(Qt::CheckStateRole).isValid()) {
else if (currntData->data(Qt::CheckStateRole).isValid()) {
QString pattern_lower = pattern.toLower();
bool isChecked = currntData->checkState() == Qt::CheckState::Checked;

Expand Down
1 change: 1 addition & 0 deletions locale/English_en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ source_data_for_field_not_found = The source of the selected data could not be f
context_menu_go_to_loc = Go To Loc Entry: {"{"}{"}"}
loc_key_not_found = The loc entry couldn't be found.
table_filter_show_blank_cells = Show Blank Cells
table_filter_show_edited_cells = Show Edited Cells
special_stuff_rescue_packfile = Rescue PackFile
are_you_sure_rescue_packfile = Are you sure you want to do this? This is a dangerous option that should never be used unless the dev or RPFM tells you to specifically use it.
So again, are you sure you want to use this?
Expand Down
3 changes: 2 additions & 1 deletion rpfm_ui/src/diagnostics_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,10 @@ impl DiagnosticsUI {
let show_blank_lines = vec![false; sensitivity.len()];
let match_groups = vec![0; sensitivity.len()];
let variant_to_search = vec![0; sensitivity.len()];
let show_edited_cells = vec![false; sensitivity.len()];

// Filter whatever it's in that column by the text we got.
trigger_tableview_filter_safe(&diagnostics_ui.diagnostics_table_filter, &columns, patterns, &use_nott, &use_regex, &sensitivity, &show_blank_lines, &match_groups, &variant_to_search);
trigger_tableview_filter_safe(&diagnostics_ui.diagnostics_table_filter, &columns, patterns, &use_nott, &use_regex, &sensitivity, &show_blank_lines, &match_groups, &variant_to_search, &show_edited_cells);
}

pub unsafe fn update_level_counts(diagnostics_ui: &Rc<Self>, diagnostics: &[DiagnosticType]) {
Expand Down
9 changes: 6 additions & 3 deletions rpfm_ui/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ pub fn new_tableview_filter_safe(parent: QPtr<QObject>) -> QBox<QSortFilterProx
}

// This function triggers the special filter used for the TableViews It has to be triggered here to work properly.
extern "C" { fn trigger_tableview_filter(filter: *const QSortFilterProxyModel, columns: *const QListOfInt, patterns: *const QStringList, use_nott: *const QListOfInt, regex: *const QListOfInt, case_sensitive: *const QListOfInt, show_blank_cells: *const QListOfInt, match_groups: *const QListOfInt, variant_to_search: *const QListOfInt); }
pub unsafe fn trigger_tableview_filter_safe(filter: &QSortFilterProxyModel, columns: &[i32], patterns: Vec<Ptr<QString>>, use_nott: &[bool], regex: &[bool], case_sensitive: &[CaseSensitivity], show_blank_cells: &[bool], match_groups: &[i32], variant_to_search: &[i32]) {
extern "C" { fn trigger_tableview_filter(filter: *const QSortFilterProxyModel, columns: *const QListOfInt, patterns: *const QStringList, use_nott: *const QListOfInt, regex: *const QListOfInt, case_sensitive: *const QListOfInt, show_blank_cells: *const QListOfInt, match_groups: *const QListOfInt, variant_to_search: *const QListOfInt, show_edited_cells: *const QListOfInt); }
pub unsafe fn trigger_tableview_filter_safe(filter: &QSortFilterProxyModel, columns: &[i32], patterns: Vec<Ptr<QString>>, use_nott: &[bool], regex: &[bool], case_sensitive: &[CaseSensitivity], show_blank_cells: &[bool], match_groups: &[i32], variant_to_search: &[i32], show_edited_cells: &[bool]) {
let columns_qlist = QListOfInt::new();
columns.iter().for_each(|x| columns_qlist.append_int(x));

Expand All @@ -188,7 +188,10 @@ pub unsafe fn trigger_tableview_filter_safe(filter: &QSortFilterProxyModel, colu
let variant_to_search_qlist = QListOfInt::new();
variant_to_search.iter().for_each(|x| variant_to_search_qlist.append_int(x));

trigger_tableview_filter(filter, columns_qlist.into_ptr().as_raw_ptr(), patterns_qlist.into_ptr().as_raw_ptr(), use_nott_qlist.into_ptr().as_raw_ptr(), regex_qlist.into_ptr().as_raw_ptr(), case_sensitive_qlist.into_ptr().as_raw_ptr(), show_blank_cells_qlist.into_ptr().as_raw_ptr(), match_groups_qlist.into_ptr().as_raw_ptr(), variant_to_search_qlist.into_ptr().as_raw_ptr());
let show_edited_cells_qlist = QListOfInt::new();
show_edited_cells.iter().for_each(|x| show_edited_cells_qlist.append_int(if *x { &1i32 } else { &0i32 }));

trigger_tableview_filter(filter, columns_qlist.into_ptr().as_raw_ptr(), patterns_qlist.into_ptr().as_raw_ptr(), use_nott_qlist.into_ptr().as_raw_ptr(), regex_qlist.into_ptr().as_raw_ptr(), case_sensitive_qlist.into_ptr().as_raw_ptr(), show_blank_cells_qlist.into_ptr().as_raw_ptr(), match_groups_qlist.into_ptr().as_raw_ptr(), variant_to_search_qlist.into_ptr().as_raw_ptr(), show_edited_cells_qlist.into_ptr().as_raw_ptr());
}

// This function allow us to create a QTreeView compatible with draggable items
Expand Down
1 change: 1 addition & 0 deletions rpfm_ui/src/views/table/filter/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub unsafe fn set_connections_filter(ui: &FilterView, slots: &FilterViewSlots) {
ui.case_sensitive_button.toggled().connect(&slots.filter_case_sensitive_button);
ui.use_regex_button.toggled().connect(&slots.filter_use_regex_button);
ui.show_blank_cells_button.toggled().connect(&slots.filter_show_blank_cells_button);
ui.show_edited_cells_button.toggled().connect(&slots.filter_show_edited_cells_button);
ui.timer_delayed_updates.timeout().connect(&slots.filter_trigger);
ui.add_button.released().connect(&slots.filter_add);
ui.remove_button.released().connect(&slots.filter_remove);
Expand Down
4 changes: 4 additions & 0 deletions rpfm_ui/src/views/table/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct FilterView {
case_sensitive_button: QPtr<QToolButton>,
use_regex_button: QPtr<QToolButton>,
show_blank_cells_button: QPtr<QToolButton>,
show_edited_cells_button: QPtr<QToolButton>,
group_combobox: QPtr<QComboBox>,
column_combobox: QPtr<QComboBox>,
variant_combobox: QPtr<QComboBox>,
Expand Down Expand Up @@ -85,6 +86,7 @@ impl FilterView {
let case_sensitive_button: QPtr<QToolButton> = find_widget(&main_widget.static_upcast(), "case_sensitive_button")?;
let use_regex_button: QPtr<QToolButton> = find_widget(&main_widget.static_upcast(), "use_regex")?;
let show_blank_cells_button: QPtr<QToolButton> = find_widget(&main_widget.static_upcast(), "show_blank_cells_button")?;
let show_edited_cells_button: QPtr<QToolButton> = find_widget(&main_widget.static_upcast(), "show_edited_cells_button")?;
let group_combobox: QPtr<QComboBox> = find_widget(&main_widget.static_upcast(), "group_combobox")?;
let column_combobox: QPtr<QComboBox> = find_widget(&main_widget.static_upcast(), "column_combobox")?;
let variant_combobox: QPtr<QComboBox> = find_widget(&main_widget.static_upcast(), "variant_combobox")?;
Expand All @@ -97,6 +99,7 @@ impl FilterView {
use_regex_button.set_tool_tip(&qtr("table_filter_use_regex"));
use_regex_button.set_checked(true);
show_blank_cells_button.set_tool_tip(&qtr("table_filter_show_blank_cells"));
show_edited_cells_button.set_tool_tip(&qtr("table_filter_show_edited_cells"));
case_sensitive_button.set_tool_tip(&qtr("table_filter_case_sensitive"));
timer_delayed_updates.set_single_shot(true);

Expand Down Expand Up @@ -144,6 +147,7 @@ impl FilterView {
case_sensitive_button,
use_regex_button,
show_blank_cells_button,
show_edited_cells_button,
group_combobox,
column_combobox,
variant_combobox,
Expand Down
7 changes: 7 additions & 0 deletions rpfm_ui/src/views/table/filter/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct FilterViewSlots {
pub filter_case_sensitive_button: QBox<SlotNoArgs>,
pub filter_use_regex_button: QBox<SlotNoArgs>,
pub filter_show_blank_cells_button: QBox<SlotNoArgs>,
pub filter_show_edited_cells_button: QBox<SlotNoArgs>,
pub filter_trigger: QBox<SlotNoArgs>,
pub filter_check_regex: QBox<SlotOfQString>,
pub filter_add: QBox<SlotNoArgs>,
Expand Down Expand Up @@ -100,6 +101,11 @@ impl FilterViewSlots {
parent_view.filter_table();
}));

let filter_show_edited_cells_button = SlotNoArgs::new(&view.main_widget, clone!(
parent_view => move || {
parent_view.filter_table();
}));

// Function triggered by the filter timer.
let filter_trigger = SlotNoArgs::new(&view.main_widget, clone!(
parent_view => move || {
Expand Down Expand Up @@ -146,6 +152,7 @@ impl FilterViewSlots {
filter_case_sensitive_button,
filter_use_regex_button,
filter_show_blank_cells_button,
filter_show_edited_cells_button,
filter_trigger,
filter_check_regex,
filter_add,
Expand Down
6 changes: 5 additions & 1 deletion rpfm_ui/src/views/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ impl TableView {
let mut show_blank_cells = vec![];
let mut match_groups = vec![];
let mut variant_to_search = vec![];
let mut show_edited_cells = vec![];

let filters = self.filters.read().unwrap();
for filter in filters.iter() {
Expand Down Expand Up @@ -1150,6 +1151,9 @@ impl TableView {
// Check if we should filter out blank cells or not.
show_blank_cells.push(filter.show_blank_cells_button().is_checked());

// Check if we should filter out edited cells or not.
show_edited_cells.push(filter.show_edited_cells_button().is_checked());

let pattern = filter.filter_line_edit().text().to_std_string();
use_nott.push(filter.not_checkbox().is_checked());

Expand All @@ -1161,7 +1165,7 @@ impl TableView {
}

// Filter whatever it's in that column by the text we got.
trigger_tableview_filter_safe(&self.table_filter, &columns, patterns, &use_nott, &use_regex, &sensitivity, &show_blank_cells, &match_groups, &variant_to_search);
trigger_tableview_filter_safe(&self.table_filter, &columns, patterns, &use_nott, &use_regex, &sensitivity, &show_blank_cells, &match_groups, &variant_to_search, &show_edited_cells);

// Update the line count.
self.update_line_counter();
Expand Down
101 changes: 60 additions & 41 deletions rpfm_ui/ui_templates/table_filter_groupbox.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,7 @@
<property name="spacing">
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QCheckBox" name="not_checkbox">
<property name="text">
<string>!</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QComboBox" name="column_combobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="9">
<item row="2" column="10">
<widget class="QToolButton" name="remove_button">
<property name="enabled">
<bool>false</bool>
Expand All @@ -72,6 +55,33 @@
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QToolButton" name="show_blank_cells_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="markasblank">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="not_checkbox">
<property name="text">
<string>!</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="filter_line_edit">
<property name="sizePolicy">
Expand Down Expand Up @@ -103,12 +113,22 @@
</widget>
</item>
<item row="2" column="8">
<widget class="QToolButton" name="add_button">
<widget class="QComboBox" name="group_combobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QToolButton" name="use_regex">
<property name="text">
<string/>
<string>...</string>
</property>
<property name="icon">
<iconset theme="list-add">
<iconset theme="nextfuzzyuntrans">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
Expand All @@ -117,10 +137,13 @@
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QComboBox" name="group_combobox">
<widget class="QComboBox" name="column_combobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand All @@ -129,13 +152,13 @@
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QToolButton" name="show_blank_cells_button">
<item row="2" column="9">
<widget class="QToolButton" name="add_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="markasblank">
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
Expand All @@ -144,19 +167,25 @@
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</widget>
</item>
<item row="2" column="6">
<widget class="QComboBox" name="variant_combobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QToolButton" name="use_regex">
<item row="2" column="5">
<widget class="QToolButton" name="show_edited_cells_button">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="nextfuzzyuntrans">
<normaloff>.</normaloff>.</iconset>
<iconset theme="cell_edit"/>
</property>
<property name="iconSize">
<size>
Expand All @@ -169,16 +198,6 @@
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QComboBox" name="variant_combobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit b41a54c

Please sign in to comment.