2016-02-17 10:11:00 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* This file is part of the Lime Report project *
|
2021-08-18 20:21:36 +03:00
|
|
|
* Copyright (C) 2021 by Alexander Arin *
|
2016-02-17 10:11:00 +03:00
|
|
|
* arin_a@bk.ru *
|
|
|
|
* *
|
|
|
|
** GNU General Public License Usage **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
** GNU Lesser General Public License **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this library. *
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
* This library is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
****************************************************************************/
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QApplication>
|
2019-02-14 20:50:01 +03:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLineEdit>
|
2019-02-18 13:55:53 +03:00
|
|
|
#include <QToolButton>
|
2019-06-28 13:08:33 +03:00
|
|
|
#include <QMenu>
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
#include "lrglobal.h"
|
|
|
|
#include "lrobjectinspectorwidget.h"
|
|
|
|
#include "lrobjectitemmodel.h"
|
|
|
|
|
|
|
|
namespace LimeReport{
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
ObjectInspectorTreeView::ObjectInspectorTreeView(QWidget *parent)
|
2016-02-17 10:11:00 +03:00
|
|
|
:QTreeView(parent), m_propertyDelegate(0)
|
|
|
|
{
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
initColorMap();
|
|
|
|
setEditTriggers(
|
|
|
|
QAbstractItemView::DoubleClicked |
|
|
|
|
QAbstractItemView::SelectedClicked |
|
|
|
|
QAbstractItemView::EditKeyPressed
|
|
|
|
);
|
|
|
|
m_propertyDelegate = new PropertyDelegate(this);
|
|
|
|
setItemDelegate(m_propertyDelegate);
|
|
|
|
QPalette p = palette();
|
|
|
|
p.setColor(QPalette::AlternateBase,QColor(229,255,214));
|
|
|
|
setPalette(p);
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
ObjectInspectorTreeView::~ObjectInspectorTreeView(){}
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
ObjectPropItem *node = nodeFromIndex(index);
|
2016-07-07 23:48:03 +03:00
|
|
|
StyleOptionViewItem so = options;
|
|
|
|
bool alternate = so.features & StyleOptionViewItem::Alternate;
|
2016-02-17 10:11:00 +03:00
|
|
|
if (node){
|
|
|
|
if ((!node->isHaveValue())){
|
|
|
|
const QColor c = options.palette.color(QPalette::Dark);
|
|
|
|
painter->fillRect(options.rect,c);
|
|
|
|
so.palette.setColor(QPalette::AlternateBase,c);
|
|
|
|
} else {
|
|
|
|
if ( index.isValid()&&(nodeFromIndex(index)->colorIndex()!=-1) ){
|
|
|
|
QColor fillColor(getColor(nodeFromIndex(index)->colorIndex()%m_colors.count()));
|
|
|
|
so.palette.setColor(QPalette::AlternateBase,fillColor.lighter(115));
|
|
|
|
if (!alternate){
|
|
|
|
painter->fillRect(options.rect,fillColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTreeView::drawRow(painter,so,index);
|
|
|
|
painter->save();
|
|
|
|
QColor gridLineColor = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor,&so));
|
|
|
|
painter->setPen(gridLineColor);
|
|
|
|
painter->drawLine(so.rect.x(),so.rect.bottom(),so.rect.right(),so.rect.bottom());
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::mousePressEvent(QMouseEvent *event)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if ((event->button()==Qt::LeftButton)){
|
|
|
|
QModelIndex index=indexAt(event->pos());
|
|
|
|
if (index.isValid()){
|
2020-01-31 20:00:28 +03:00
|
|
|
if (event->pos().x() < indentation()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
if (!nodeFromIndex(index)->isHaveValue())
|
|
|
|
setExpanded(index,!isExpanded(index));
|
|
|
|
} else {
|
|
|
|
if ((index.column()==1)&&(!nodeFromIndex(index)->isHaveChildren())) {
|
|
|
|
setCurrentIndex(index);
|
2020-01-31 20:00:28 +03:00
|
|
|
|
|
|
|
Qt::ItemFlags flags = index.model()->flags(index);
|
|
|
|
if ( !(((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0)) )
|
|
|
|
edit(index);
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeView::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::initColorMap()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
m_colors.reserve(6);
|
|
|
|
m_colors.push_back(QColor(255,230,191));
|
|
|
|
m_colors.push_back(QColor(255,255,191));
|
|
|
|
m_colors.push_back(QColor(191,255,191));
|
|
|
|
m_colors.push_back(QColor(199,255,255));
|
|
|
|
m_colors.push_back(QColor(234,191,255));
|
|
|
|
m_colors.push_back(QColor(255,191,239));
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
QColor ObjectInspectorTreeView::getColor(const int index) const
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
return m_colors[index];
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::reset()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
QTreeView::reset();
|
|
|
|
for (int i=0;i<model()->rowCount();i++){
|
|
|
|
if (!nodeFromIndex(model()->index(i,0))->isHaveValue()){
|
|
|
|
setFirstColumnSpanned(i,model()->index(i,0).parent(),true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
ObjectPropItem * ObjectInspectorTreeView::nodeFromIndex(QModelIndex index) const
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2019-02-14 00:21:57 +03:00
|
|
|
return qvariant_cast<LimeReport::ObjectPropItem*>(index.data(Qt::UserRole));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::keyPressEvent(QKeyEvent *event)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (event->key()==Qt::Key_Return){
|
|
|
|
if(!m_propertyDelegate->isEditing()){
|
|
|
|
QModelIndex index = currentIndex().model()->index(currentIndex().row(),
|
|
|
|
1,currentIndex().parent());
|
|
|
|
edit(index);
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
} else QTreeView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
void ObjectInspectorTreeView::commitActiveEditorData(){
|
2016-02-17 10:11:00 +03:00
|
|
|
if (state()==QAbstractItemView::EditingState){
|
|
|
|
commitData(indexWidget(currentIndex()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
bool PropertyFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
2021-08-23 08:07:08 +03:00
|
|
|
if (sourceParent.isValid()) return true;
|
|
|
|
#if QT_VERSION < 0x060000
|
2019-02-14 20:50:01 +03:00
|
|
|
return sourceModel()->data(index).toString().contains(filterRegExp());
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
|
|
|
return sourceModel()->data(index).toString().contains(filterRegularExpression());
|
|
|
|
#endif
|
2019-02-14 20:50:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-08-24 08:37:40 +03:00
|
|
|
#if QT_VERSION < 0x060000
|
2019-02-14 20:50:01 +03:00
|
|
|
m_filterModel->setFilterRegExp(QRegExp("", Qt::CaseInsensitive, QRegExp::FixedString));
|
2021-08-24 08:37:40 +03:00
|
|
|
#else
|
|
|
|
m_filterModel->setFilterRegularExpression(QRegularExpression("", QRegularExpression::CaseInsensitiveOption));
|
|
|
|
#endif
|
2019-02-14 20:50:01 +03:00
|
|
|
m_objectInspectorView->setModel(m_filterModel);
|
|
|
|
QVBoxLayout* l = new QVBoxLayout();
|
|
|
|
QLineEdit* le = new QLineEdit(this);
|
2019-02-18 13:55:53 +03:00
|
|
|
QToolButton * pbClear = new QToolButton(this);
|
2019-02-14 20:50:01 +03:00
|
|
|
pbClear->setToolTip(tr("Clear"));
|
2019-02-18 13:55:53 +03:00
|
|
|
pbClear->setIcon(QIcon(":/items/clear.png"));
|
2019-02-14 20:50:01 +03:00
|
|
|
connect(pbClear, SIGNAL(clicked()), le, SLOT(clear()));
|
|
|
|
le->setPlaceholderText(tr("Filter"));
|
|
|
|
connect(le, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterTextChanged(const QString&)));
|
2019-06-28 13:08:33 +03:00
|
|
|
|
|
|
|
QToolButton* settingButton = new QToolButton(this);
|
|
|
|
settingButton->setIcon(QIcon(":/items/images/settings.png"));
|
|
|
|
QMenu* settingMenu = new QMenu(settingButton);
|
|
|
|
m_translateProperties = settingMenu->addAction(tr("Translate properties"));
|
|
|
|
m_translateProperties->setCheckable(true);
|
|
|
|
m_translateProperties->setChecked(translateProperties());
|
|
|
|
|
|
|
|
connect(m_translateProperties, SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(slotTranslatePropertiesChecked(bool)));
|
|
|
|
|
|
|
|
settingButton->setMenu(settingMenu);
|
|
|
|
settingButton->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
2019-02-14 20:50:01 +03:00
|
|
|
QHBoxLayout* h = new QHBoxLayout();
|
|
|
|
h->setSpacing(2);
|
|
|
|
h->addWidget(le);
|
|
|
|
h->addWidget(pbClear);
|
2019-06-28 13:08:33 +03:00
|
|
|
h->addWidget(settingButton);
|
2019-02-14 20:50:01 +03:00
|
|
|
l->addLayout(h);
|
|
|
|
l->addWidget(m_objectInspectorView);
|
2021-08-23 08:07:08 +03:00
|
|
|
int margin = Const::DOCKWIDGET_MARGINS;
|
|
|
|
l->setContentsMargins(margin, margin, margin, margin);
|
2019-02-18 13:55:53 +03:00
|
|
|
l->setSpacing(2);
|
2019-02-14 20:50:01 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-28 13:08:33 +03:00
|
|
|
bool ObjectInspectorWidget::translateProperties()
|
|
|
|
{
|
|
|
|
return m_propertyModel->isTranslateProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectInspectorWidget::setTranslateProperties(bool value)
|
|
|
|
{
|
|
|
|
m_propertyModel->setTranslateProperties(value);
|
|
|
|
m_translateProperties->setChecked(value);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:00:33 +03:00
|
|
|
const QObject *ObjectInspectorWidget::object(){
|
2019-02-14 20:50:01 +03:00
|
|
|
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)
|
2021-08-24 08:37:40 +03:00
|
|
|
#if QT_VERSION < 0x060000
|
2019-02-14 20:50:01 +03:00
|
|
|
m_filterModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::FixedString));
|
2021-08-24 08:37:40 +03:00
|
|
|
#else
|
|
|
|
m_filterModel->setFilterRegularExpression(QRegularExpression(filter, QRegularExpression::CaseInsensitiveOption));
|
|
|
|
#endif
|
2019-02-14 20:50:01 +03:00
|
|
|
}
|
|
|
|
|
2019-06-28 13:08:33 +03:00
|
|
|
void ObjectInspectorWidget::slotTranslatePropertiesChecked(bool value)
|
|
|
|
{
|
|
|
|
setTranslateProperties(value);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
} //namespace LimeReport
|