mirror of
https://github.com/fralx/LimeReport.git
synced 2025-10-01 11:31:10 +03:00
QT_VERSION < 0x060000 -> (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
page order has been fixed when TOC page is present and some pages are not printable
This commit is contained in:
@@ -282,14 +282,13 @@ void CodeEditor::insertCompletion(const QString &completion)
|
||||
if (m_completer->widget() != this)
|
||||
return;
|
||||
QTextCursor tc = textCursor();
|
||||
int extra = completion.length() - m_completer->completionPrefix().length();
|
||||
//tc.movePosition(QTextCursor::Left);
|
||||
//tc.movePosition(QTextCursor::EndOfWord);
|
||||
// QString prefix = m_completer->completionPrefix();
|
||||
// int extra = completion.length() - prefix.length();
|
||||
for (int i=0; i < m_completer->completionPrefix().length(); ++i ) {
|
||||
tc.deletePreviousChar();
|
||||
}
|
||||
tc.insertText(completion);
|
||||
//tc.insertText(completion.right(extra));
|
||||
// tc.insertText(completion.right(extra));
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
|
142
limereport/scripteditor/lrcompletermodel.cpp
Normal file
142
limereport/scripteditor/lrcompletermodel.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
#include "lrcompletermodel.h"
|
||||
#include <QDebug>
|
||||
|
||||
CompleterModel::CompleterModel(QObject *parent) : QAbstractItemModel(parent){m_root.setModel(this);}
|
||||
|
||||
QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
CompleterItem const *parentItem;
|
||||
if (!parent.isValid())
|
||||
parentItem = &m_root;
|
||||
else
|
||||
parentItem = static_cast<CompleterItem*>(parent.internalPointer());
|
||||
|
||||
if ((parentItem == nullptr)
|
||||
|| (row < 0)
|
||||
|| (column < 0)
|
||||
|| (row >= parentItem->rowCount())
|
||||
|| (column >= 1))
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
return createIndex(row, column, parentItem->child(row));
|
||||
}
|
||||
|
||||
QModelIndex CompleterModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
if (child.isValid()){
|
||||
CompleterItem *childItem = static_cast<CompleterItem*>(child.internalPointer());
|
||||
CompleterItem *parentItem = childItem->parent();
|
||||
if (parentItem != &m_root) {
|
||||
return indexFromItem(parentItem);
|
||||
}
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
int CompleterModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid()){
|
||||
CompleterItem *parentItem = static_cast<CompleterItem*>(parent.internalPointer());
|
||||
return parentItem->rowCount();
|
||||
}
|
||||
return m_root.rowCount();
|
||||
}
|
||||
|
||||
int CompleterModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant CompleterModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.isValid()){
|
||||
CompleterItem* item = static_cast<CompleterItem*>(index.internalPointer());
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
if (!item) return QVariant();
|
||||
|
||||
if (index.column()==0){
|
||||
return item->text();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
case Qt::DecorationRole :
|
||||
if (!item) return QIcon();
|
||||
if (index.column()==0){
|
||||
return item->icon();
|
||||
} else return QIcon();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QList<CompleterItem *> CompleterModel::findItems(const QString &text, Qt::MatchFlags flags, int column) const
|
||||
{
|
||||
QModelIndexList indexes = match(index(0, column, QModelIndex()),
|
||||
Qt::DisplayRole, text, -1, flags);
|
||||
QList<CompleterItem*> items;
|
||||
const int numIndexes = indexes.size();
|
||||
items.reserve(numIndexes);
|
||||
for (int i = 0; i < numIndexes; ++i)
|
||||
items.append(itemFromIndex(indexes.at(i)));
|
||||
return items;
|
||||
}
|
||||
|
||||
void CompleterModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_root.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
CompleterItem *CompleterModel::itemFromIndex(const QModelIndex index) const
|
||||
{
|
||||
if ((index.row() < 0) || (index.column() < 0) || (index.model() != this))
|
||||
return nullptr;
|
||||
CompleterItem *parent = static_cast<CompleterItem*>(index.internalPointer());
|
||||
if (parent == nullptr)
|
||||
return nullptr;
|
||||
CompleterItem *item = parent->child(index.row());
|
||||
return item;
|
||||
}
|
||||
|
||||
QModelIndex CompleterModel::indexFromItem(CompleterItem *item) const
|
||||
{
|
||||
if (item && item->parent()){
|
||||
return createIndex(item->row(), 0, item);
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
CompleterItem::~CompleterItem(){}
|
||||
|
||||
void CompleterItem::setIcon(const QIcon &newIcon)
|
||||
{
|
||||
m_icon = newIcon;
|
||||
}
|
||||
|
||||
void CompleterItem::setText(const QString &newText)
|
||||
{
|
||||
m_text = newText;
|
||||
}
|
||||
|
||||
void CompleterItem::appendRow(CompleterItem *child){
|
||||
child->m_parent = this;
|
||||
child->m_model = this->m_model;
|
||||
m_children.append(QSharedPointer<CompleterItem>(child));
|
||||
if (m_model){
|
||||
QModelIndex start = m_model->indexFromItem(child);
|
||||
emit m_model->dataChanged(start, start);
|
||||
}
|
||||
}
|
||||
|
||||
void CompleterItem::appendRows(const QList<CompleterItem*> &children){
|
||||
foreach(CompleterItem* item, children){
|
||||
appendRow(item);
|
||||
}
|
||||
}
|
71
limereport/scripteditor/lrcompletermodel.h
Normal file
71
limereport/scripteditor/lrcompletermodel.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef COMPLETERMODEL_H
|
||||
#define COMPLETERMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QIcon>
|
||||
|
||||
class CompleterModel;
|
||||
|
||||
class CompleterItem {
|
||||
public:
|
||||
CompleterItem():m_parent(0), m_model(0){}
|
||||
CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){}
|
||||
~CompleterItem();
|
||||
int rowCount() const {return m_children.count();}
|
||||
CompleterItem* child(int row) const {return m_children.at(row).data();}
|
||||
CompleterItem* parent() const {return m_parent;}
|
||||
int row() const{
|
||||
if (m_parent){
|
||||
for(int i=0; i < m_parent->m_children.count(); ++i){
|
||||
CompleterItem* c = m_parent->m_children.at(i).data();
|
||||
if (c == this) return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
QString text(){return m_text;}
|
||||
QIcon icon() {return m_icon;}
|
||||
|
||||
void setIcon(const QIcon &newIcon);
|
||||
void setText(const QString &newText);
|
||||
void setModel(CompleterModel* model){m_model=model;}
|
||||
void clear(){m_children.clear();}
|
||||
void appendRow(CompleterItem* child);
|
||||
void appendRows(const QList<CompleterItem *> &children);
|
||||
private:
|
||||
CompleterItem* m_parent;
|
||||
QVector<QSharedPointer<CompleterItem> > m_children;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
CompleterModel* m_model;
|
||||
};
|
||||
|
||||
|
||||
class CompleterModel : public QAbstractItemModel
|
||||
{
|
||||
friend CompleterItem;
|
||||
public:
|
||||
explicit CompleterModel(QObject *parent = nullptr);
|
||||
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
CompleterItem* invisibleRootItem(){return &m_root;}
|
||||
QList<CompleterItem*> findItems(const QString &text,
|
||||
Qt::MatchFlags flags = Qt::MatchExactly,
|
||||
int column = 0) const;
|
||||
void clear();
|
||||
private:
|
||||
CompleterItem *itemFromIndex(const QModelIndex index) const;
|
||||
QModelIndex indexFromItem(CompleterItem *item) const;
|
||||
private:
|
||||
CompleterItem m_root;
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
#endif // COMPLETERMODEL_H
|
@@ -20,7 +20,7 @@ ScriptEditor::ScriptEditor(QWidget *parent) :
|
||||
setFocusProxy(ui->textEdit);
|
||||
m_completer = new ReportStructureCompleater(this);
|
||||
ui->textEdit->setCompleter(m_completer);
|
||||
#if QT_VERSION < 0x060000
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,12,3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("0").width()*m_tabIndention);
|
||||
#else
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("0").width()*m_tabIndention);
|
||||
@@ -90,7 +90,7 @@ void ScriptEditor::setPageBand(BandDesignIntf* band)
|
||||
void ScriptEditor::setTabIndention(int charCount)
|
||||
{
|
||||
if (m_tabIndention != charCount){
|
||||
#if QT_VERSION < 0x060000
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,12,3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("W").width()*charCount);
|
||||
#else
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("W").width()*charCount);
|
||||
@@ -182,21 +182,21 @@ QStringList ReportStructureCompleater::splitPath(const QString &path) const
|
||||
return path.split(".");
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::addAdditionalDatawords(QStandardItemModel* model, DataSourceManager* dataManager){
|
||||
void ReportStructureCompleater::addAdditionalDatawords(CompleterModel* model, DataSourceManager* dataManager){
|
||||
|
||||
foreach(const QString &dsName,dataManager->dataSourceNames()){
|
||||
QStandardItem* dsNode = new QStandardItem;
|
||||
CompleterItem* dsNode = new CompleterItem;
|
||||
dsNode->setText(dsName);
|
||||
model->invisibleRootItem()->appendRow(dsNode);
|
||||
foreach(const QString &field, dataManager->fieldNames(dsName)){
|
||||
QStandardItem* fieldNode = new QStandardItem;
|
||||
CompleterItem* fieldNode = new CompleterItem;
|
||||
fieldNode->setText(field);
|
||||
dsNode->appendRow(fieldNode);
|
||||
}
|
||||
model->invisibleRootItem()->appendRow(dsNode);
|
||||
}
|
||||
|
||||
foreach (QString varName, dataManager->variableNames()) {
|
||||
QStandardItem* varNode = new QStandardItem;
|
||||
CompleterItem* varNode = new CompleterItem;
|
||||
varNode->setText(varName.remove("#"));
|
||||
model->invisibleRootItem()->appendRow(varNode);
|
||||
}
|
||||
@@ -208,19 +208,20 @@ void ReportStructureCompleater::addAdditionalDatawords(QStandardItemModel* model
|
||||
while (it.hasNext()){
|
||||
it.next();
|
||||
if (it.value().isCallable() ){
|
||||
QStandardItem* itemNode = new QStandardItem;
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
itemNode->setText(it.name()+"()");
|
||||
model->invisibleRootItem()->appendRow(itemNode);
|
||||
}
|
||||
if (it.value().isQObject()){
|
||||
if (it.value().toQObject()){
|
||||
if (model->findItems(it.name()).isEmpty()){
|
||||
QStandardItem* objectNode = new QStandardItem;
|
||||
CompleterItem* objectNode = new CompleterItem;
|
||||
objectNode->setText(it.name());
|
||||
objectNode->setIcon(QIcon(":/report/images/object"));
|
||||
|
||||
for (int i = 0; i< it.value().toQObject()->metaObject()->methodCount();++i){
|
||||
if (it.value().toQObject()->metaObject()->method(i).methodType() == QMetaMethod::Method){
|
||||
QStandardItem* methodNode = new QStandardItem;
|
||||
CompleterItem* methodNode = new CompleterItem;
|
||||
QMetaMethod m = it.value().toQObject()->metaObject()->method(i);
|
||||
QString methodSignature = m.name() + "(";
|
||||
bool isFirst = true;
|
||||
@@ -245,46 +246,49 @@ void ReportStructureCompleater::addAdditionalDatawords(QStandardItemModel* model
|
||||
void ReportStructureCompleater::updateCompleaterModel(ReportEnginePrivateInterface* report)
|
||||
{
|
||||
if (report){
|
||||
m_model.clear();
|
||||
m_newModel.clear();
|
||||
|
||||
QIcon signalIcon(":/report/images/signal");
|
||||
QIcon propertyIcon(":/report/images/property");
|
||||
|
||||
for ( int i = 0; i < report->pageCount(); ++i){
|
||||
PageDesignIntf* page = report->pageAt(i);
|
||||
|
||||
QStandardItem* itemNode = new QStandardItem;
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
itemNode->setText(page->pageItem()->objectName());
|
||||
itemNode->setIcon(QIcon(":/report/images/object"));
|
||||
m_model.invisibleRootItem()->appendRow(itemNode);
|
||||
|
||||
QStringList items = extractSignalNames(page->pageItem());
|
||||
foreach(QString slotName, items){
|
||||
QStandardItem* slotItem = new QStandardItem;
|
||||
CompleterItem* slotItem = new CompleterItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
itemNode->appendRow(slotItem);
|
||||
}
|
||||
items = extractProperties(page->pageItem());
|
||||
foreach(QString propertyName, items){
|
||||
QStandardItem* properyItem = new QStandardItem;
|
||||
CompleterItem* properyItem = new CompleterItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
}
|
||||
|
||||
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()){
|
||||
addChildItem(item, itemNode->text(), m_model.invisibleRootItem());
|
||||
addChildItem(item, itemNode->text(), m_newModel.invisibleRootItem());
|
||||
}
|
||||
|
||||
m_newModel.invisibleRootItem()->appendRow(itemNode);
|
||||
}
|
||||
|
||||
addAdditionalDatawords(&m_model, report->dataManager());
|
||||
m_model.sort(0);
|
||||
addAdditionalDatawords(&m_newModel, report->dataManager());
|
||||
m_newModel.sort(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::updateCompleaterModel(DataSourceManager *dataManager)
|
||||
{
|
||||
m_model.clear();
|
||||
addAdditionalDatawords(&m_model, dataManager);
|
||||
m_newModel.clear();
|
||||
addAdditionalDatawords(&m_newModel, dataManager);
|
||||
}
|
||||
|
||||
QStringList ReportStructureCompleater::extractSignalNames(BaseDesignIntf *item)
|
||||
@@ -325,46 +329,64 @@ QStringList ReportStructureCompleater::extractProperties(BaseDesignIntf *item)
|
||||
return result;
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::addChildItem(BaseDesignIntf *item, const QString &pageName, QStandardItem *parent)
|
||||
void ReportStructureCompleater::addChildItem(BaseDesignIntf *item, const QString &pageName, CompleterItem *parent)
|
||||
{
|
||||
if (!item) return;
|
||||
|
||||
QIcon signalIcon(":/report/images/signal");
|
||||
QIcon propertyIcon(":/report/images/property");
|
||||
|
||||
QStandardItem* itemNode = new QStandardItem;
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
itemNode->setText(pageName+"_"+item->objectName());
|
||||
itemNode->setIcon(QIcon(":/report/images/object"));
|
||||
parent->appendRow(itemNode);
|
||||
QStringList items;
|
||||
|
||||
if (!m_signals.contains(item->metaObject()->className())){
|
||||
items = extractSignalNames(item);
|
||||
m_signals.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_signals.value(item->metaObject()->className());
|
||||
}
|
||||
// if (m_cache.contains(item->metaObject()->className())){
|
||||
|
||||
foreach(QString slotName, items){
|
||||
QStandardItem* slotItem = new QStandardItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
itemNode->appendRow(slotItem);
|
||||
}
|
||||
// QSharedPointer<CacheItem> cacheItem = m_cache.value(item->metaObject()->className());
|
||||
// itemNode->appendRows(cacheItem->slotsItems);
|
||||
// itemNode->appendRows(cacheItem->propsItems);
|
||||
|
||||
if (!m_properties.contains(item->metaObject()->className())){
|
||||
items = extractProperties(item);
|
||||
m_properties.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_properties.value(item->metaObject()->className());
|
||||
}
|
||||
// } else {
|
||||
|
||||
foreach(QString propertyName, items){
|
||||
QStandardItem* properyItem = new QStandardItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
}
|
||||
// QSharedPointer<CacheItem> cacheItem = QSharedPointer<CacheItem>(new CacheItem);
|
||||
|
||||
QStringList items;
|
||||
if (!m_signals.contains(item->metaObject()->className())){
|
||||
items = extractSignalNames(item);
|
||||
m_signals.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_signals.value(item->metaObject()->className());
|
||||
}
|
||||
|
||||
foreach(QString slotName, items){
|
||||
CompleterItem* slotItem = new CompleterItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
//cacheItem->slotsItems.append(QSharedPointer<CompleterItem>(slotItem));
|
||||
itemNode->appendRow(slotItem);
|
||||
|
||||
}
|
||||
|
||||
if (!m_properties.contains(item->metaObject()->className())){
|
||||
items = extractProperties(item);
|
||||
m_properties.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_properties.value(item->metaObject()->className());
|
||||
}
|
||||
|
||||
foreach(QString propertyName, items){
|
||||
CompleterItem* properyItem = new CompleterItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
//cacheItem->propsItems.append(QSharedPointer<CompleterItem>(properyItem));
|
||||
}
|
||||
|
||||
//m_cache.insert(item->metaObject()->className(), cacheItem);
|
||||
//itemNode->appendRows(cacheItem->slotsItems);
|
||||
//itemNode->appendRows(cacheItem->propsItems);
|
||||
//}
|
||||
|
||||
foreach (BaseDesignIntf* child, item->childBaseItems()){
|
||||
addChildItem(child, pageName, parent);
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QStandardItemModel>
|
||||
#include "lrcompletermodel.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
@@ -20,12 +21,17 @@ namespace Ui {
|
||||
class ScriptEditor;
|
||||
}
|
||||
|
||||
struct CacheItem {
|
||||
QList<QSharedPointer<CompleterItem>> propsItems;
|
||||
QList<QSharedPointer<CompleterItem>> slotsItems;
|
||||
};
|
||||
|
||||
class ReportStructureCompleater : public QCompleter{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ReportStructureCompleater(QObject* parent = 0): QCompleter(parent){ setModel(&m_model);}
|
||||
explicit ReportStructureCompleater(QObject* parent = 0): QCompleter(parent){ setModel(&m_newModel);}
|
||||
explicit ReportStructureCompleater(QAbstractItemModel* model, QObject* parent = 0)
|
||||
:QCompleter(model, parent){ setModel(&m_model);}
|
||||
:QCompleter(model, parent){ setModel(&m_newModel);}
|
||||
public:
|
||||
// QCompleter interface
|
||||
QString pathFromIndex(const QModelIndex& index) const;
|
||||
@@ -35,10 +41,10 @@ public:
|
||||
protected:
|
||||
QStringList extractSignalNames(BaseDesignIntf* item);
|
||||
QStringList extractProperties(BaseDesignIntf* item);
|
||||
void addChildItem(BaseDesignIntf *item, const QString &pageName, QStandardItem *parent);
|
||||
void addAdditionalDatawords(QStandardItemModel* model, DataSourceManager *dataManager);
|
||||
void addChildItem(BaseDesignIntf *item, const QString &pageName, CompleterItem *parent);
|
||||
void addAdditionalDatawords(CompleterModel *model, DataSourceManager *dataManager);
|
||||
private:
|
||||
QStandardItemModel m_model;
|
||||
CompleterModel m_newModel;
|
||||
QMap<QString, QStringList> m_properties;
|
||||
QMap<QString, QStringList> m_signals;
|
||||
};
|
||||
|
Reference in New Issue
Block a user