ObjectInspector has been wrapped by QWidget

This commit is contained in:
Arin Alexander 2019-02-14 20:50:01 +03:00
parent 5f9ee85dba
commit 4208b98f4a
6 changed files with 195 additions and 68 deletions

View File

@ -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);
@ -711,7 +696,7 @@ void ReportDesignWindow::writeState()
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("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<BandDesignIntf::BandsType> 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<QObject*>(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());
}
}

View File

@ -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

View File

@ -30,6 +30,10 @@
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#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;i<model()->rowCount();i++){
@ -132,12 +136,12 @@ void ObjectInspectorWidget::reset()
}
}
ObjectPropItem * ObjectInspectorWidget::nodeFromIndex(QModelIndex index) const
ObjectPropItem * ObjectInspectorTreeView::nodeFromIndex(QModelIndex index) const
{
return qvariant_cast<LimeReport::ObjectPropItem*>(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<QObject *> *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

View File

@ -32,17 +32,20 @@
#include <QTreeView>
#include <QMap>
#include <QSortFilterProxyModel>
#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<QObject *>* 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

View File

@ -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;
}

View File

@ -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;
};