1
0
mirror of https://github.com/altlinux/admc.git synced 2025-02-09 01:57:26 +03:00

rework how console filter dialog works

it's given to object impl and then impl gets filter directly from
\ the dialog
replace refresh_object_tree() with ObjectImpl::refresh_tree()
This commit is contained in:
Dmitry Degtyarev 2021-11-04 12:19:52 +04:00
parent 143072a63c
commit 2280b071ea
6 changed files with 45 additions and 59 deletions

View File

@ -47,6 +47,7 @@
#include "settings.h"
#include "status.h"
#include "utils.h"
#include "console_filter_dialog.h"
#include <QDebug>
#include <QMenu>
@ -69,6 +70,7 @@ ObjectImpl::ObjectImpl(ConsoleWidget *console_arg)
: ConsoleImpl(console_arg) {
buddy_console = nullptr;
policy_impl = nullptr;
filter_dialog = nullptr;
change_dc_dialog = new ChangeDCDialog(console);
move_dialog = new SelectContainerDialog(console);
@ -82,9 +84,6 @@ ObjectImpl::ObjectImpl(ConsoleWidget *console_arg)
upn_suffixes_editor = new MultiEditor(console);
password_dialog = new PasswordDialog(console);
current_filter = QString();
filtering_is_ON = false;
set_results_view(new ResultsView(console_arg));
find_action_enabled = true;
@ -190,13 +189,12 @@ void ObjectImpl::set_buddy_console(ConsoleWidget *buddy_console_arg) {
buddy_console = buddy_console_arg;
}
void ObjectImpl::enable_filtering(const QString &filter) {
current_filter = filter;
filtering_is_ON = true;
}
void ObjectImpl::set_filter_dialog(ConsoleFilterDialog *filter_dialog_arg) {
filter_dialog = filter_dialog_arg;
void ObjectImpl::disable_filtering() {
filtering_is_ON = false;
connect(
filter_dialog, &QDialog::accepted,
this, &ObjectImpl::refresh_tree);
}
// Load children of this item in scope tree
@ -215,9 +213,9 @@ void ObjectImpl::fetch(const QModelIndex &index) {
// NOTE: OR user filter with containers filter so
// that container objects are always shown, even if
// they are filtered out by user filter
if (filtering_is_ON) {
if (filter_dialog != nullptr && filter_dialog->filtering_ON()) {
out = filter_OR({is_container_filter(), out});
out = filter_OR({current_filter, out});
out = filter_OR({filter_dialog->get_filter(), out});
}
advanced_features_filter(out);
@ -294,7 +292,7 @@ QString ObjectImpl::get_description(const QModelIndex &index) const {
out += object_count_text;
if (filtering_is_ON) {
if (filter_dialog != nullptr && filter_dialog->filtering_ON()) {
out += tr(" [Filtering enabled]");
}
@ -616,6 +614,19 @@ QList<int> ObjectImpl::default_columns() const {
return object_impl_default_columns();
}
void ObjectImpl::refresh_tree() {
const QModelIndex object_tree_root = get_object_tree_root(console);
if (!object_tree_root.isValid()) {
return;
}
show_busy_indicator();
console->refresh_scope(object_tree_root);
hide_busy_indicator();
}
void ObjectImpl::on_new_user() {
new_object(create_user_dialog);
}

View File

@ -41,6 +41,7 @@ class RenameObjectDialog;
class CreateObjectDialog;
class AttributeEditor;
class PasswordDialog;
class ConsoleFilterDialog;
/**
* Some f-ns used for models that store objects.
@ -74,8 +75,12 @@ public:
// buddy console.
void set_buddy_console(ConsoleWidget *buddy_console);
void enable_filtering(const QString &filter);
void disable_filtering();
// Filter will be loaded from this dialog. If no dialog
// is set, no filter is applied.
//
// NOTE: filter dialog is optional because object impl
// used in find widget doesn't need it
void set_filter_dialog(ConsoleFilterDialog *filter_dialog);
void fetch(const QModelIndex &index) override;
bool can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) override;
@ -101,6 +106,8 @@ public:
QList<QString> column_labels() const override;
QList<int> default_columns() const override;
void refresh_tree();
private slots:
void on_new_user();
void on_new_computer();
@ -138,9 +145,7 @@ private:
CreateObjectDialog *create_computer_dialog;
AttributeEditor *upn_suffixes_editor;
PasswordDialog *password_dialog;
QString current_filter;
bool filtering_is_ON;
ConsoleFilterDialog *filter_dialog;
QAction *find_action;
QAction *move_action;

View File

@ -66,7 +66,8 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent)
action_show_client_user->setCheckable(true);
ui->statusbar->addAction(action_show_client_user);
d->filter_dialog = new ConsoleFilterDialog(this);
auto filter_dialog = new ConsoleFilterDialog(this);
filter_dialog->init(ad.adconfig());
//
// Console
@ -87,6 +88,7 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent)
ui->console->register_impl(ItemType_QueryFolder, query_folder_impl);
d->object_impl->set_policy_impl(policy_impl);
d->object_impl->set_filter_dialog(filter_dialog);
query_item_impl->set_query_folder_impl(query_folder_impl);
// Create dialogs opened from menubar
@ -186,9 +188,6 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent)
ui->console->set_current_scope(object_tree_root);
}
d->filter_dialog->init(ad.adconfig());
on_filter_dialog_accepted();
query_item_impl->init(ad.adconfig());
query_folder_impl->init(ad.adconfig());
@ -289,10 +288,7 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent)
connect(
ui->action_filter_objects, &QAction::triggered,
d->filter_dialog, &QDialog::open);
connect(
d->filter_dialog, &QDialog::accepted,
this, &MainWindow::on_filter_dialog_accepted);
filter_dialog, &QDialog::open);
connect(
ui->menu_action, &QMenu::aboutToShow,
@ -318,38 +314,27 @@ void MainWindow::closeEvent(QCloseEvent *event) {
}
// NOTE: f-ns below need to manually change a setting and
// then refresh_object_tree() because setting needs to be
// changed before tree is refreshed. If you do this in a
// more convenient way by connecting as a slot, call order
// will be undefined.
// then refresh_tree() because setting needs to be changed
// before tree is refreshed. If you do this in a more
// convenient way by connecting as a slot, call order will
// be undefined.
void MainWindow::on_show_non_containers(bool checked) {
settings_set_bool(SETTING_show_non_containers_in_console_tree, checked);
refresh_object_tree();
d->object_impl->refresh_tree();
}
void MainWindow::on_dev_mode(bool checked) {
settings_set_bool(SETTING_dev_mode, checked);
refresh_object_tree();
d->object_impl->refresh_tree();
}
void MainWindow::on_advanced_features(bool checked) {
settings_set_bool(SETTING_advanced_features, checked);
refresh_object_tree();
}
void MainWindow::on_filter_dialog_accepted() {
if (d->filter_dialog->filtering_ON()) {
const QString filter = d->filter_dialog->get_filter();
d->object_impl->enable_filtering(filter);
} else {
d->object_impl->disable_filtering();
}
refresh_object_tree();
d->object_impl->refresh_tree();
}
void MainWindow::on_log_searches_changed() {
@ -417,16 +402,3 @@ void MainWindow::on_language_action(bool checked) {
message_box_information(this, tr("Info"), tr("Restart the app to switch to the selected language."));
}
void MainWindow::refresh_object_tree() {
const QModelIndex object_tree_root = get_object_tree_root(ui->console);
if (!object_tree_root.isValid()) {
return;
}
show_busy_indicator();
ui->console->refresh_scope(object_tree_root);
hide_busy_indicator();
}

View File

@ -45,7 +45,6 @@ protected:
private:
MainWindowPrivate *d;
void refresh_object_tree();
void on_show_non_containers(bool checked);
void on_dev_mode(bool checked);
void on_advanced_features(bool checked);

View File

@ -24,13 +24,11 @@
#include <QLocale>
class ObjectImpl;
class ConsoleFilterDialog;
class QLabel;
class MainWindowPrivate final {
public:
ObjectImpl *object_impl;
ConsoleFilterDialog *filter_dialog;
QLabel *client_user_label;
QHash<QLocale::Language, QAction *> language_action_map;
};

View File

@ -205,6 +205,7 @@ QList<QPersistentModelIndex> persistent_index_list(const QList<QModelIndex> &ind
// is off
void advanced_features_filter(QString &filter) {
const bool advanced_features_OFF = !settings_get_bool(SETTING_advanced_features);
if (advanced_features_OFF) {
const QString advanced_features = filter_CONDITION(Condition_NotEquals, ATTRIBUTE_SHOW_IN_ADVANCED_VIEW_ONLY, LDAP_BOOL_TRUE);
filter = filter_AND({filter, advanced_features});