Property filter has been added

This commit is contained in:
Arin Alexander 2019-02-14 00:21:57 +03:00
parent 47ae56ab26
commit 7a512eca0b
5 changed files with 40 additions and 6 deletions

View File

@ -40,6 +40,8 @@
#include <QCheckBox> #include <QCheckBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QSortFilterProxyModel>
#include <QLineEdit>
#include "lrreportdesignwindow.h" #include "lrreportdesignwindow.h"
#include "lrbandsmanager.h" #include "lrbandsmanager.h"
@ -504,13 +506,23 @@ void ReportDesignWindow::createObjectInspector()
m_validator = new ObjectNameValidator(); m_validator = new ObjectNameValidator();
m_propertyModel->setValidator(m_validator); m_propertyModel->setValidator(m_validator);
m_propertyModel->setSubclassesAsLevel(false); m_propertyModel->setSubclassesAsLevel(false);
// connect(m_propertyModel,SIGNAL(objectPropetyChanged(QString,QVariant,QVariant)),this,SLOT(slotItemDataChanged(QString,QVariant,QVariant))); m_filterModel = new PropertyFilterModel(this);
m_objectInspector->setModel(m_propertyModel); 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->setAlternatingRowColors(true);
m_objectInspector->setRootIsDecorated(!m_propertyModel->subclassesAsLevel()); m_objectInspector->setRootIsDecorated(!m_propertyModel->subclassesAsLevel());
QDockWidget *objectDoc = new QDockWidget(this); QDockWidget *objectDoc = new QDockWidget(this);
QWidget* w = new QWidget(objectDoc); QWidget* w = new QWidget(objectDoc);
QVBoxLayout* l = new QVBoxLayout(w); 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->addWidget(m_objectInspector);
l->setContentsMargins(2,2,2,2); l->setContentsMargins(2,2,2,2);
w->setLayout(l); w->setLayout(l);
@ -1470,6 +1482,11 @@ void ReportDesignWindow::slotPageDeleted()
m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); 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 #ifdef HAVE_QTDESIGNER_INTEGRATION
void ReportDesignWindow::slotDeleteDialog() void ReportDesignWindow::slotDeleteDialog()
{ {
@ -1541,5 +1558,12 @@ bool ObjectNameValidator::validate(const QString &propName, const QVariant &prop
return true; 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());
}
} }

View File

@ -120,6 +120,7 @@ private slots:
void slotLoadRecentFile(const QString fileName); void slotLoadRecentFile(const QString fileName);
void slotPageAdded(PageDesignIntf* ); void slotPageAdded(PageDesignIntf* );
void slotPageDeleted(); void slotPageDeleted();
void slotFilterTextChanged(const QString& filter);
#ifdef HAVE_QTDESIGNER_INTEGRATION #ifdef HAVE_QTDESIGNER_INTEGRATION
void slotDeleteDialog(); void slotDeleteDialog();
void slotAddNewDialog(); void slotAddNewDialog();
@ -273,12 +274,19 @@ private:
bool m_reportItemIsLocked; bool m_reportItemIsLocked;
QMap<QDockWidget*, bool> m_leftDocVisibleState; QMap<QDockWidget*, bool> m_leftDocVisibleState;
QMap<QDockWidget*, bool> m_rightDocVisibleState; QMap<QDockWidget*, bool> m_rightDocVisibleState;
QSortFilterProxyModel* m_filterModel;
}; };
class ObjectNameValidator : public ValidatorIntf{ class ObjectNameValidator : public ValidatorIntf{
bool validate(const QString &propName, const QVariant &propValue, QObject *object, QString &msg); 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 #endif // LRREPORTEDITORWINDOW_H

View File

@ -134,7 +134,7 @@ void ObjectInspectorWidget::reset()
ObjectPropItem * ObjectInspectorWidget::nodeFromIndex(QModelIndex index) const ObjectPropItem * ObjectInspectorWidget::nodeFromIndex(QModelIndex index) const
{ {
return static_cast<LimeReport::ObjectPropItem*>(index.internalPointer()); return qvariant_cast<LimeReport::ObjectPropItem*>(index.data(Qt::UserRole));
} }
void ObjectInspectorWidget::keyPressEvent(QKeyEvent *event) void ObjectInspectorWidget::keyPressEvent(QKeyEvent *event)

View File

@ -303,6 +303,8 @@ QVariant QObjectPropertyModel::data(const QModelIndex &index, int role) const
return node->iconValue(); return node->iconValue();
}else return QIcon(); }else return QIcon();
break; break;
case Qt::UserRole:
return QVariant::fromValue(node);
default: default:
return QVariant(); return QVariant();
} }

View File

@ -51,7 +51,7 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
LimeReport::ObjectPropItem *node = static_cast<LimeReport::ObjectPropItem*>(index.internalPointer()); LimeReport::ObjectPropItem *node = qvariant_cast<LimeReport::ObjectPropItem*>(index.data(Qt::UserRole));
if (node){ if (node){
if (!node->isHaveValue()){ if (!node->isHaveValue()){
if (index.column()==0) { 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 QWidget * LimeReport::PropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
m_editingItem=static_cast<LimeReport::ObjectPropItem*>(index.internalPointer()); m_editingItem = qvariant_cast<LimeReport::ObjectPropItem*>(index.data(Qt::UserRole));
connect(m_editingItem,SIGNAL(destroyed(QObject*)), this, SLOT(slotItemDeleted(QObject*))); connect(m_editingItem,SIGNAL(destroyed(QObject*)), this, SLOT(slotItemDeleted(QObject*)));
QWidget *editor=m_editingItem->createProperyEditor(parent); QWidget *editor=m_editingItem->createProperyEditor(parent);
if (editor){ if (editor){