From bf5f1ab7b49d1f3f9fa43963b353f1d2f9827018 Mon Sep 17 00:00:00 2001 From: Semyon Knyazev Date: Fri, 17 Nov 2023 03:38:50 +0400 Subject: [PATCH] Add domain info item Added root domain info item to console tree and corresponding functional for domain_info_impl to main window --- src/admc/console_impls/item_type.h | 1 + src/admc/console_widget/console_widget.cpp | 42 +++++++++++++++------- src/admc/console_widget/console_widget.h | 7 +++- src/admc/console_widget/console_widget_p.h | 4 +++ src/admc/main_window.cpp | 23 ++++++------ src/admc/main_window.h | 2 +- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/admc/console_impls/item_type.h b/src/admc/console_impls/item_type.h index 051b5f7a..725171da 100644 --- a/src/admc/console_impls/item_type.h +++ b/src/admc/console_impls/item_type.h @@ -33,6 +33,7 @@ enum ItemType { ItemType_FindObject, ItemType_FindPolicy, ItemType_FoundPolicy, + ItemType_DomainInfo, ItemType_LAST, }; diff --git a/src/admc/console_widget/console_widget.cpp b/src/admc/console_widget/console_widget.cpp index 0941c1eb..850f4673 100644 --- a/src/admc/console_widget/console_widget.cpp +++ b/src/admc/console_widget/console_widget.cpp @@ -105,6 +105,7 @@ ConsoleWidget::ConsoleWidget(QWidget *parent) // greater at the moment. d->scope_view->header()->setStretchLastSection(false); d->scope_view->header()->setSectionResizeMode(QHeaderView::Interactive); + d->scope_view->setRootIsDecorated(false); d->model = new ConsoleDragModel(this); @@ -219,13 +220,18 @@ ConsoleWidget::ConsoleWidget(QWidget *parent) connect( qApp, &QApplication::focusChanged, d, &ConsoleWidgetPrivate::on_focus_changed); + + d->domain_info_index = add_scope_item(ItemType_DomainInfo, QModelIndex())[0]->index(); + d->scope_view->expand(d->domain_info_index); + connect(d->scope_view, &QTreeView::collapsed, [this](const QModelIndex &index_proxy) { + const QModelIndex index = d->scope_proxy_model->mapToSource(index_proxy); + if (index == d->domain_info_index) { + d->scope_view->expand(index_proxy); + } + }); } void ConsoleWidget::register_impl(const int type, ConsoleImpl *impl) { - if (d->impl_map.contains(type)) { - qDebug() << "Duplicate register_impl() call for type" << type; - } - d->impl_map[type] = impl; QWidget *results_widget = impl->widget(); @@ -281,7 +287,6 @@ QList ConsoleWidget::add_results_item(const int type, const QMo return 1; } else { ConsoleImpl *parent_impl = d->get_impl(parent); - return parent_impl->column_labels().size(); } }(); @@ -541,13 +546,12 @@ void ConsoleWidget::restore_state(const QVariant &state_variant) { // Restore displayed of currently selected view // type setting QAction *current_view_type_action = [&]() -> QAction * { - const ResultsViewType current_results_view_type = [&]() { - ConsoleImpl *current_impl = d->get_current_scope_impl(); - ResultsView *current_results_view = current_impl->view(); - const ResultsViewType out = current_results_view->current_view_type(); - - return out; - }(); + ConsoleImpl *current_impl = d->get_current_scope_impl(); + ResultsView *current_results_view = current_impl->view(); + if (!current_results_view) { + return nullptr; + } + const ResultsViewType current_results_view_type = current_results_view->current_view_type(); switch (current_results_view_type) { case ResultsViewType_Icons: return d->actions.view_icons; @@ -601,7 +605,19 @@ QWidget *ConsoleWidget::get_result_widget_for_index(const QModelIndex &index) } void ConsoleWidget::clear_scope_tree() { - delete_children(d->scope_view->rootIndex()); + delete_children(d->domain_info_index); +} + +void ConsoleWidget::expand_item(const QModelIndex &index) { + if (!index.isValid()) { + return; + } + const QModelIndex index_proxy = d->scope_proxy_model->mapFromSource(index); + d->scope_view->expand(index_proxy); +} + +QPersistentModelIndex ConsoleWidget::domain_info_index() { + return d->domain_info_index; } void ConsoleWidget::resizeEvent(QResizeEvent *event) { diff --git a/src/admc/console_widget/console_widget.h b/src/admc/console_widget/console_widget.h index 879a196b..47988b83 100644 --- a/src/admc/console_widget/console_widget.h +++ b/src/admc/console_widget/console_widget.h @@ -181,16 +181,21 @@ public: // scope item index. Can return nullptr. QWidget *get_result_widget_for_index(const QModelIndex &index); - // Removes all items from scope tree view. + // Removes all items from scope tree view except top domain info item. // It is used when domain changes. void clear_scope_tree(); + void expand_item(const QModelIndex &index); + + QPersistentModelIndex domain_info_index(); + signals: // Emitted when selection in the whole console // widget changes, both in scope and results panes. // Can be caused by selection change in focused // view or change of which view is focused. void selection_changed(); + void fsmo_master_changed(const QString &new_master_dn, const QString &string_fsmo_role); protected: void resizeEvent(QResizeEvent *event) override; diff --git a/src/admc/console_widget/console_widget_p.h b/src/admc/console_widget/console_widget_p.h index f13ac219..56b88d43 100644 --- a/src/admc/console_widget/console_widget_p.h +++ b/src/admc/console_widget/console_widget_p.h @@ -30,6 +30,7 @@ #include #include +#include class QLabel; class QStackedWidget; @@ -87,6 +88,9 @@ public: QHash standard_action_map; + QPersistentModelIndex domain_info_index; + + ConsoleWidgetPrivate(ConsoleWidget *q_arg); void update_navigation_actions(); diff --git a/src/admc/main_window.cpp b/src/admc/main_window.cpp index fcc1ea1b..1cc62b05 100644 --- a/src/admc/main_window.cpp +++ b/src/admc/main_window.cpp @@ -44,8 +44,8 @@ #include "utils.h" #include "fsmo/fsmo_utils.h" #include "icon_manager/icon_manager.h" +#include "console_impls/domain_info_impl.h" -#include #include #include #include @@ -68,6 +68,9 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent) // // Console // + auto domain_info_impl = new DomainInfoImpl(ui->console); + ui->console->register_impl(ItemType_DomainInfo, domain_info_impl); + auto object_impl = new ObjectImpl(ui->console); ui->console->register_impl(ItemType_Object, object_impl); @@ -138,9 +141,12 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent) ui->menu_view->removeAction(ui->action_toggle_toolbar); // Load console tree's + domain_info_impl->load_domain_info_item(ad); + ui->console->set_current_scope(ui->console->domain_info_index()); console_object_tree_init(ui->console, ad); console_policy_tree_init(ui->console); console_query_tree_init(ui->console); + ui->console->expand_item(ui->console->domain_info_index()); // Set current scope to object head to load it const QModelIndex object_tree_root = get_object_tree_root(ui->console); @@ -369,7 +375,7 @@ void MainWindow::open_connection_options() { connect(dialog, &ConnectionOptionsDialog::domain_changed, [this](const QString &host) { show_busy_indicator(); - reload_scope_tree(); + reload_console_tree(); hide_busy_indicator(); g_status->add_message(tr("Connected to host ") + host, StatusType_Success); }); @@ -393,16 +399,9 @@ void MainWindow::edit_fsmo_roles() { auto dialog = new FSMODialog(ad, this); dialog->open(); + connect(dialog, &FSMODialog::master_changed, ui->console, &ConsoleWidget::fsmo_master_changed); } -void MainWindow::reload_scope_tree() -{ - AdInterface ad; - if (!ad.is_connected()) { - return; - } - ui->console->clear_scope_tree(); - console_object_tree_init(ui->console, ad); - console_policy_tree_init(ui->console); - console_query_tree_init(ui->console); +void MainWindow::reload_console_tree() { + ui->console->refresh_scope(ui->console->domain_info_index()); } diff --git a/src/admc/main_window.h b/src/admc/main_window.h index b92b1107..a5408224 100644 --- a/src/admc/main_window.h +++ b/src/admc/main_window.h @@ -52,7 +52,7 @@ private: void open_changelog(); void open_about(); void edit_fsmo_roles(); - void reload_scope_tree(); + void reload_console_tree(); }; #endif /* MAIN_WINDOW_H */