1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-25 10:50:13 +03:00

move model/proxy setup into constructors

move signal connecting into widgets/models
change only_show_containers to field
This commit is contained in:
Dmitry Degtyarev 2020-05-21 16:19:00 +04:00
parent 1504ab81da
commit 887bc71d19
12 changed files with 66 additions and 57 deletions

@ -4,16 +4,17 @@
#include <QAction>
AdFilter::AdFilter(const QAction * const advanced_view_action, bool only_show_containers) {
this->only_show_containers = only_show_containers;
AdFilter::AdFilter(AdModel *model, QAction *advanced_view_toggle) {
this->setSourceModel(model);
connect(advanced_view_toggle, &QAction::toggled,
this, &AdFilter::on_advanced_view_toggled);
}
void AdFilter::on_advanced_view_toggled(bool checked) {
// On advanced view toggle, copy advanced view flag and invalidate filter
connect(advanced_view_action, &QAction::toggled,
[this](bool checked)
{
this->advanced_view = checked;
this->invalidateFilter();
});
advanced_view = checked;
this->invalidateFilter();
}
bool AdFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {

@ -13,13 +13,18 @@ class AdModel;
// Connected to advanced view toggle in menubar
class AdFilter : public QSortFilterProxyModel {
public:
explicit AdFilter(const QAction * const advanced_view_action, bool only_show_containers = false);
explicit AdFilter(AdModel *model, QAction *advanced_view_toggle);
bool only_show_containers;
private slots:
void on_advanced_view_toggled(bool checked);
private:
bool advanced_view = false;
bool only_show_containers;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};
#endif /* AD_FILTER_H */

@ -120,6 +120,19 @@ AdModel::AdModel(): QStandardItemModel(0, Column::COUNT) {
QStandardItem *invis_root = this->invisibleRootItem();
auto head_dn = QString(HEAD_DN);
load_and_add_row(invis_root, head_dn);
QObject::connect(
&ad_interface, &AdInterface::entry_deleted,
this, &AdModel::on_entry_deleted);
QObject::connect(
&ad_interface, &AdInterface::entry_changed,
this, &AdModel::on_entry_changed);
QObject::connect(
&ad_interface, &AdInterface::user_moved,
this, &AdModel::on_user_moved);
QObject::connect(
&ad_interface, &AdInterface::entry_created,
this, &AdModel::on_entry_created);
}
bool AdModel::canFetchMore(const QModelIndex &parent) const {

@ -28,7 +28,7 @@ public:
void fetchMore(const QModelIndex &parent);
bool hasChildren(const QModelIndex &parent) const override;
public slots:
private slots:
void on_entry_changed(const QString &dn);
void on_entry_deleted(const QString &dn);
void on_user_moved(const QString &old_dn, const QString &new_dn, const QString &new_parent_dn);

@ -15,7 +15,7 @@ class AttributesList : public QObject {
Q_OBJECT
public:
explicit AttributesList(QTreeView *view);
AttributesList(QTreeView *view);
AttributesModel model;

@ -5,6 +5,10 @@
AttributesModel::AttributesModel(): QStandardItemModel(0, Column::COUNT) {
change_target(QString(""));
QObject::connect(
&ad_interface, &AdInterface::entry_deleted,
this, &AttributesModel::on_entry_deleted);
}
// This will be called when an attribute value is edited

@ -22,7 +22,7 @@ public:
signals:
void entry_changed(const QString &dn);
public slots:
private slots:
void on_entry_deleted(const QString &dn);
private:

@ -1,14 +1,17 @@
#include "containers_tree.h"
#include "ad_filter.h"
#include "ad_model.h"
#include <QTreeView>
ContainersTree::ContainersTree(QTreeView *view, AdFilter *proxy) {
ContainersTree::ContainersTree(QTreeView *view, AdModel *model, QAction *advanced_view_toggle):
proxy(model, advanced_view_toggle)
{
this->view = view;
view->setModel(proxy);
proxy.only_show_containers = true;
view->setModel(&proxy);
view->hideColumn(AdModel::Column::Category);
view->hideColumn(AdModel::Column::Description);
view->hideColumn(AdModel::Column::DN);

@ -2,17 +2,21 @@
#ifndef CONTAINERS_VIEW_H
#define CONTAINERS_VIEW_H
#include "ad_filter.h"
class QTreeView;
class AdFilter;
class AdModel;
class QAction;
// Shows names of AdModel as a tree
class ContainersTree {
public:
ContainersTree(QTreeView *view, AdFilter *proxy);
ContainersTree(QTreeView *view, AdModel *model, QAction *advanced_view_toggle);
private:
QTreeView *view;
AdFilter proxy;
};

@ -1,8 +1,8 @@
#include "contents_list.h"
#include "ad_interface.h"
#include "ad_filter.h"
#include "ad_model.h"
#include "ad_filter.h"
#include <QApplication>
#include <QItemSelection>
@ -12,10 +12,13 @@
#include <QMimeData>
#include <QTreeView>
ContentsList::ContentsList(QTreeView *view, AdFilter *proxy): QWidget() {
ContentsList::ContentsList(QTreeView *view, AdModel* model, QAction *advanced_view_toggle) :
QWidget(),
proxy(model, advanced_view_toggle)
{
this->view = view;
view->setModel(proxy);
view->setModel(&proxy);
view->hideColumn(AdModel::Column::DN);
};
@ -65,7 +68,7 @@ void ContentsList::set_root_index_from_selection(const QItemSelection &selected,
// probably from dragging being started incorrectly
void ContentsList::mousePressEvent(QMouseEvent *event) {
// view->mousePressEvent(event);
// Record drag position
if (event->button() == Qt::LeftButton) {
drag_start_position = event->pos();
@ -74,7 +77,7 @@ void ContentsList::mousePressEvent(QMouseEvent *event) {
void ContentsList::mouseMoveEvent(QMouseEvent *event) {
// view->mouseMoveEvent(event);
// Start drag event if holding left mouse button and dragged far enough
bool holding_left_button = event->buttons() & Qt::LeftButton;
@ -112,7 +115,7 @@ void ContentsList::mouseMoveEvent(QMouseEvent *event) {
void ContentsList::dragEnterEvent(QDragEnterEvent *event) {
// view->dragEnterEvent(event);
// TODO: is this needed?
if (event->mimeData()->hasText()) {
event->acceptProposedAction();
@ -131,7 +134,7 @@ void ContentsList::dragMoveEvent(QDragMoveEvent *event) {
// This only changes the drag icon
// view->dragMoveEvent(event);
QPoint pos = event->pos();
QModelIndex index = view->indexAt(pos);
QModelIndex category_index = index.siblingAtColumn(AdModel::Column::Category);

@ -2,10 +2,13 @@
#ifndef CONTENTS_VIEW_H
#define CONTENTS_VIEW_H
#include "ad_filter.h"
#include <QWidget>
class QTreeView;
class AdFilter;
class AdModel;
class QAction;
class QItemSelection;
// Shows name, category and description of children of entry selected in containers view
@ -13,7 +16,7 @@ class ContentsList : public QWidget {
Q_OBJECT
public:
explicit ContentsList(QTreeView *view, AdFilter *proxy);
ContentsList(QTreeView *view, AdModel *model, QAction *advanced_view);
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
@ -27,6 +30,7 @@ public slots:
private:
QPoint drag_start_position;
QTreeView *view;
AdFilter proxy;
};
#endif /* CONTENTS_VIEW_H */

@ -35,22 +35,11 @@ int main(int argc, char **argv) {
AdModel ad_model;
// Attributes
ContainersTree containers_tree(ui.containers_view, &ad_model, ui.menubar_view_advancedView);
ContentsList contents_list(ui.contents_view, &ad_model, ui.menubar_view_advancedView);
AttributesList attributes_view(ui.attributes_view);
// Containers
AdFilter containers_proxy(ui.menubar_view_advancedView, true);
containers_proxy.setSourceModel(&ad_model);
ContainersTree containers_tree(ui.containers_view, &containers_proxy);
// Contents
AdFilter contents_proxy(ui.menubar_view_advancedView);
contents_proxy.setSourceModel(&ad_model);
ContentsList contents_list(ui.contents_view, &containers_proxy);
//
// Entry context menu
//
{
auto entry_context_menu = new EntryContextMenu(&main_window);
@ -70,23 +59,6 @@ int main(int argc, char **argv) {
delete_entry);
}
// Connect signals to update models on when entries are modified
QObject::connect(
&ad_interface, &AdInterface::entry_deleted,
&ad_model, &AdModel::on_entry_deleted);
QObject::connect(
&ad_interface, &AdInterface::entry_deleted,
&attributes_view.model, &AttributesModel::on_entry_deleted);
QObject::connect(
&ad_interface, &AdInterface::entry_changed,
&ad_model, &AdModel::on_entry_changed);
QObject::connect(
&ad_interface, &AdInterface::user_moved,
&ad_model, &AdModel::on_user_moved);
QObject::connect(
&ad_interface, &AdInterface::entry_created,
&ad_model, &AdModel::on_entry_created);
// Set root index of contents view to selection of containers view
QObject::connect(
ui.containers_view->selectionModel(), &QItemSelectionModel::selectionChanged,