mirror of
https://github.com/altlinux/admc.git
synced 2025-01-22 18:03:57 +03:00
Policy OU linked policies widget is refactored and drag&drop model is added
Linked policies widget is refactored. In particular, the widget is initialized with console ptr now. Drag&drop changes: add model, configuration and corresponding applying slot.
This commit is contained in:
parent
828ba085cb
commit
30786c41d0
@ -138,7 +138,9 @@ void DragDropLinksModel::load_row(QList<QStandardItem *> &item_row, int order, c
|
||||
item_row[0]->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_Policy_Link));
|
||||
item_row[LinkedPoliciesColumn_Order]->setData(order, Qt::DisplayRole);
|
||||
item_row[LinkedPoliciesColumn_Name]->setText(display_name);
|
||||
item_row[LinkedPoliciesColumn_Enforced]->setCheckable(true);
|
||||
item_row[LinkedPoliciesColumn_Enforced]->setCheckState(is_enforced);
|
||||
item_row[LinkedPoliciesColumn_Disabled]->setCheckable(true);
|
||||
item_row[LinkedPoliciesColumn_Disabled]->setCheckState(is_disabled);
|
||||
|
||||
set_data_for_row(item_row, dn, LinkedPoliciesRole_DN);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "status.h"
|
||||
#include "utils.h"
|
||||
#include "icon_manager/icon_manager.h"
|
||||
#include "drag_drop_links_model.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QHeaderView>
|
||||
@ -21,12 +22,17 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
|
||||
LinkedPoliciesWidget::LinkedPoliciesWidget(QWidget *parent) :
|
||||
LinkedPoliciesWidget::LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::LinkedPoliciesWidget)
|
||||
ui(new Ui::LinkedPoliciesWidget),
|
||||
console(console_arg)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (!console) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto remove_link_action = new QAction(tr("Remove link"), this);
|
||||
auto move_up_action = new QAction(tr("Move up"), this);
|
||||
auto move_down_action = new QAction(tr("Move down"), this);
|
||||
@ -36,7 +42,7 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(QWidget *parent) :
|
||||
context_menu->addAction(move_up_action);
|
||||
context_menu->addAction(move_down_action);
|
||||
|
||||
model = new QStandardItemModel(0, LinkedPoliciesColumn_COUNT, this);
|
||||
model = new DragDropLinksModel(gplink, 0, LinkedPoliciesColumn_COUNT, this);
|
||||
set_horizontal_header_labels_from_map(model,
|
||||
{
|
||||
{LinkedPoliciesColumn_Order, tr("Order")},
|
||||
@ -47,13 +53,18 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(QWidget *parent) :
|
||||
|
||||
ui->view->set_model(model);
|
||||
|
||||
ui->view->detail_view()->header()->resizeSection(0, 50);
|
||||
ui->view->detail_view()->header()->resizeSection(1, 300);
|
||||
ui->view->detail_view()->header()->resizeSection(2, 100);
|
||||
ui->view->detail_view()->header()->resizeSection(3, 100);
|
||||
ui->view->detail_view()->header()->resizeSection(4, 500);
|
||||
QHeaderView *detail_view_header = ui->view->detail_view()->header();
|
||||
|
||||
ui->view->set_drag_drop_enabled(false);
|
||||
detail_view_header->resizeSection(0, 50);
|
||||
detail_view_header->resizeSection(1, 300);
|
||||
detail_view_header->resizeSection(2, 100);
|
||||
detail_view_header->resizeSection(3, 100);
|
||||
detail_view_header->resizeSection(4, 500);
|
||||
|
||||
ui->view->set_drag_drop_internal();
|
||||
ui->view->current_view()->setDragDropOverwriteMode(false);
|
||||
ui->view->current_view()->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->view->current_view()->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
const QVariant state = settings_get_variant(SETTING_policy_ou_results_state);
|
||||
ui->view->restore_state(state,
|
||||
@ -79,6 +90,29 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(QWidget *parent) :
|
||||
connect(
|
||||
move_down_action, &QAction::triggered,
|
||||
this, &LinkedPoliciesWidget::move_down);
|
||||
|
||||
connect(model, &DragDropLinksModel::link_orders_changed, [this](const Gplink &gplink_arg) {
|
||||
AdInterface ad;
|
||||
if (ad_failed(ad, this)) {
|
||||
model->arrange_orders_from_gplink(gplink);
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink_arg.to_string());
|
||||
if (!success) {
|
||||
model->arrange_orders_from_gplink(gplink);
|
||||
return;
|
||||
}
|
||||
|
||||
gplink = gplink_arg;
|
||||
const QModelIndex scope_tree_ou_index = console->get_current_scope_item();
|
||||
update_ou_item_gplink_data(gplink.to_string(), scope_tree_ou_index, console);
|
||||
|
||||
g_status->add_message(tr("Organizational unit ") + scope_tree_ou_index.data().toString() + tr("'s link orders have been succesfuly changed."),
|
||||
StatusType_Success);
|
||||
|
||||
emit gplink_changed(scope_tree_ou_index);
|
||||
});
|
||||
}
|
||||
|
||||
LinkedPoliciesWidget::~LinkedPoliciesWidget()
|
||||
@ -110,14 +144,10 @@ void LinkedPoliciesWidget::update(const QModelIndex &ou_index) {
|
||||
return out;
|
||||
}();
|
||||
|
||||
reload_gplink();
|
||||
update_link_items();
|
||||
emit gplink_changed(ou_index);
|
||||
}
|
||||
|
||||
void LinkedPoliciesWidget::set_console(ConsoleWidget *console_arg) {
|
||||
console = console_arg;
|
||||
}
|
||||
|
||||
void LinkedPoliciesWidget::on_item_changed(QStandardItem *item) {
|
||||
const LinkedPoliciesColumn column = (LinkedPoliciesColumn) item->column();
|
||||
if (!option_columns.contains(column)) {
|
||||
@ -149,7 +179,7 @@ void LinkedPoliciesWidget::on_item_changed(QStandardItem *item) {
|
||||
|
||||
g_status->display_ad_messages(ad, this);
|
||||
|
||||
reload_gplink();
|
||||
update_link_items();
|
||||
|
||||
const QModelIndex scope_tree_ou_index = console->get_current_scope_item();
|
||||
update_ou_item_gplink_data(gplink_string, scope_tree_ou_index, console);
|
||||
@ -224,7 +254,7 @@ void LinkedPoliciesWidget::move_down() {
|
||||
modify_gplink(modify_function);
|
||||
}
|
||||
|
||||
void LinkedPoliciesWidget::reload_gplink() {
|
||||
void LinkedPoliciesWidget::update_link_items() {
|
||||
model->removeRows(0, model->rowCount());
|
||||
|
||||
AdInterface ad;
|
||||
@ -236,7 +266,7 @@ void LinkedPoliciesWidget::reload_gplink() {
|
||||
|
||||
for (const AdObject &gpo_object : gpo_obj_list) {
|
||||
const QList<QStandardItem *> row = make_item_row(LinkedPoliciesColumn_COUNT);
|
||||
update_item_row(gpo_object, row);
|
||||
load_item_row(gpo_object, row);
|
||||
model->appendRow(row);
|
||||
}
|
||||
|
||||
@ -267,7 +297,7 @@ void LinkedPoliciesWidget::modify_gplink(void (*modify_function)(Gplink &, const
|
||||
|
||||
g_status->display_ad_messages(ad, this);
|
||||
|
||||
reload_gplink();
|
||||
update_link_items();
|
||||
|
||||
const QModelIndex scope_tree_ou_index = console->get_current_scope_item();
|
||||
update_ou_item_gplink_data(gplink_string, scope_tree_ou_index, console);
|
||||
@ -310,7 +340,7 @@ QList<AdObject> LinkedPoliciesWidget::gpo_object_list(AdInterface &ad) {
|
||||
return gpo_objects;
|
||||
}
|
||||
|
||||
void LinkedPoliciesWidget::update_item_row(const AdObject &gpo_object, QList<QStandardItem*> row) {
|
||||
void LinkedPoliciesWidget::load_item_row(const AdObject &gpo_object, QList<QStandardItem*> row) {
|
||||
const QList<QString> gpo_dn_list = gplink.get_gpo_list();
|
||||
|
||||
// NOTE: Gplink may contain invalid gpo's, in which
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "gplink.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSet>
|
||||
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
@ -14,6 +13,7 @@ class ConsoleWidget;
|
||||
class ADMCTestPolicyOUResultsWidget;
|
||||
class AdObject;
|
||||
class AdInterface;
|
||||
class DragDropLinksModel;
|
||||
|
||||
namespace Ui {
|
||||
class LinkedPoliciesWidget;
|
||||
@ -22,41 +22,14 @@ class LinkedPoliciesWidget;
|
||||
class LinkedPoliciesWidget final : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
enum LinkedPoliciesColumn {
|
||||
LinkedPoliciesColumn_Order,
|
||||
LinkedPoliciesColumn_Name,
|
||||
LinkedPoliciesColumn_Enforced,
|
||||
LinkedPoliciesColumn_Disabled,
|
||||
|
||||
LinkedPoliciesColumn_COUNT,
|
||||
};
|
||||
|
||||
enum LinkedPoliciesRole {
|
||||
LinkedPoliciesRole_DN = Qt::UserRole + 1,
|
||||
|
||||
LinkedPoliciesRole_COUNT,
|
||||
};
|
||||
|
||||
const QSet<LinkedPoliciesColumn> option_columns = {
|
||||
LinkedPoliciesColumn_Enforced,
|
||||
LinkedPoliciesColumn_Disabled,
|
||||
};
|
||||
|
||||
const QHash<LinkedPoliciesColumn, GplinkOption> column_to_option = {
|
||||
{LinkedPoliciesColumn_Enforced, GplinkOption_Enforced},
|
||||
{LinkedPoliciesColumn_Disabled, GplinkOption_Disabled},
|
||||
};
|
||||
|
||||
public:
|
||||
explicit LinkedPoliciesWidget(QWidget *parent = nullptr);
|
||||
explicit LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *parent = nullptr);
|
||||
~LinkedPoliciesWidget();
|
||||
|
||||
// Loads links for given OU. Nothing is done if given
|
||||
// index is not an OU in policy tree.
|
||||
void update(const QModelIndex &ou_index);
|
||||
|
||||
void set_console(ConsoleWidget *console_arg);
|
||||
|
||||
signals:
|
||||
void gplink_changed(const QModelIndex &index);
|
||||
|
||||
@ -64,7 +37,7 @@ private:
|
||||
Ui::LinkedPoliciesWidget *ui;
|
||||
|
||||
ConsoleWidget *console;
|
||||
QStandardItemModel *model;
|
||||
DragDropLinksModel *model;
|
||||
Gplink gplink;
|
||||
QString ou_dn;
|
||||
QMenu *context_menu;
|
||||
@ -74,11 +47,11 @@ private:
|
||||
void remove_link();
|
||||
void move_up();
|
||||
void move_down();
|
||||
void reload_gplink();
|
||||
void update_link_items();
|
||||
void modify_gplink(void (*modify_function)(Gplink &, const QString &));
|
||||
void change_policy_icon(const QString &policy_dn, bool is_checked, GplinkOption option);
|
||||
QList<AdObject> gpo_object_list(AdInterface &ad);
|
||||
void update_item_row(const AdObject &gpo_object, QList<QStandardItem*> row);
|
||||
void load_item_row(const AdObject &gpo_object, QList<QStandardItem*> row);
|
||||
};
|
||||
|
||||
#endif // LINKED_POLICIES_WIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user