From 7a512eca0b7c7d0ff96db88248bafd2e4ff98c0b Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 14 Feb 2019 00:21:57 +0300 Subject: [PATCH] Property filter has been added --- limereport/lrreportdesignwindow.cpp | 28 +++++++++++++++++-- limereport/lrreportdesignwindow.h | 10 ++++++- .../lrobjectinspectorwidget.cpp | 2 +- .../objectinspector/lrobjectitemmodel.cpp | 2 ++ .../objectinspector/lrpropertydelegate.cpp | 4 +-- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index a6524c9..8a795f3 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "lrreportdesignwindow.h" #include "lrbandsmanager.h" @@ -504,13 +506,23 @@ void ReportDesignWindow::createObjectInspector() m_validator = new ObjectNameValidator(); m_propertyModel->setValidator(m_validator); m_propertyModel->setSubclassesAsLevel(false); -// connect(m_propertyModel,SIGNAL(objectPropetyChanged(QString,QVariant,QVariant)),this,SLOT(slotItemDataChanged(QString,QVariant,QVariant))); - m_objectInspector->setModel(m_propertyModel); + 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->setAlternatingRowColors(true); m_objectInspector->setRootIsDecorated(!m_propertyModel->subclassesAsLevel()); QDockWidget *objectDoc = new QDockWidget(this); QWidget* w = new QWidget(objectDoc); QVBoxLayout* l = new QVBoxLayout(w); + QLineEdit* le = new QLineEdit(w); + le->setPlaceholderText(tr("Filter")); + connect(le, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterTextChanged(const QString&))); +// QHBoxLayout* h = new QHBoxLayout(w); +// h->addWidget(new QLabel(tr("Filter"))); +// h->addWidget(le); + l->addWidget(le); l->addWidget(m_objectInspector); l->setContentsMargins(2,2,2,2); w->setLayout(l); @@ -1470,6 +1482,11 @@ void ReportDesignWindow::slotPageDeleted() m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); } +void ReportDesignWindow::slotFilterTextChanged(const QString& filter) +{ + m_filterModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::FixedString)); +} + #ifdef HAVE_QTDESIGNER_INTEGRATION void ReportDesignWindow::slotDeleteDialog() { @@ -1541,5 +1558,12 @@ 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 e7cd514..f3bf87e 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -120,6 +120,7 @@ private slots: void slotLoadRecentFile(const QString fileName); void slotPageAdded(PageDesignIntf* ); void slotPageDeleted(); + void slotFilterTextChanged(const QString& filter); #ifdef HAVE_QTDESIGNER_INTEGRATION void slotDeleteDialog(); void slotAddNewDialog(); @@ -273,12 +274,19 @@ private: bool m_reportItemIsLocked; QMap m_leftDocVisibleState; QMap m_rightDocVisibleState; - + QSortFilterProxyModel* m_filterModel; }; 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 325ec1e..81de3e9 100644 --- a/limereport/objectinspector/lrobjectinspectorwidget.cpp +++ b/limereport/objectinspector/lrobjectinspectorwidget.cpp @@ -134,7 +134,7 @@ void ObjectInspectorWidget::reset() ObjectPropItem * ObjectInspectorWidget::nodeFromIndex(QModelIndex index) const { - return static_cast(index.internalPointer()); + return qvariant_cast(index.data(Qt::UserRole)); } void ObjectInspectorWidget::keyPressEvent(QKeyEvent *event) diff --git a/limereport/objectinspector/lrobjectitemmodel.cpp b/limereport/objectinspector/lrobjectitemmodel.cpp index 22d147a..b4d429c 100644 --- a/limereport/objectinspector/lrobjectitemmodel.cpp +++ b/limereport/objectinspector/lrobjectitemmodel.cpp @@ -303,6 +303,8 @@ QVariant QObjectPropertyModel::data(const QModelIndex &index, int role) const return node->iconValue(); }else return QIcon(); break; + case Qt::UserRole: + return QVariant::fromValue(node); default: return QVariant(); } diff --git a/limereport/objectinspector/lrpropertydelegate.cpp b/limereport/objectinspector/lrpropertydelegate.cpp index acb9c20..5270200 100644 --- a/limereport/objectinspector/lrpropertydelegate.cpp +++ b/limereport/objectinspector/lrpropertydelegate.cpp @@ -51,7 +51,7 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - LimeReport::ObjectPropItem *node = static_cast(index.internalPointer()); + LimeReport::ObjectPropItem *node = qvariant_cast(index.data(Qt::UserRole)); if (node){ if (!node->isHaveValue()){ if (index.column()==0) { @@ -137,7 +137,7 @@ QSize LimeReport::PropertyDelegate::sizeHint(const QStyleOptionViewItem &option, QWidget * LimeReport::PropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { - m_editingItem=static_cast(index.internalPointer()); + m_editingItem = qvariant_cast(index.data(Qt::UserRole)); connect(m_editingItem,SIGNAL(destroyed(QObject*)), this, SLOT(slotItemDeleted(QObject*))); QWidget *editor=m_editingItem->createProperyEditor(parent); if (editor){