From 4208b98f4a2596105e2db1450cab536989917fc2 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 14 Feb 2019 20:50:01 +0300 Subject: [PATCH] ObjectInspector has been wrapped by QWidget --- limereport/lrreportdesignwindow.cpp | 64 +++----- limereport/lrreportdesignwindow.h | 9 +- .../lrobjectinspectorwidget.cpp | 139 ++++++++++++++++-- .../objectinspector/lrobjectinspectorwidget.h | 43 +++++- .../objectinspector/lrpropertydelegate.cpp | 2 +- .../objectinspector/lrpropertydelegate.h | 6 +- 6 files changed, 195 insertions(+), 68 deletions(-) diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index 607af45..be7cb77 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -503,31 +503,16 @@ void ReportDesignWindow::initReportEditor(ReportEnginePrivateInterface* report) void ReportDesignWindow::createObjectInspector() { m_objectInspector = new ObjectInspectorWidget(this); - m_propertyModel = new BaseDesignPropertyModel(this); + //m_propertyModel = new BaseDesignPropertyModel(this); m_validator = new ObjectNameValidator(); - m_propertyModel->setValidator(m_validator); - m_propertyModel->setSubclassesAsLevel(false); - m_filterModel = new PropertyFilterModel(this); - m_filterModel->setSourceModel(m_propertyModel); - m_filterModel->setFilterRegExp(QRegExp("", Qt::CaseInsensitive, QRegExp::FixedString)); - m_filterModel->setRecursiveFilteringEnabled(false); - m_objectInspector->setModel(m_filterModel); + m_objectInspector->setValidator(m_validator); + m_objectInspector->setSubclassesAsLevel(false); + //m_objectInspector->setModel(m_propertyModel); m_objectInspector->setAlternatingRowColors(true); - m_objectInspector->setRootIsDecorated(!m_propertyModel->subclassesAsLevel()); + m_objectInspector->setRootIsDecorated(!m_objectInspector->subclassesAsLevel()); QDockWidget *objectDoc = new QDockWidget(this); QWidget* w = new QWidget(objectDoc); QVBoxLayout* l = new QVBoxLayout(w); - QLineEdit* le = new QLineEdit(w); - QPushButton * pbClear = new QPushButton(QIcon(":/items/clear.png"),"",w); - pbClear->setToolTip(tr("Clear")); - connect(pbClear, SIGNAL(clicked()), le, SLOT(clear())); - le->setPlaceholderText(tr("Filter")); - connect(le, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterTextChanged(const QString&))); - QHBoxLayout* h = new QHBoxLayout(); - h->setSpacing(2); - h->addWidget(le); - h->addWidget(pbClear); - l->addLayout(h); l->addWidget(m_objectInspector); l->setContentsMargins(2,2,2,2); w->setLayout(l); @@ -707,11 +692,11 @@ void ReportDesignWindow::writeState() setDocWidgetsVisibility(true); m_editorsStates[m_editorTabType] = saveState(); - settings()->setValue("PageEditorsState", m_editorsStates[ReportDesignWidget::Page]); - settings()->setValue("DialogEditorsState", m_editorsStates[ReportDesignWidget::Dialog]); - settings()->setValue("ScriptEditorsState", m_editorsStates[ReportDesignWidget::Script]); - settings()->setValue("TranslationEditorsState", m_editorsStates[ReportDesignWidget::Translations]); - settings()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0)); + settings()->setValue("PageEditorsState", m_editorsStates[ReportDesignWidget::Page]); + settings()->setValue("DialogEditorsState", m_editorsStates[ReportDesignWidget::Dialog]); + settings()->setValue("ScriptEditorsState", m_editorsStates[ReportDesignWidget::Script]); + settings()->setValue("TranslationEditorsState", m_editorsStates[ReportDesignWidget::Translations]); + settings()->setValue("InspectorFirsColumnWidth", m_objectInspector->columnWidth(0)); settings()->endGroup(); settings()->beginGroup("RecentFiles"); settings()->setValue("filesCount",m_recentFiles.count()); @@ -950,7 +935,7 @@ void ReportDesignWindow::slotNewBand(int bandType) void ReportDesignWindow::slotItemSelected(LimeReport::BaseDesignIntf *item) { - if (m_propertyModel->currentObject()!=item){ + if (m_objectInspector->currentObject()!=item){ m_newSubDetail->setEnabled(false); m_newSubDetailHeader->setEnabled(false); @@ -961,9 +946,9 @@ void ReportDesignWindow::slotItemSelected(LimeReport::BaseDesignIntf *item) m_newDataFooter->setEnabled(false); m_objectInspector->commitActiveEditorData(); - m_propertyModel->setObject(item); + m_objectInspector->setObject(item); - if (m_propertyModel->subclassesAsLevel()) + if (m_objectInspector->subclassesAsLevel()) m_objectInspector->expandToDepth(0); QSet bs; @@ -997,7 +982,7 @@ void ReportDesignWindow::slotItemSelected(LimeReport::BaseDesignIntf *item) m_fontEditorBar->setItem(item); m_textAlignmentEditorBar->setItem(item); m_itemsBordersEditorBar->setItem(item); - } else {m_propertyModel->clearObjectsList();} + } else {m_objectInspector->clearObjectsList();} } void ReportDesignWindow::slotItemPropertyChanged(const QString &objectName, const QString &propertyName, const QVariant& oldValue, const QVariant& newValue ) @@ -1005,8 +990,8 @@ void ReportDesignWindow::slotItemPropertyChanged(const QString &objectName, cons Q_UNUSED(oldValue) Q_UNUSED(newValue) - if (m_propertyModel->currentObject()&&(m_propertyModel->currentObject()->objectName()==objectName)){ - m_propertyModel->updateProperty(propertyName); + if (m_objectInspector->currentObject()&&(m_objectInspector->currentObject()->objectName()==objectName)){ + m_objectInspector->updateProperty(propertyName); } } @@ -1019,8 +1004,8 @@ void ReportDesignWindow::slotMultiItemSelected() QObject* oi = dynamic_cast(gi); if (oi) selectionList.append(oi); } - m_propertyModel->setMultiObjects(&selectionList); - if (m_propertyModel->subclassesAsLevel()) + m_objectInspector->setMultiObjects(&selectionList); + if (m_objectInspector->subclassesAsLevel()) m_objectInspector->expandToDepth(0); } @@ -1112,7 +1097,7 @@ void ReportDesignWindow::slotLoadReport() m_reportDesignWidget->clear(); if (m_reportDesignWidget->loadFromFile(fileName)){ m_lblReportName->setText(fileName); - m_propertyModel->setObject(0); + m_objectInspector->setObject(0); updateRedoUndo(); setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); if (!m_recentFiles.contains(fileName)){ @@ -1336,7 +1321,7 @@ void ReportDesignWindow::showDefaultEditors(){ void ReportDesignWindow::slotActivePageChanged() { - m_propertyModel->setObject(0); + m_objectInspector->setObject(0); updateRedoUndo(); updateAvaibleBands(); @@ -1464,7 +1449,7 @@ void ReportDesignWindow::slotLoadRecentFile(const QString fileName) m_reportDesignWidget->clear(); m_reportDesignWidget->loadFromFile(fileName); m_lblReportName->setText(fileName); - m_propertyModel->setObject(0); + m_objectInspector->setObject(0); updateRedoUndo(); unsetCursor(); setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); @@ -1563,12 +1548,5 @@ bool ObjectNameValidator::validate(const QString &propName, const QVariant &prop return true; } -bool PropertyFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const -{ - QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - if (sourceParent.isValid()) return true; - return sourceModel()->data(index).toString().contains(filterRegExp()); -} - } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index f3bf87e..18df464 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -238,7 +238,7 @@ private: QSignalMapper* m_recentFilesSignalMap; ObjectInspectorWidget* m_objectInspector; - QObjectPropertyModel* m_propertyModel; + //QObjectPropertyModel* m_propertyModel; ReportDesignWidget* m_reportDesignWidget; DataBrowser * m_dataBrowser; @@ -281,12 +281,5 @@ class ObjectNameValidator : public ValidatorIntf{ bool validate(const QString &propName, const QVariant &propValue, QObject *object, QString &msg); }; - -class PropertyFilterModel: public QSortFilterProxyModel{ -public: - PropertyFilterModel(QObject* parent = 0): QSortFilterProxyModel(parent){} -protected: - bool filterAcceptsRow(int sourceRow,const QModelIndex &sourceParent) const; -}; } #endif // LRREPORTEDITORWINDOW_H diff --git a/limereport/objectinspector/lrobjectinspectorwidget.cpp b/limereport/objectinspector/lrobjectinspectorwidget.cpp index 81de3e9..4ca3fff 100644 --- a/limereport/objectinspector/lrobjectinspectorwidget.cpp +++ b/limereport/objectinspector/lrobjectinspectorwidget.cpp @@ -30,6 +30,10 @@ #include #include #include +#include +#include +#include +#include #include "lrglobal.h" #include "lrobjectinspectorwidget.h" @@ -37,7 +41,7 @@ namespace LimeReport{ -ObjectInspectorWidget::ObjectInspectorWidget(QWidget *parent) +ObjectInspectorTreeView::ObjectInspectorTreeView(QWidget *parent) :QTreeView(parent), m_propertyDelegate(0) { setRootIsDecorated(false); @@ -54,9 +58,9 @@ ObjectInspectorWidget::ObjectInspectorWidget(QWidget *parent) setPalette(p); } -ObjectInspectorWidget::~ObjectInspectorWidget(){} +ObjectInspectorTreeView::~ObjectInspectorTreeView(){} -void ObjectInspectorWidget::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const +void ObjectInspectorTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const { ObjectPropItem *node = nodeFromIndex(index); StyleOptionViewItem so = options; @@ -84,7 +88,7 @@ void ObjectInspectorWidget::drawRow(QPainter *painter, const QStyleOptionViewIte painter->restore(); } -void ObjectInspectorWidget::mousePressEvent(QMouseEvent *event) +void ObjectInspectorTreeView::mousePressEvent(QMouseEvent *event) { if ((event->button()==Qt::LeftButton)){ @@ -106,7 +110,7 @@ void ObjectInspectorWidget::mousePressEvent(QMouseEvent *event) QTreeView::mousePressEvent(event); } -void ObjectInspectorWidget::initColorMap() +void ObjectInspectorTreeView::initColorMap() { m_colors.reserve(6); m_colors.push_back(QColor(255,230,191)); @@ -117,12 +121,12 @@ void ObjectInspectorWidget::initColorMap() m_colors.push_back(QColor(255,191,239)); } -QColor ObjectInspectorWidget::getColor(const int index) const +QColor ObjectInspectorTreeView::getColor(const int index) const { return m_colors[index]; } -void ObjectInspectorWidget::reset() +void ObjectInspectorTreeView::reset() { QTreeView::reset(); for (int i=0;irowCount();i++){ @@ -132,12 +136,12 @@ void ObjectInspectorWidget::reset() } } -ObjectPropItem * ObjectInspectorWidget::nodeFromIndex(QModelIndex index) const +ObjectPropItem * ObjectInspectorTreeView::nodeFromIndex(QModelIndex index) const { return qvariant_cast(index.data(Qt::UserRole)); } -void ObjectInspectorWidget::keyPressEvent(QKeyEvent *event) +void ObjectInspectorTreeView::keyPressEvent(QKeyEvent *event) { if (event->key()==Qt::Key_Return){ if(!m_propertyDelegate->isEditing()){ @@ -149,10 +153,125 @@ void ObjectInspectorWidget::keyPressEvent(QKeyEvent *event) } else QTreeView::keyPressEvent(event); } -void ObjectInspectorWidget::commitActiveEditorData(){ +void ObjectInspectorTreeView::commitActiveEditorData(){ if (state()==QAbstractItemView::EditingState){ commitData(indexWidget(currentIndex())); } } +bool PropertyFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + if (sourceParent.isValid()) return true; + return sourceModel()->data(index).toString().contains(filterRegExp()); +} + +ObjectInspectorWidget::ObjectInspectorWidget(QWidget *parent) + :QWidget(parent), m_filterModel(0) +{ + m_objectInspectorView = new ObjectInspectorTreeView(this); + m_propertyModel = new BaseDesignPropertyModel(this); + m_filterModel = new PropertyFilterModel(this); + m_filterModel->setSourceModel(m_propertyModel); + m_filterModel->setFilterRegExp(QRegExp("", Qt::CaseInsensitive, QRegExp::FixedString)); + m_objectInspectorView->setModel(m_filterModel); + QVBoxLayout* l = new QVBoxLayout(); + QLineEdit* le = new QLineEdit(this); + QPushButton * pbClear = new QPushButton(QIcon(":/items/clear.png"),"",this); + pbClear->setToolTip(tr("Clear")); + connect(pbClear, SIGNAL(clicked()), le, SLOT(clear())); + le->setPlaceholderText(tr("Filter")); + connect(le, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterTextChanged(const QString&))); + QHBoxLayout* h = new QHBoxLayout(); + h->setSpacing(2); + h->addWidget(le); + h->addWidget(pbClear); + l->addLayout(h); + l->addWidget(m_objectInspectorView); + l->setContentsMargins(2,2,2,2); + this->setLayout(l); +} + +void ObjectInspectorWidget::setModel(QAbstractItemModel *model) +{ + + m_filterModel->setSourceModel(model); + +} + +void ObjectInspectorWidget::setAlternatingRowColors(bool value) +{ + m_objectInspectorView->setAlternatingRowColors(value); +} + +void ObjectInspectorWidget::setRootIsDecorated(bool value) +{ + m_objectInspectorView->setRootIsDecorated(value); +} + +void ObjectInspectorWidget::setColumnWidth(int column, int width) +{ + m_objectInspectorView->setColumnWidth(column, width); +} + +int ObjectInspectorWidget::columnWidth(int column) +{ + return m_objectInspectorView->columnWidth(column); +} + +void ObjectInspectorWidget::expandToDepth(int depth) +{ + m_objectInspectorView->expandToDepth(depth); +} + +void ObjectInspectorWidget::commitActiveEditorData() +{ + m_objectInspectorView->commitActiveEditorData(); +} + +void ObjectInspectorWidget::setValidator(ValidatorIntf *validator) +{ + m_propertyModel->setValidator(validator); +} + +bool ObjectInspectorWidget::subclassesAsLevel() +{ + return m_propertyModel->subclassesAsLevel(); +} + +void ObjectInspectorWidget::setSubclassesAsLevel(bool value) +{ + m_propertyModel->setSubclassesAsLevel(value); +} + +const QObject *ObjectInspectorWidget::currentObject(){ + return m_propertyModel->currentObject(); +} + +void ObjectInspectorWidget::setObject(QObject *object) +{ + m_propertyModel->setObject(object); +} + +void ObjectInspectorWidget::setMultiObjects(QList *list) +{ + m_propertyModel->setMultiObjects(list); +} + +void ObjectInspectorWidget::clearObjectsList() +{ + m_propertyModel->clearObjectsList(); +} + +void ObjectInspectorWidget::updateProperty(const QString &propertyName) +{ + m_propertyModel->updateProperty(propertyName); +} + +void ObjectInspectorWidget::slotFilterTextChanged(const QString &filter) +{ + if (m_filterModel) + m_filterModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::FixedString)); +} + } //namespace LimeReport diff --git a/limereport/objectinspector/lrobjectinspectorwidget.h b/limereport/objectinspector/lrobjectinspectorwidget.h index d6e4495..fcb0c48 100644 --- a/limereport/objectinspector/lrobjectinspectorwidget.h +++ b/limereport/objectinspector/lrobjectinspectorwidget.h @@ -32,17 +32,20 @@ #include #include +#include + #include "lrobjectitemmodel.h" +#include "lrbasedesignobjectmodel.h" #include "lrpropertydelegate.h" namespace LimeReport{ -class ObjectInspectorWidget : public QTreeView +class ObjectInspectorTreeView : public QTreeView { Q_OBJECT public: - ObjectInspectorWidget(QWidget * parent=0); - ~ObjectInspectorWidget(); + ObjectInspectorTreeView(QWidget * parent=0); + ~ObjectInspectorTreeView(); QColor getColor(const int index) const; virtual void reset(); virtual void commitActiveEditorData(); @@ -59,6 +62,40 @@ private: PropertyDelegate *m_propertyDelegate; }; +class PropertyFilterModel: public QSortFilterProxyModel{ +public: + PropertyFilterModel(QObject* parent = 0): QSortFilterProxyModel(parent){} +protected: + bool filterAcceptsRow(int sourceRow,const QModelIndex &sourceParent) const; +}; + +class ObjectInspectorWidget: public QWidget{ + Q_OBJECT +public: + ObjectInspectorWidget(QWidget* parent = 0); + void setModel(QAbstractItemModel* model); + void setAlternatingRowColors(bool value); + void setRootIsDecorated(bool value); + void setColumnWidth(int column, int width); + int columnWidth(int column); + void expandToDepth(int depth); + void commitActiveEditorData(); + void setValidator(ValidatorIntf *validator); + bool subclassesAsLevel(); + void setSubclassesAsLevel(bool value); + void setObject(QObject* object); + const QObject* currentObject(); + void setMultiObjects(QList* list); + void clearObjectsList(); + void updateProperty(const QString &propertyName); +private slots: + void slotFilterTextChanged(const QString& filter); +private: + ObjectInspectorTreeView* m_objectInspectorView; + QSortFilterProxyModel* m_filterModel; + BaseDesignPropertyModel* m_propertyModel; +}; + } //namespace LimeReport #endif // LROBJECTINSPECTORWIDGET_H diff --git a/limereport/objectinspector/lrpropertydelegate.cpp b/limereport/objectinspector/lrpropertydelegate.cpp index 5270200..3a67cdc 100644 --- a/limereport/objectinspector/lrpropertydelegate.cpp +++ b/limereport/objectinspector/lrpropertydelegate.cpp @@ -173,7 +173,7 @@ void LimeReport::PropertyDelegate::updateEditorGeometry(QWidget *editor, const Q if (m_editingItem) m_editingItem->updateEditorGeometry(editor,option,index); } -void LimeReport::PropertyDelegate::setObjectInspector(ObjectInspectorWidget* objectInspector) +void LimeReport::PropertyDelegate::setObjectInspector(ObjectInspectorTreeView* objectInspector) { m_objectInspector=objectInspector; } diff --git a/limereport/objectinspector/lrpropertydelegate.h b/limereport/objectinspector/lrpropertydelegate.h index d9d9b66..b64cdae 100644 --- a/limereport/objectinspector/lrpropertydelegate.h +++ b/limereport/objectinspector/lrpropertydelegate.h @@ -39,14 +39,14 @@ namespace LimeReport{ -class ObjectInspectorWidget; +class ObjectInspectorTreeView; //class PropertyDelegate : public QItemDelegate class PropertyDelegate : public QStyledItemDelegate { Q_OBJECT public: PropertyDelegate(QObject *parent=0); - void setObjectInspector(ObjectInspectorWidget* objectInspector); + void setObjectInspector(ObjectInspectorTreeView* objectInspector); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -60,7 +60,7 @@ private slots: void slotEditorDeleted(); void slotItemDeleted(QObject* item); private: - LimeReport::ObjectInspectorWidget* m_objectInspector; + LimeReport::ObjectInspectorTreeView* m_objectInspector; mutable LimeReport::ObjectPropItem* m_editingItem; mutable bool m_isEditing; };