代码拉取完成,页面将自动刷新
同步操作将从 爬山虎/ndd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "columnedit.h"
#include "scintillaeditview.h"
ColumnEdit::ColumnEdit(QWidget *parent)
: QWidget(parent), m_curEditWin(nullptr), m_editTabWidget(nullptr)
{
ui.setupUi(this);
connect(ui.addPrefix, &QCheckBox::stateChanged, this, &ColumnEdit::slot_addPrefix);
}
ColumnEdit::~ColumnEdit()
{
}
void ColumnEdit::slot_insertTextEnable(bool check)
{
if (check)
{
if (ui.numGroupBox->isChecked())
{
ui.numGroupBox->setChecked(!check);
}
}
}
void ColumnEdit::slot_insertNumEnable(bool check)
{
if (check)
{
if (ui.textGroupBox->isChecked())
{
ui.textGroupBox->setChecked(!check);
}
}
}
void ColumnEdit::slot_addPrefix(int s)
{
if (s == Qt::Checked)
{
ui.prefix->setEnabled(true);
}
else
{
ui.prefix->setEnabled(false);
}
}
//自动调整当前窗口的状态
QWidget* ColumnEdit::autoAdjustCurrentEditWin()
{
QWidget* pw = m_editTabWidget->currentWidget();
if (m_curEditWin != pw)
{
m_curEditWin = pw;
}
return pw;
}
void ColumnEdit::setTabWidget(QTabWidget *editTabWidget)
{
m_editTabWidget = editTabWidget;
}
void ColumnEdit::slot_ok()
{
autoAdjustCurrentEditWin();
ScintillaEditView* pEdit = dynamic_cast<ScintillaEditView*>(m_curEditWin);
if (pEdit == nullptr || pEdit->isReadOnly())
{
QApplication::beep();
return;
}
QString text;
bool isNum = false;
int numType = 10;
int initNum = 0;
int inc = ui.incNum->value();
int repeNum = ui.repeNum->value();
bool addPrefix = ui.addPrefix->isChecked();
QString prefix = ui.prefix->text();
//是插入文本模式
if (ui.textGroupBox->isChecked())
{
text = ui.inputText->text();
}
else
{
isNum = true;
text = ui.initNum->text();
bool ok = false;
if (ui.is10->isChecked())
{
numType = 10;
}
else if (ui.is16->isChecked())
{
numType = 16;
}
else if (ui.is8->isChecked())
{
numType = 8;
}
else if (ui.is2->isChecked())
{
numType = 2;
}
int num = text.toInt(&ok, 10);
initNum = num;
if (ok)
{
text = QString::number(num, numType);
if (addPrefix)
{
text = prefix + text;
}
}
else
{
QApplication::beep();
return;
}
}
pEdit->execute(SCI_BEGINUNDOACTION);
auto cursorPos = pEdit->execute(SCI_GETCURRENTPOS);
auto cursorCol = pEdit->execute(SCI_GETCOLUMN, cursorPos);
auto cursorLine = pEdit->execute(SCI_LINEFROMPOSITION, cursorPos);
auto endPos = pEdit->execute(SCI_GETLENGTH);
auto endLine = pEdit->execute(SCI_LINEFROMPOSITION, endPos);
QByteArray lineData;
int rn = repeNum;
for (size_t i = cursorLine; i <= static_cast<size_t>(endLine); ++i)
{
auto lineBegin = pEdit->execute(SCI_POSITIONFROMLINE, i);
auto lineEnd = pEdit->execute(SCI_GETLINEENDPOSITION, i);
auto lineEndCol = pEdit->execute(SCI_GETCOLUMN, lineEnd);
auto lineLen = lineEnd - lineBegin;
lineData.resize(lineLen);
Sci_TextRange lineText;
lineText.chrg.cpMin = static_cast<Sci_Position>(lineBegin);
lineText.chrg.cpMax = static_cast<Sci_Position>(lineEnd);
lineText.lpstrText = lineData.data();
//获取原始行的内容
pEdit->SendScintilla(SCI_GETTEXTRANGE, 0, &lineText);
if (lineEndCol < cursorCol)
{
QByteArray s_space(cursorCol - lineEndCol, ' ');
lineData.append(s_space);
lineData.append(text);
}
else
{
int posAbs2Start = pEdit->execute(SCI_FINDCOLUMN, i, cursorCol);
int posRelative2Start = posAbs2Start - lineBegin;
lineData.insert(posRelative2Start, text);
}
pEdit->SendScintilla(SCI_SETTARGETRANGE, lineBegin, lineEnd);
pEdit->SendScintilla(SCI_REPLACETARGET, lineData.size(), lineData.data());
if (isNum)
{
--rn;
if (rn > 0)
{
}
else
{
rn = repeNum;
initNum += inc;
}
text = QString::number(initNum, numType);
if (addPrefix)
{
text = prefix + text;
}
}
}
pEdit->execute(SCI_ENDUNDOACTION);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。