mirror of
https://github.com/altlinux/admc.git
synced 2025-01-18 02:04:36 +03:00
change ui components from inheriting to using
make QTreeView's members and inherit from QWidget instead
This commit is contained in:
parent
8cd2038d46
commit
5f8f668f5d
@ -26,7 +26,7 @@
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="ContainersView" name="containers_view">
|
||||
<widget class="QTreeView" name="containers_view">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
@ -46,7 +46,7 @@
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="ContentsView" name="contents_view">
|
||||
<widget class="QTreeView" name="contents_view">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
@ -75,7 +75,7 @@
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="AttributesView" name="attributes_view">
|
||||
<widget class="QTreeView" name="attributes_view">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
|
||||
</property>
|
||||
@ -163,23 +163,6 @@
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ContainersView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>src/containers_view.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ContentsView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>src/contents_view.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AttributesView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>src/attributes_view.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,21 +1,21 @@
|
||||
|
||||
#include "attributes_view.h"
|
||||
#include "attributes_model.h"
|
||||
#include "ad_model.h"
|
||||
#include "ad_interface.h"
|
||||
|
||||
// TODO: on attribute edit, update entry in ad model
|
||||
// since attributes affect model's contents
|
||||
#include <QWidget>
|
||||
#include <QTreeView>
|
||||
|
||||
AttributesView::AttributesView(QTreeView *view): QObject() {
|
||||
this->view = view;
|
||||
|
||||
view->setModel(&model);
|
||||
};
|
||||
|
||||
void AttributesView::set_target_dn(const QString &new_target_dn) {
|
||||
this->target_dn = new_target_dn;
|
||||
|
||||
// Clear model of previous root
|
||||
// TODO: get rid of cast
|
||||
AttributesModel *model = qobject_cast<AttributesModel *>(this->model());
|
||||
if (model != nullptr) {
|
||||
model->change_target(this->target_dn);
|
||||
}
|
||||
model.change_target(this->target_dn);
|
||||
|
||||
// Populate model with attributes of new root
|
||||
QMap<QString, QList<QString>> attributes = load_attributes(this->target_dn);
|
||||
@ -28,7 +28,7 @@ void AttributesView::set_target_dn(const QString &new_target_dn) {
|
||||
|
||||
name_item->setEditable(false);
|
||||
|
||||
model->appendRow({name_item, value_item});
|
||||
model.appendRow({name_item, value_item});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,22 @@
|
||||
#ifndef ATTRIBUTES_VIEW_H
|
||||
#define ATTRIBUTES_VIEW_H
|
||||
|
||||
#include <QTreeView>
|
||||
#include "attributes_model.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTreeView;
|
||||
class QString;
|
||||
class AttributesModel;
|
||||
|
||||
// Shows names and values of attributes of the entry selected in contents view
|
||||
class AttributesView : public QTreeView {
|
||||
class AttributesView : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using QTreeView::QTreeView;
|
||||
explicit AttributesView(QTreeView *view);
|
||||
|
||||
AttributesModel model;
|
||||
|
||||
public slots:
|
||||
void set_target_dn(const QString &new_target_dn);
|
||||
@ -21,8 +29,8 @@ private:
|
||||
COUNT,
|
||||
};
|
||||
|
||||
QTreeView *view;
|
||||
QString target_dn;
|
||||
|
||||
};
|
||||
|
||||
#endif /* ATTRIBUTES_VIEW_H */
|
||||
|
@ -1,12 +1,15 @@
|
||||
|
||||
#include "containers_view.h"
|
||||
#include "ad_filter.h"
|
||||
#include "ad_model.h"
|
||||
#include "entry_context_menu.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QItemSelection>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QTreeView>
|
||||
|
||||
ContainersView::ContainersView(QWidget *parent) : QTreeView(parent) {
|
||||
ContainersView::ContainersView(QTreeView *view, AdFilter *proxy) {
|
||||
this->view = view;
|
||||
|
||||
view->setModel(proxy);
|
||||
view->hideColumn(AdModel::Column::Category);
|
||||
view->hideColumn(AdModel::Column::Description);
|
||||
view->hideColumn(AdModel::Column::DN);
|
||||
};
|
||||
|
@ -2,20 +2,17 @@
|
||||
#ifndef CONTAINERS_VIEW_H
|
||||
#define CONTAINERS_VIEW_H
|
||||
|
||||
#include <QTreeView>
|
||||
class QTreeView;
|
||||
class AdFilter;
|
||||
|
||||
// Shows names of AdModel as a tree
|
||||
class ContainersView : public QTreeView {
|
||||
Q_OBJECT
|
||||
class ContainersView {
|
||||
|
||||
public:
|
||||
explicit ContainersView(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
ContainersView(QTreeView *view, AdFilter *proxy);
|
||||
|
||||
private:
|
||||
QTreeView *view;
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include "contents_view.h"
|
||||
#include "ad_interface.h"
|
||||
#include "ad_filter.h"
|
||||
#include "ad_model.h"
|
||||
|
||||
#include <QApplication>
|
||||
@ -9,11 +10,19 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QTreeView>
|
||||
|
||||
ContentsView::ContentsView(QTreeView *view, AdFilter *proxy): QWidget() {
|
||||
this->view = view;
|
||||
|
||||
view->setModel(proxy);
|
||||
view->hideColumn(AdModel::Column::DN);
|
||||
};
|
||||
|
||||
// TODO: bake this assumptions into view classes
|
||||
// Both contents and containers share the same source model, but have different proxy's to it
|
||||
// So need to map from containers proxy to source then back to proxy of contents
|
||||
void ContentsView::set_root_index_from_selection(const QItemSelection &selected, const QItemSelection &) {
|
||||
|
||||
const QList<QModelIndex> indexes = selected.indexes();
|
||||
|
||||
if (indexes.size() == 0) {
|
||||
@ -32,21 +41,21 @@ void ContentsView::set_root_index_from_selection(const QItemSelection &selected,
|
||||
// Map from source model of this view to proxy model of this view (if needed)
|
||||
QModelIndex contents_index = source_index;
|
||||
{
|
||||
auto proxy_model = qobject_cast<const QSortFilterProxyModel *>(this->model());
|
||||
auto proxy_model = qobject_cast<const QSortFilterProxyModel *>(view->model());
|
||||
if (proxy_model != nullptr) {
|
||||
contents_index = proxy_model->mapFromSource(contents_index);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->model()->checkIndex(contents_index)) {
|
||||
if (!view->model()->checkIndex(contents_index)) {
|
||||
printf("ContentsView::set_root_index_from_selection received bad index!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
this->setRootIndex(contents_index);
|
||||
view->setRootIndex(contents_index);
|
||||
|
||||
// NOTE: have to hide columns after model update
|
||||
this->hideColumn(AdModel::Column::DN);
|
||||
view->hideColumn(AdModel::Column::DN);
|
||||
}
|
||||
|
||||
// TODO: currently dragging doesn't work correctly most of the time
|
||||
@ -55,16 +64,16 @@ void ContentsView::set_root_index_from_selection(const QItemSelection &selected,
|
||||
// icon is incorrect for example
|
||||
// probably from dragging being started incorrectly
|
||||
void ContentsView::mousePressEvent(QMouseEvent *event) {
|
||||
QTreeView::mousePressEvent(event);
|
||||
// view->mousePressEvent(event);
|
||||
|
||||
// Record drag position
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->drag_start_position = event->pos();
|
||||
drag_start_position = event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
void ContentsView::mouseMoveEvent(QMouseEvent *event) {
|
||||
QTreeView::mouseMoveEvent(event);
|
||||
// view->mouseMoveEvent(event);
|
||||
|
||||
// Start drag event if holding left mouse button and dragged far enough
|
||||
|
||||
@ -73,7 +82,7 @@ void ContentsView::mouseMoveEvent(QMouseEvent *event) {
|
||||
return;
|
||||
}
|
||||
|
||||
int drag_distance = (event->pos() - this->drag_start_position).manhattanLength();
|
||||
int drag_distance = (event->pos() - drag_start_position).manhattanLength();
|
||||
if (drag_distance < QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
@ -85,7 +94,7 @@ void ContentsView::mouseMoveEvent(QMouseEvent *event) {
|
||||
// Figure out if this entry can be dragged
|
||||
// Entry has to be a person
|
||||
QPoint pos = event->pos();
|
||||
QModelIndex index = this->indexAt(pos);
|
||||
QModelIndex index = view->indexAt(pos);
|
||||
QModelIndex category_index = index.siblingAtColumn(AdModel::Column::Category);
|
||||
QString category_text = category_index.data().toString();
|
||||
|
||||
@ -102,7 +111,7 @@ void ContentsView::mouseMoveEvent(QMouseEvent *event) {
|
||||
}
|
||||
|
||||
void ContentsView::dragEnterEvent(QDragEnterEvent *event) {
|
||||
QTreeView::dragEnterEvent(event);
|
||||
// view->dragEnterEvent(event);
|
||||
|
||||
// TODO: is this needed?
|
||||
if (event->mimeData()->hasText()) {
|
||||
@ -121,10 +130,10 @@ void ContentsView::dragMoveEvent(QDragMoveEvent *event) {
|
||||
// hovered entry
|
||||
// This only changes the drag icon
|
||||
|
||||
// QTreeView::dragMoveEvent(event);
|
||||
// view->dragMoveEvent(event);
|
||||
|
||||
QPoint pos = event->pos();
|
||||
QModelIndex index = this->indexAt(pos);
|
||||
QModelIndex index = view->indexAt(pos);
|
||||
QModelIndex category_index = index.siblingAtColumn(AdModel::Column::Category);
|
||||
QString category = category_index.data().toString();
|
||||
|
||||
@ -144,7 +153,7 @@ void ContentsView::dropEvent(QDropEvent *event) {
|
||||
printf("drop\n");
|
||||
|
||||
QPoint pos = event->pos();
|
||||
QModelIndex target_index = this->indexAt(pos);
|
||||
QModelIndex target_index = view->indexAt(pos);
|
||||
QModelIndex target_category_index = target_index.siblingAtColumn(AdModel::Column::Category);
|
||||
QString target_category = target_category_index.data().toString();
|
||||
|
||||
|
@ -2,16 +2,18 @@
|
||||
#ifndef CONTENTS_VIEW_H
|
||||
#define CONTENTS_VIEW_H
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
|
||||
class QPoint;
|
||||
class QTreeView;
|
||||
class AdFilter;
|
||||
class QItemSelection;
|
||||
|
||||
// Shows name, category and description of children of entry selected in containers view
|
||||
class ContentsView : public QTreeView {
|
||||
class ContentsView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using QTreeView::QTreeView;
|
||||
explicit ContentsView(QTreeView *view, AdFilter *proxy);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
@ -24,6 +26,7 @@ public slots:
|
||||
|
||||
private:
|
||||
QPoint drag_start_position;
|
||||
QTreeView *view;
|
||||
};
|
||||
|
||||
#endif /* CONTENTS_VIEW_H */
|
||||
|
38
src/main.cpp
38
src/main.cpp
@ -36,33 +36,17 @@ int main(int argc, char **argv) {
|
||||
AdModel ad_model;
|
||||
|
||||
// Attributes
|
||||
AttributesModel attributes_model;
|
||||
ui.attributes_view->setModel(&attributes_model);
|
||||
|
||||
// Contents
|
||||
{
|
||||
ContentsView *view = ui.contents_view;
|
||||
|
||||
auto proxy = new AdFilter(ui.menubar_view_advancedView);
|
||||
proxy->setSourceModel(&ad_model);
|
||||
view->setModel(proxy);
|
||||
|
||||
view->hideColumn(AdModel::Column::DN);
|
||||
}
|
||||
AttributesView attributes_view(ui.attributes_view);
|
||||
|
||||
// Containers
|
||||
{
|
||||
ContainersView *view = ui.containers_view;
|
||||
AdFilter containers_proxy(ui.menubar_view_advancedView);
|
||||
containers_proxy.setSourceModel(&ad_model);
|
||||
ContainersView containers_view(ui.containers_view, &containers_proxy);
|
||||
|
||||
auto proxy = new AdFilter(ui.menubar_view_advancedView, true);
|
||||
proxy->setSourceModel(&ad_model);
|
||||
view->setModel(proxy);
|
||||
|
||||
// NOTE: have to hide columns after setting model
|
||||
view->hideColumn(AdModel::Column::Category);
|
||||
view->hideColumn(AdModel::Column::Description);
|
||||
view->hideColumn(AdModel::Column::DN);
|
||||
}
|
||||
// Contents
|
||||
AdFilter contents_proxy(ui.menubar_view_advancedView);
|
||||
contents_proxy.setSourceModel(&ad_model);
|
||||
ContentsView contents_view(ui.contents_view, &containers_proxy);
|
||||
|
||||
//
|
||||
// Entry context menu
|
||||
@ -78,7 +62,7 @@ int main(int argc, char **argv) {
|
||||
// entry context menu is clicked
|
||||
QObject::connect(
|
||||
entry_context_menu, &EntryContextMenu::attributes_clicked,
|
||||
ui.attributes_view, &AttributesView::set_target_dn);
|
||||
&attributes_view, &AttributesView::set_target_dn);
|
||||
|
||||
// Delete entry when delete button is pressed
|
||||
QObject::connect(
|
||||
@ -92,7 +76,7 @@ int main(int argc, char **argv) {
|
||||
&ad_model, &AdModel::on_entry_deleted);
|
||||
QObject::connect(
|
||||
&ad_interface, &AdInterface::entry_deleted,
|
||||
&attributes_model, &AttributesModel::on_entry_deleted);
|
||||
&attributes_view.model, &AttributesModel::on_entry_deleted);
|
||||
QObject::connect(
|
||||
&ad_interface, &AdInterface::entry_changed,
|
||||
&ad_model, &AdModel::on_entry_changed);
|
||||
@ -106,7 +90,7 @@ int main(int argc, char **argv) {
|
||||
// Set root index of contents view to selection of containers view
|
||||
QObject::connect(
|
||||
ui.containers_view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
ui.contents_view, &ContentsView::set_root_index_from_selection);
|
||||
&contents_view, &ContentsView::set_root_index_from_selection);
|
||||
|
||||
// Connect menubar "New" submenu's to entry creation dialogs
|
||||
QObject::connect(
|
||||
|
@ -18,10 +18,8 @@
|
||||
#include <QtWidgets/QMenuBar>
|
||||
#include <QtWidgets/QSplitter>
|
||||
#include <QtWidgets/QStatusBar>
|
||||
#include <QtWidgets/QTreeView>
|
||||
#include <QtWidgets/QWidget>
|
||||
#include "src/attributes_view.h"
|
||||
#include "src/containers_view.h"
|
||||
#include "src/contents_view.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -37,9 +35,9 @@ public:
|
||||
QAction *menubar_new_group;
|
||||
QWidget *centralwidget;
|
||||
QSplitter *splitter;
|
||||
ContainersView *containers_view;
|
||||
ContentsView *contents_view;
|
||||
AttributesView *attributes_view;
|
||||
QTreeView *containers_view;
|
||||
QTreeView *contents_view;
|
||||
QTreeView *attributes_view;
|
||||
QMenuBar *menubar;
|
||||
QMenu *menubar_new;
|
||||
QMenu *menuEdit;
|
||||
@ -72,7 +70,7 @@ public:
|
||||
splitter->setObjectName(QString::fromUtf8("splitter"));
|
||||
splitter->setGeometry(QRect(0, 0, 1301, 591));
|
||||
splitter->setOrientation(Qt::Horizontal);
|
||||
containers_view = new ContainersView(splitter);
|
||||
containers_view = new QTreeView(splitter);
|
||||
containers_view->setObjectName(QString::fromUtf8("containers_view"));
|
||||
containers_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
containers_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
@ -81,7 +79,7 @@ public:
|
||||
containers_view->setExpandsOnDoubleClick(true);
|
||||
splitter->addWidget(containers_view);
|
||||
containers_view->header()->setVisible(true);
|
||||
contents_view = new ContentsView(splitter);
|
||||
contents_view = new QTreeView(splitter);
|
||||
contents_view->setObjectName(QString::fromUtf8("contents_view"));
|
||||
contents_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
contents_view->setAcceptDrops(true);
|
||||
@ -93,7 +91,7 @@ public:
|
||||
contents_view->setExpandsOnDoubleClick(false);
|
||||
splitter->addWidget(contents_view);
|
||||
contents_view->header()->setVisible(true);
|
||||
attributes_view = new AttributesView(splitter);
|
||||
attributes_view = new QTreeView(splitter);
|
||||
attributes_view->setObjectName(QString::fromUtf8("attributes_view"));
|
||||
attributes_view->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
|
||||
attributes_view->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
|
Loading…
x
Reference in New Issue
Block a user