remove null deleter

This commit is contained in:
Roy Qu 2023-03-07 17:18:35 +08:00
parent ff109d5b58
commit d295ff8d11
10 changed files with 164 additions and 61 deletions

View File

@ -7,6 +7,9 @@ Red Panda C++ Version 2.17
- enhancement: Show mousetip for numbers in the GNU assembly file.
- enhancement: Open offline gnu as/x86 assembly manual if exists.
- fix: Hex number with 'f' in not is not correctly colored.
- fix: After project's default encoding is changed in the project options dialog, all project files' encoding are wrongly setted to the new encoding.(They should be "Project default")
- enhancement: Make project's default encoding setting in the project options dialog more user friendly.
- fix: In project options dialog's file page, Project's default encoding name is not updated when it's changed.
Red Panda C++ Version 2.16

View File

@ -1131,7 +1131,8 @@ void Project::setEncoding(const QByteArray &encoding)
continue;
Editor * e=unitEditor(unit);
if (e) {
e->setEncodingOption(mOptions.encoding);
e->setEncodingOption(ENCODING_PROJECT);
unit->setEncoding(ENCODING_PROJECT);
}
}
}

View File

@ -255,7 +255,11 @@ void ProjectFilesWidget::init()
ui->spinPriority->setMaximum(9999);
ui->cbEncodingDetail->setVisible(false);
ui->cbEncoding->clear();
if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) {
ui->cbEncoding->addItem(tr("Project(%1)").arg(tr("ANSI"),ENCODING_PROJECT));
} else {
ui->cbEncoding->addItem(tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)),ENCODING_PROJECT);
}
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
@ -264,6 +268,17 @@ void ProjectFilesWidget::init()
SettingsWidget::init();
}
void ProjectFilesWidget::showEvent(QShowEvent *event)
{
if (ui->cbEncoding->count()>0) {
if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) {
ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(tr("ANSI")));
} else {
ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)));
}
}
}
void ProjectFilesWidget::on_cbEncodingDetail_currentTextChanged(const QString &)
{

View File

@ -63,6 +63,10 @@ private slots:
public:
void init() override;
// QWidget interface
protected:
void showEvent(QShowEvent *event) override;
};
#endif // PROJECTFILESWIDGET_H

View File

@ -21,6 +21,7 @@
#include "settings.h"
#include "../systemconsts.h"
#include "../iconsmanager.h"
#include "qt_utils/charsetinfo.h"
#include <QFileDialog>
#include <QIcon>
@ -79,7 +80,26 @@ void ProjectGeneralWidget::doLoad()
.arg(totalCount).arg(srcCount).arg(headerCount)
.arg(resCount).arg(otherCount));
ui->cbDefaultEncoding->setCurrentText(project->options().encoding);
QByteArray defaultEncoding = project->options().encoding;
if (defaultEncoding == ENCODING_AUTO_DETECT
|| defaultEncoding == ENCODING_SYSTEM_DEFAULT
|| defaultEncoding == ENCODING_UTF8
|| defaultEncoding == ENCODING_UTF8_BOM) {
int index =ui->cbEncoding->findData(defaultEncoding);
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetail->clear();
ui->cbEncodingDetail->setVisible(false);
} else {
QString language = pCharsetInfoManager->findLanguageByCharsetName(defaultEncoding);
ui->cbEncoding->setCurrentText(language);
ui->cbEncodingDetail->setVisible(true);
ui->cbEncodingDetail->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetail->addItem(info->name);
}
ui->cbEncodingDetail->setCurrentText(defaultEncoding);
}
ui->lstType->setCurrentRow( static_cast<int>(project->options().type));
@ -97,7 +117,11 @@ void ProjectGeneralWidget::doSave()
return;
project->setName(ui->txtName->text().trimmed());
project->setEncoding(ui->cbDefaultEncoding->currentText().toUtf8());
if (ui->cbEncodingDetail->isVisible()) {
project->setEncoding(ui->cbEncodingDetail->currentText().toUtf8());
} else {
project->setEncoding(ui->cbEncoding->currentData().toByteArray());
}
int row = std::max(0,ui->lstType->currentRow());
project->options().type = static_cast<ProjectType>(row);
@ -164,13 +188,35 @@ void ProjectGeneralWidget::on_btnRemove_clicked()
setSettingsChanged();
}
void ProjectGeneralWidget::on_cbEncoding_currentTextChanged(const QString &arg1)
{
QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8
|| userData == ENCODING_UTF8_BOM) {
ui->cbEncodingDetail->setVisible(false);
ui->cbEncodingDetail->clear();
} else {
ui->cbEncodingDetail->setVisible(true);
ui->cbEncodingDetail->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetail->addItem(info->name);
}
}
}
void ProjectGeneralWidget::init()
{
ui->cbDefaultEncoding->clear();
QStringList codecNames=pSystemConsts->codecNames();
//project encoding shouldn't be auto
codecNames.removeAll(ENCODING_AUTO_DETECT);
ui->cbDefaultEncoding->addItems(codecNames);
ui->cbEncodingDetail->setVisible(false);
ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
ui->cbEncoding->addItem(tr("UTF-8 BOM"),ENCODING_UTF8_BOM);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
ui->cbEncoding->addItem(langName,langName);
}
SettingsWidget::init();
}

View File

@ -44,6 +44,7 @@ protected:
private slots:
void on_btnBrowse_clicked();
void on_btnRemove_clicked();
void on_cbEncoding_currentTextChanged(const QString &arg1);
// SettingsWidget interface
public:

View File

@ -52,9 +52,6 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cbDefaultEncoding"/>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lblFiles">
<property name="text">
@ -281,6 +278,43 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item>
<widget class="QComboBox" name="cbEncodingDetail"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>

View File

@ -751,8 +751,8 @@ void QSynEditPainter::paintFoldAttributes()
// Paint collapsed lines using changed pen
if (edit->mCodeFolding.showCollapsedLine) {
painter->setPen(edit->mCodeFolding.collapsedLineColor);
for (int i=0; i< edit->mAllFoldRanges.count();i++) {
PCodeFoldingRange range = edit->mAllFoldRanges[i];
for (int i=0; i< edit->mAllFoldRanges->count();i++) {
PCodeFoldingRange range = (*edit->mAllFoldRanges)[i];
if (range->collapsed && !range->parentCollapsed() &&
(range->fromLine <= vLastLine) && (range->fromLine >= vFirstLine) ) {
// Get starting and end points

View File

@ -149,6 +149,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mContentImage = std::make_shared<QImage>(clientWidth()*dpr,clientHeight()*dpr,QImage::Format_ARGB32);
mContentImage->setDevicePixelRatio(dpr);
mAllFoldRanges = std::make_shared<CodeFoldingRanges>();
mUseCodeFolding = true;
m_blinkTimerId = 0;
m_blinkStatus = 0;
@ -947,8 +948,8 @@ int QSynEdit::lineToRow(int aLine) const
int QSynEdit::foldRowToLine(int Row) const
{
int result = Row;
for (int i=0;i<mAllFoldRanges.count();i++) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i=0;i<mAllFoldRanges->count();i++) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (range->collapsed && !range->parentCollapsed() && range->fromLine < result) {
result += range->linesCollapsed;
}
@ -959,8 +960,8 @@ int QSynEdit::foldRowToLine(int Row) const
int QSynEdit::foldLineToRow(int Line) const
{
int result = Line;
for (int i=mAllFoldRanges.count()-1;i>=0;i--) {
PCodeFoldingRange range =mAllFoldRanges[i];
for (int i=mAllFoldRanges->count()-1;i>=0;i--) {
PCodeFoldingRange range =(*mAllFoldRanges)[i];
if (range->collapsed && !range->parentCollapsed()) {
// Line is found after fold
if (range->toLine < Line)
@ -1223,8 +1224,8 @@ bool QSynEdit::inputMethodOn()
void QSynEdit::collapseAll()
{
incPaintLock();
for (int i = mAllFoldRanges.count()-1;i>=0;i--){
collapse(mAllFoldRanges[i]);
for (int i = mAllFoldRanges->count()-1;i>=0;i--){
collapse((*mAllFoldRanges)[i]);
}
decPaintLock();
}
@ -1232,8 +1233,8 @@ void QSynEdit::collapseAll()
void QSynEdit::unCollpaseAll()
{
incPaintLock();
for (int i = mAllFoldRanges.count()-1;i>=0;i--){
uncollapse(mAllFoldRanges[i]);
for (int i = mAllFoldRanges->count()-1;i>=0;i--){
uncollapse((*mAllFoldRanges)[i]);
}
decPaintLock();
}
@ -3428,8 +3429,8 @@ void QSynEdit::collapse(PCodeFoldingRange FoldRange)
void QSynEdit::foldOnListInserted(int Line, int Count)
{
// Delete collapsed inside selection
for (int i = mAllFoldRanges.count()-1;i>=0;i--) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i = mAllFoldRanges->count()-1;i>=0;i--) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (range->fromLine == Line - 1) {// insertion starts at fold line
if (range->collapsed)
uncollapse(range);
@ -3441,13 +3442,13 @@ void QSynEdit::foldOnListInserted(int Line, int Count)
void QSynEdit::foldOnListDeleted(int Line, int Count)
{
// Delete collapsed inside selection
for (int i = mAllFoldRanges.count()-1;i>=0;i--) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i = mAllFoldRanges->count()-1;i>=0;i--) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (range->fromLine == Line && Count == 1) {// open up because we are messing with the starting line
if (range->collapsed)
uncollapse(range);
} else if (range->fromLine >= Line - 1 && range->fromLine < Line + Count) // delete inside affectec area
mAllFoldRanges.remove(i);
mAllFoldRanges->remove(i);
else if (range->fromLine >= Line + Count) // Move after affected area
range->move(-Count);
@ -3457,7 +3458,7 @@ void QSynEdit::foldOnListDeleted(int Line, int Count)
void QSynEdit::foldOnListCleared()
{
mAllFoldRanges.clear();
mAllFoldRanges->clear();
}
void QSynEdit::rescanFolds()
@ -3473,8 +3474,6 @@ void QSynEdit::rescanFolds()
invalidateGutter();
}
static void null_deleter(CodeFoldingRanges *) {}
void QSynEdit::rescanForFoldRanges()
{
// Delete all uncollapsed folds
@ -3485,13 +3484,13 @@ void QSynEdit::rescanForFoldRanges()
// }
// Did we leave any collapsed folds and are we viewing a code file?
if (mAllFoldRanges.count() > 0) {
if (mAllFoldRanges->count() > 0) {
QMap<QString,PCodeFoldingRange> rangeIndexes;
foreach(const PCodeFoldingRange& r, mAllFoldRanges.ranges()) {
foreach(const PCodeFoldingRange& r, mAllFoldRanges->ranges()) {
if (r->collapsed)
rangeIndexes.insert(QString("%1-%2").arg(r->fromLine).arg(r->toLine),r);
}
mAllFoldRanges.clear();
mAllFoldRanges->clear();
// Add folds to a separate list
PCodeFoldingRanges temporaryAllFoldRanges = std::make_shared<CodeFoldingRanges>();
scanForFoldRanges(temporaryAllFoldRanges);
@ -3507,11 +3506,11 @@ void QSynEdit::rescanForFoldRanges()
tempFoldRange->collapsed=true;
tempFoldRange->linesCollapsed=r2->linesCollapsed;
}
mAllFoldRanges.add(tempFoldRange);
mAllFoldRanges->add(tempFoldRange);
}
} else {
// We ended up with no folds after deleting, just pass standard data...
PCodeFoldingRanges temp(&mAllFoldRanges, null_deleter);
PCodeFoldingRanges temp{mAllFoldRanges};
scanForFoldRanges(temp);
}
}
@ -3612,10 +3611,10 @@ void QSynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRa
PCodeFoldingRange QSynEdit::collapsedFoldStartAtLine(int Line)
{
for (int i = 0; i< mAllFoldRanges.count() - 1; i++ ) {
if (mAllFoldRanges[i]->collapsed && mAllFoldRanges[i]->fromLine == Line) {
return mAllFoldRanges[i];
} else if (mAllFoldRanges[i]->fromLine > Line) {
for (int i = 0; i< mAllFoldRanges->count() - 1; i++ ) {
if ((*mAllFoldRanges)[i]->collapsed && (*mAllFoldRanges)[i]->fromLine == Line) {
return (*mAllFoldRanges)[i];
} else if ((*mAllFoldRanges)[i]->fromLine > Line) {
break; // sorted by line. don't bother scanning further
}
}
@ -3629,8 +3628,8 @@ void QSynEdit::initializeCaret()
PCodeFoldingRange QSynEdit::foldStartAtLine(int Line) const
{
for (int i = 0; i<mAllFoldRanges.count();i++) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i = 0; i<mAllFoldRanges->count();i++) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (range->fromLine == Line ){
return range;
} else if (range->fromLine>Line)
@ -3641,8 +3640,8 @@ PCodeFoldingRange QSynEdit::foldStartAtLine(int Line) const
bool QSynEdit::foldCollapsedBetween(int startLine, int endLine) const
{
for (int i = 0; i<mAllFoldRanges.count();i++) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i = 0; i<mAllFoldRanges->count();i++) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (startLine >=range->fromLine && range->fromLine<=endLine
&& (range->collapsed || range->parentCollapsed())){
return true;
@ -3696,32 +3695,32 @@ QString QSynEdit::substringByColumns(const QString &s, int startColumn, int &col
return result;
}
PCodeFoldingRange QSynEdit::foldAroundLine(int Line)
PCodeFoldingRange QSynEdit::foldAroundLine(int line)
{
return foldAroundLineEx(Line,false,false,false);
return foldAroundLineEx(line,false,false,false);
}
PCodeFoldingRange QSynEdit::foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine)
PCodeFoldingRange QSynEdit::foldAroundLineEx(int line, bool wantCollapsed, bool acceptFromLine, bool acceptToLine)
{
// Check global list
PCodeFoldingRange Result = checkFoldRange(&mAllFoldRanges, Line, WantCollapsed, AcceptFromLine, AcceptToLine);
PCodeFoldingRange result = checkFoldRange(mAllFoldRanges, line, wantCollapsed, acceptFromLine, acceptToLine);
// Found an item in the top level list?
if (Result) {
if (result) {
while (true) {
PCodeFoldingRange ResultChild = checkFoldRange(Result->subFoldRanges.get(), Line, WantCollapsed, AcceptFromLine, AcceptToLine);
PCodeFoldingRange ResultChild = checkFoldRange(result->subFoldRanges, line, wantCollapsed, acceptFromLine, acceptToLine);
if (!ResultChild)
break;
Result = ResultChild; // repeat for this one
result = ResultChild; // repeat for this one
}
}
return Result;
return result;
}
PCodeFoldingRange QSynEdit::checkFoldRange(CodeFoldingRanges *FoldRangeToCheck, int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine)
PCodeFoldingRange QSynEdit::checkFoldRange(PCodeFoldingRanges foldRangesToCheck, int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine)
{
for (int i = 0; i< FoldRangeToCheck->count(); i++) {
PCodeFoldingRange range = (*FoldRangeToCheck)[i];
for (int i = 0; i< foldRangesToCheck->count(); i++) {
PCodeFoldingRange range = (*foldRangesToCheck)[i];
if (((range->fromLine < Line) || ((range->fromLine <= Line) && AcceptFromLine)) &&
((range->toLine > Line) || ((range->toLine >= Line) && AcceptToLine))) {
if (range->collapsed == WantCollapsed) {
@ -3734,8 +3733,8 @@ PCodeFoldingRange QSynEdit::checkFoldRange(CodeFoldingRanges *FoldRangeToCheck,
PCodeFoldingRange QSynEdit::foldEndAtLine(int Line)
{
for (int i = 0; i<mAllFoldRanges.count();i++) {
PCodeFoldingRange range = mAllFoldRanges[i];
for (int i = 0; i<mAllFoldRanges->count();i++) {
PCodeFoldingRange range = (*mAllFoldRanges)[i];
if (range->toLine == Line ){
return range;
} else if (range->fromLine>Line)

View File

@ -520,10 +520,10 @@ private:
PCodeFoldingRange foldStartAtLine(int Line) const;
bool foldCollapsedBetween(int startLine, int endLine) const;
QString substringByColumns(const QString& s, int startColumn, int& colLen);
PCodeFoldingRange foldAroundLine(int Line);
PCodeFoldingRange foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PCodeFoldingRange checkFoldRange(CodeFoldingRanges* FoldRangeToCheck,int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PCodeFoldingRange foldEndAtLine(int Line);
PCodeFoldingRange foldAroundLine(int line);
PCodeFoldingRange foldAroundLineEx(int line, bool wantCollapsed, bool acceptFromLine, bool acceptToLine);
PCodeFoldingRange checkFoldRange(PCodeFoldingRanges foldRangesToCheck,int line, bool wantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PCodeFoldingRange foldEndAtLine(int line);
void paintCaret(QPainter& painter, const QRect rcClip);
int textOffset() const;
EditCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers);
@ -639,7 +639,7 @@ private slots:
private:
std::shared_ptr<QImage> mContentImage;
CodeFoldingRanges mAllFoldRanges;
PCodeFoldingRanges mAllFoldRanges;
CodeFoldingOptions mCodeFolding;
int mEditingCount;
bool mUseCodeFolding;