mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
Completer refactored
This commit is contained in:
parent
8efb6792a3
commit
37b929459b
@ -583,7 +583,7 @@ QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &a
|
||||
match = rx.match(query);
|
||||
}
|
||||
}
|
||||
// TODO: Qt6 port - possible done
|
||||
// TODO: Qt6 port - done
|
||||
#else
|
||||
QRegExp rx(Const::FIELD_RX);
|
||||
if (query.contains(rx)){
|
||||
|
@ -470,7 +470,7 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Qt6 port - possible done
|
||||
// TODO: Qt6 port - done
|
||||
#else
|
||||
if ( contentItem && contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}"))){
|
||||
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
|
||||
@ -556,7 +556,7 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
|
||||
match = rx.match(content, pos + match.capturedLength());
|
||||
}
|
||||
}
|
||||
// TODO: Qt6 port - possible done
|
||||
// TODO: Qt6 port - done
|
||||
#else
|
||||
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
|
||||
rx.setMinimal(true);
|
||||
|
@ -15,7 +15,7 @@
|
||||
namespace LimeReport{
|
||||
|
||||
CodeEditor::CodeEditor(QWidget *parent)
|
||||
: QPlainTextEdit(parent), m_compleater(0)
|
||||
: QPlainTextEdit(parent), m_completer(0)
|
||||
{
|
||||
lineNumberArea = new LineNumberArea(this);
|
||||
|
||||
@ -33,12 +33,13 @@ CodeEditor::CodeEditor(QWidget *parent)
|
||||
void CodeEditor::setCompleter(QCompleter *value)
|
||||
{
|
||||
if (value) disconnect(value,0,this,0);
|
||||
m_compleater = value;
|
||||
if (!m_compleater) return;
|
||||
m_compleater->setWidget(this);
|
||||
m_compleater->setCompletionMode(QCompleter::PopupCompletion);
|
||||
m_compleater->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
connect(m_compleater,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
||||
m_completer = value;
|
||||
if (!m_completer) return;
|
||||
m_completer->setWidget(this);
|
||||
m_completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||
m_completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
connect(m_completer,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
||||
}
|
||||
|
||||
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
|
||||
@ -86,12 +87,11 @@ int CodeEditor::lineNumberAreaWidth()
|
||||
|
||||
void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (m_compleater && m_compleater->popup()->isVisible()) {
|
||||
if (m_completer && m_completer->popup()->isVisible()) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Escape:
|
||||
m_compleater->popup()->close();
|
||||
case Qt::Key_Tab:
|
||||
case Qt::Key_Backtab:
|
||||
case Qt::Key_Right:
|
||||
@ -106,10 +106,10 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
|
||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space);
|
||||
if (!m_compleater || !isShortcut) QPlainTextEdit::keyPressEvent(e);
|
||||
if (!m_completer || !isShortcut) QPlainTextEdit::keyPressEvent(e);
|
||||
|
||||
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
|
||||
if (!m_compleater || (ctrlOrShift && e->text().isEmpty()))
|
||||
if (!m_completer || (ctrlOrShift && e->text().isEmpty()))
|
||||
return;
|
||||
|
||||
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
|
||||
@ -120,36 +120,36 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
|| Const::EOW.contains(e->text().right(1)))
|
||||
)
|
||||
{
|
||||
m_compleater->popup()->hide();
|
||||
m_completer->popup()->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (completionPrefix != m_compleater->completionPrefix()) {
|
||||
m_compleater->setCompletionPrefix(completionPrefix);
|
||||
m_compleater->popup()->setCurrentIndex(m_compleater->completionModel()->index(0, 0));
|
||||
if (completionPrefix != m_completer->completionPrefix()) {
|
||||
m_completer->setCompletionPrefix(completionPrefix);
|
||||
m_completer->popup()->setCurrentIndex(m_completer->completionModel()->index(0, 0));
|
||||
}
|
||||
|
||||
QModelIndex ci = m_compleater->completionModel()->index(0,0);
|
||||
if (ci.isValid() && m_compleater->completionModel()->data(ci).toString().compare(completionPrefix) == 0){
|
||||
m_compleater->popup()->hide();
|
||||
QModelIndex ci = m_completer->completionModel()->index(0,0);
|
||||
if (ci.isValid() && m_completer->completionModel()->data(ci).toString().compare(completionPrefix) == 0){
|
||||
m_completer->popup()->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
QRect cr = cursorRect();
|
||||
cr.setWidth(m_compleater->popup()->sizeHintForColumn(0)
|
||||
+ m_compleater->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_compleater->complete(cr);
|
||||
cr.setWidth(m_completer->popup()->sizeHintForColumn(0)
|
||||
+ m_completer->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_completer->complete(cr);
|
||||
|
||||
if (!completionPrefix.isEmpty() &&
|
||||
completionPrefix.at(completionPrefix.length()-1) == '.')
|
||||
{
|
||||
m_compleater->popup();
|
||||
m_completer->popup();
|
||||
}
|
||||
}
|
||||
|
||||
void CodeEditor::focusInEvent(QFocusEvent *e)
|
||||
{
|
||||
if (m_compleater) m_compleater->setWidget(this);
|
||||
if (m_completer) m_completer->setWidget(this);
|
||||
QPlainTextEdit::focusInEvent(e);
|
||||
}
|
||||
|
||||
@ -279,13 +279,17 @@ QChar CodeEditor::getParenthesisReverceChar(QChar parenthesisChar)
|
||||
|
||||
void CodeEditor::insertCompletion(const QString &completion)
|
||||
{
|
||||
if (m_compleater->widget() != this)
|
||||
if (m_completer->widget() != this)
|
||||
return;
|
||||
QTextCursor tc = textCursor();
|
||||
int extra = completion.length() - m_compleater->completionPrefix().length();
|
||||
int extra = completion.length() - m_completer->completionPrefix().length();
|
||||
//tc.movePosition(QTextCursor::Left);
|
||||
//tc.movePosition(QTextCursor::EndOfWord);
|
||||
tc.insertText(completion.right(extra));
|
||||
for (int i=0; i < m_completer->completionPrefix().length(); ++i ) {
|
||||
tc.deletePreviousChar();
|
||||
}
|
||||
tc.insertText(completion);
|
||||
//tc.insertText(completion.right(extra));
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class CodeEditor :public QPlainTextEdit
|
||||
public:
|
||||
CodeEditor(QWidget* parent=0);
|
||||
void setCompleter(QCompleter* value);
|
||||
QCompleter* compleater() const{ return m_compleater;}
|
||||
QCompleter* compleater() const{ return m_completer;}
|
||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||
int lineNumberAreaWidth();
|
||||
protected:
|
||||
@ -41,7 +41,7 @@ private slots:
|
||||
void updateLineNumberArea(const QRect &rect, int dy);
|
||||
void matchParentheses();
|
||||
private:
|
||||
QCompleter* m_compleater;
|
||||
QCompleter* m_completer;
|
||||
QWidget *lineNumberArea;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user