mirror of
https://github.com/altlinux/admc.git
synced 2025-03-31 02:50:17 +03:00
make some actions global
move entry context menu creation into EntryWidget remove connect_proxy_action remove context_menu_requested take new entry actions out of enum'ed list
This commit is contained in:
parent
1a350089a3
commit
f8afff7ca2
@ -52,6 +52,7 @@ set(ADTOOL_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/create_entry_dialog.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/main_window.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/entry_widget.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/actions.cpp
|
||||
)
|
||||
|
||||
add_definitions(${QT5_DEFINITIONS})
|
||||
|
@ -2,11 +2,16 @@
|
||||
#include "ad_proxy_model.h"
|
||||
#include "ad_model.h"
|
||||
#include "ad_interface.h"
|
||||
#include "actions.h"
|
||||
|
||||
AdProxyModel::AdProxyModel(AdModel *model, QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
setSourceModel(model);
|
||||
|
||||
connect(
|
||||
&action_advanced_view, &QAction::triggered,
|
||||
this, &AdProxyModel::on_advanced_view_toggled);
|
||||
}
|
||||
|
||||
void AdProxyModel::on_advanced_view_toggled(bool checked) {
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
|
||||
bool only_show_containers = false;
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void on_advanced_view_toggled(bool checked);
|
||||
|
||||
private:
|
||||
|
@ -28,7 +28,7 @@ AttributesWidget::AttributesWidget()
|
||||
layout()->addWidget(view);
|
||||
};
|
||||
|
||||
void AttributesWidget::set_target_dn(const QString &new_target_dn) {
|
||||
void AttributesWidget::change_model_target(const QString &new_target_dn) {
|
||||
// Set model to new target
|
||||
model->change_target(new_target_dn);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
AttributesWidget();
|
||||
|
||||
public slots:
|
||||
void set_target_dn(const QString &new_target_dn);
|
||||
void change_model_target(const QString &new_target_dn);
|
||||
|
||||
private:
|
||||
enum Column {
|
||||
|
@ -18,6 +18,7 @@ ContainersWidget::ContainersWidget(AdModel *model)
|
||||
|
||||
proxy->only_show_containers = true;
|
||||
|
||||
column_hidden[AdModel::Column::Name] = false;
|
||||
column_hidden[AdModel::Column::Category] = true;
|
||||
column_hidden[AdModel::Column::Description] = true;
|
||||
column_hidden[AdModel::Column::DN] = true;
|
||||
|
@ -20,6 +20,9 @@ ContentsWidget::ContentsWidget(AdModel* model)
|
||||
|
||||
label->setText("Contents");
|
||||
|
||||
column_hidden[AdModel::Column::Name] = false;
|
||||
column_hidden[AdModel::Column::Category] = false;
|
||||
column_hidden[AdModel::Column::Description] = false;
|
||||
column_hidden[AdModel::Column::DN] = true;
|
||||
update_column_visibility();
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "ad_interface.h"
|
||||
#include "ad_model.h"
|
||||
#include "ad_proxy_model.h"
|
||||
#include "actions.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QItemSelection>
|
||||
@ -14,7 +15,7 @@
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
EntryWidget::EntryWidget(AdModel* model)
|
||||
: QWidget()
|
||||
@ -41,25 +42,36 @@ EntryWidget::EntryWidget(AdModel* model)
|
||||
}
|
||||
update_column_visibility();
|
||||
|
||||
// Convert view's customContextMenuRequested
|
||||
// to context_menu_requested signal with global pos
|
||||
connect(
|
||||
view, &QWidget::customContextMenuRequested,
|
||||
[this] (const QPoint &pos) {
|
||||
QModelIndex index = view->indexAt(pos);
|
||||
QObject::connect(
|
||||
&action_toggle_dn, &QAction::triggered,
|
||||
this, &EntryWidget::on_action_toggle_dn);
|
||||
|
||||
if (index.isValid()) {
|
||||
QPoint global_pos = view->mapToGlobal(pos);
|
||||
|
||||
emit context_menu_requested(global_pos);
|
||||
}
|
||||
});
|
||||
QObject::connect(
|
||||
view, &QWidget::customContextMenuRequested,
|
||||
this, &EntryWidget::on_context_menu_requested);
|
||||
}
|
||||
|
||||
void EntryWidget::connect_proxy_action(QAction *action_advanced_view) {
|
||||
connect(
|
||||
action_advanced_view, &QAction::triggered,
|
||||
proxy, &AdProxyModel::on_advanced_view_toggled);
|
||||
void EntryWidget::on_context_menu_requested(const QPoint &pos) {
|
||||
// Open entry context menu
|
||||
QModelIndex index = view->indexAt(pos);
|
||||
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu menu;
|
||||
|
||||
menu.addAction(&action_attributes);
|
||||
menu.addAction(&action_delete_entry);
|
||||
|
||||
QMenu *submenu_new = menu.addMenu("New");
|
||||
submenu_new->addAction(&action_new_user);
|
||||
submenu_new->addAction(&action_new_computer);
|
||||
submenu_new->addAction(&action_new_group);
|
||||
submenu_new->addAction(&action_new_ou);
|
||||
|
||||
QPoint global_pos = view->mapToGlobal(pos);
|
||||
menu.exec(global_pos, &action_attributes);
|
||||
}
|
||||
|
||||
QString EntryWidget::get_selected_dn() const {
|
||||
|
@ -21,13 +21,10 @@ public:
|
||||
EntryWidget(AdModel *model);
|
||||
|
||||
QString get_selected_dn() const;
|
||||
void connect_proxy_action(QAction *action_advanced_view);
|
||||
|
||||
signals:
|
||||
void context_menu_requested(const QPoint &pos);
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void on_action_toggle_dn(bool checked);
|
||||
void on_context_menu_requested(const QPoint &pos);
|
||||
|
||||
protected:
|
||||
QTreeView *view = nullptr;
|
||||
|
@ -6,9 +6,9 @@
|
||||
#include "ad_model.h"
|
||||
#include "attributes_model.h"
|
||||
#include "create_entry_dialog.h"
|
||||
#include "actions.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
@ -16,10 +16,14 @@
|
||||
#include <QStatusBar>
|
||||
#include <QTreeView>
|
||||
|
||||
MainWindow::MainWindow(): QMainWindow() {
|
||||
MainWindow::MainWindow()
|
||||
: QMainWindow()
|
||||
{
|
||||
//
|
||||
// Setup widgets
|
||||
//
|
||||
actions_init();
|
||||
|
||||
resize(1300, 800);
|
||||
setWindowTitle("MainWindow");
|
||||
|
||||
@ -32,8 +36,16 @@ MainWindow::MainWindow(): QMainWindow() {
|
||||
const auto menubar = new QMenuBar(this);
|
||||
setMenuBar(menubar);
|
||||
menubar->setGeometry(QRect(0, 0, 1307, 27));
|
||||
|
||||
const auto menubar_new = menubar->addMenu("New");
|
||||
menubar_new->addAction(&action_new_user);
|
||||
menubar_new->addAction(&action_new_computer);
|
||||
menubar_new->addAction(&action_new_group);
|
||||
menubar_new->addAction(&action_new_ou);
|
||||
|
||||
const auto menubar_view = menubar->addMenu("View");
|
||||
menubar_view->addAction(&action_advanced_view);
|
||||
menubar_view->addAction(&action_toggle_dn);
|
||||
|
||||
const auto splitter = new QSplitter(central_widget);
|
||||
splitter->setGeometry(QRect(0, 0, 1301, 591));
|
||||
@ -48,58 +60,28 @@ MainWindow::MainWindow(): QMainWindow() {
|
||||
splitter->addWidget(containers_widget);
|
||||
splitter->addWidget(contents_widget);
|
||||
splitter->addWidget(attributes_widget);
|
||||
|
||||
|
||||
//
|
||||
// Setup actions
|
||||
// Connect actions
|
||||
//
|
||||
const auto action_advanced_view = new QAction("Advanced view", this);
|
||||
action_advanced_view->setCheckable(true);
|
||||
menubar_view->addAction(action_advanced_view);
|
||||
containers_widget->connect_proxy_action(action_advanced_view);
|
||||
contents_widget->connect_proxy_action(action_advanced_view);
|
||||
|
||||
const auto action_toggle_dn = new QAction("Show DN");
|
||||
action_toggle_dn->setCheckable(true);
|
||||
menubar_view->addAction(action_toggle_dn);
|
||||
QObject::connect(
|
||||
action_toggle_dn, &QAction::triggered,
|
||||
containers_widget, &EntryWidget::on_action_toggle_dn);
|
||||
QObject::connect(
|
||||
action_toggle_dn, &QAction::triggered,
|
||||
contents_widget, &EntryWidget::on_action_toggle_dn);
|
||||
|
||||
action_attributes = new QAction("Attributes", this);
|
||||
QObject::connect(
|
||||
action_attributes, &QAction::triggered,
|
||||
&action_attributes, &QAction::triggered,
|
||||
this, &MainWindow::on_action_attributes);
|
||||
|
||||
action_delete_entry = new QAction("Delete", this);
|
||||
QObject::connect(
|
||||
action_delete_entry, &QAction::triggered,
|
||||
&action_delete_entry, &QAction::triggered,
|
||||
this, &MainWindow::on_action_delete_entry);
|
||||
|
||||
// Setup "New X" actions
|
||||
for (int type_i = NewEntryType::User; type_i < NewEntryType::COUNT; type_i++) {
|
||||
NewEntryType type = static_cast<NewEntryType>(type_i);
|
||||
QString text = new_entry_type_to_string[type];
|
||||
QAction *action = new QAction(text, this);
|
||||
|
||||
QObject::connect(action, &QAction::triggered,
|
||||
[type] () {
|
||||
create_entry_dialog(type);
|
||||
});
|
||||
|
||||
new_entry_actions.push_back(action);
|
||||
menubar_new->addAction(action);
|
||||
}
|
||||
|
||||
// Popup context menu from containers and contents widgets
|
||||
QObject::connect(
|
||||
containers_widget, &EntryWidget::context_menu_requested,
|
||||
this, &MainWindow::popup_entry_context_menu);
|
||||
&action_new_user, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_user);
|
||||
QObject::connect(
|
||||
contents_widget, &EntryWidget::context_menu_requested,
|
||||
this, &MainWindow::popup_entry_context_menu);
|
||||
&action_new_computer, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_computer);
|
||||
QObject::connect(
|
||||
&action_new_group, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_group);
|
||||
QObject::connect(
|
||||
&action_new_ou, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_ou);
|
||||
|
||||
// Set root index of contents view to selection of containers view
|
||||
QObject::connect(
|
||||
@ -122,7 +104,7 @@ QString MainWindow::get_selected_dn() const {
|
||||
|
||||
void MainWindow::on_action_attributes() {
|
||||
QString dn = get_selected_dn();
|
||||
attributes_widget->set_target_dn(dn);
|
||||
attributes_widget->change_model_target(dn);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_delete_entry() {
|
||||
@ -130,21 +112,23 @@ void MainWindow::on_action_delete_entry() {
|
||||
delete_entry(dn);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_entry(NewEntryType type) {
|
||||
void MainWindow::on_action_new_entry_generic(NewEntryType type) {
|
||||
QString dn = get_selected_dn();
|
||||
create_entry_dialog(type, dn);
|
||||
}
|
||||
|
||||
void MainWindow::popup_entry_context_menu(const QPoint &pos) {
|
||||
QMenu menu;
|
||||
|
||||
menu.addAction(action_attributes);
|
||||
menu.addAction(action_delete_entry);
|
||||
|
||||
QMenu *submenu_new = menu.addMenu("New");
|
||||
for (auto action : new_entry_actions) {
|
||||
submenu_new->addAction(action);
|
||||
}
|
||||
|
||||
menu.exec(pos, action_attributes);
|
||||
void MainWindow::on_action_new_user() {
|
||||
on_action_new_entry_generic(NewEntryType::User);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_computer() {
|
||||
on_action_new_entry_generic(NewEntryType::Computer);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_group() {
|
||||
on_action_new_entry_generic(NewEntryType::Group);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_ou() {
|
||||
on_action_new_entry_generic(NewEntryType::OU);
|
||||
}
|
||||
|
@ -5,20 +5,12 @@
|
||||
#include "ad_interface.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QList>
|
||||
#include <QPoint>
|
||||
|
||||
class QString;
|
||||
class AdModel;
|
||||
class ContainersWidget;
|
||||
class ContentsWidget;
|
||||
class AttributesWidget;
|
||||
class QAction;
|
||||
class QWidget;
|
||||
class QSplitter;
|
||||
class QMenuBar;
|
||||
class QMenu;
|
||||
class QStatusBar;
|
||||
|
||||
class MainWindow final : public QMainWindow {
|
||||
Q_OBJECT
|
||||
@ -26,21 +18,22 @@ Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow();
|
||||
|
||||
private:
|
||||
QString get_selected_dn() const;
|
||||
private slots:
|
||||
void on_action_attributes();
|
||||
void on_action_delete_entry();
|
||||
void on_action_new_entry(NewEntryType type);
|
||||
void popup_entry_context_menu(const QPoint &pos);
|
||||
void on_action_new_user();
|
||||
void on_action_new_computer();
|
||||
void on_action_new_group();
|
||||
void on_action_new_ou();
|
||||
|
||||
private:
|
||||
QString get_selected_dn() const;
|
||||
void on_action_new_entry_generic(NewEntryType type);
|
||||
|
||||
AdModel *ad_model;
|
||||
ContainersWidget *containers_widget;
|
||||
ContentsWidget *contents_widget;
|
||||
AttributesWidget *attributes_widget;
|
||||
|
||||
QAction *action_attributes;
|
||||
QAction *action_delete_entry;
|
||||
QList<QAction *> new_entry_actions;
|
||||
};
|
||||
|
||||
#endif /* MAIN_WINDOW_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user