1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-20 10:04:05 +03:00

Add domain info item

Added root domain info item to console tree and
corresponding functional for domain_info_impl to main window
This commit is contained in:
Semyon Knyazev 2023-11-17 03:38:50 +04:00
parent 14343b61f0
commit bf5f1ab7b4
6 changed files with 52 additions and 27 deletions

View File

@ -33,6 +33,7 @@ enum ItemType {
ItemType_FindObject,
ItemType_FindPolicy,
ItemType_FoundPolicy,
ItemType_DomainInfo,
ItemType_LAST,
};

View File

@ -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<QStandardItem *> 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) {

View File

@ -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;

View File

@ -30,6 +30,7 @@
#include <QCoreApplication>
#include <QSet>
#include <QPersistentModelIndex>
class QLabel;
class QStackedWidget;
@ -87,6 +88,9 @@ public:
QHash<StandardAction, QAction *> standard_action_map;
QPersistentModelIndex domain_info_index;
ConsoleWidgetPrivate(ConsoleWidget *q_arg);
void update_navigation_actions();

View File

@ -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 <QDebug>
#include <QDesktopServices>
#include <QLabel>
#include <QModelIndex>
@ -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());
}

View File

@ -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 */