-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'extendedFolding' into '1.3.0-release'
Extended folding See merge request devel/studio!554
- Loading branch information
Showing
7 changed files
with
177 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "blockdata.h" | ||
|
||
namespace gams { | ||
namespace studio { | ||
namespace syntax { | ||
|
||
BlockData::~BlockData() | ||
{ } | ||
|
||
BlockData *BlockData::fromTextBlock(QTextBlock block) | ||
{ | ||
return (block.isValid() && block.userData()) ? static_cast<BlockData*>(block.userData()) | ||
: nullptr; | ||
} | ||
|
||
QChar BlockData::charForPos(int relPos) | ||
{ | ||
for (int i = mParentheses.count()-1; i >= 0; --i) { | ||
if (mParentheses.at(i).relPos == relPos || mParentheses.at(i).relPos-1 == relPos) { | ||
return mParentheses.at(i).character; | ||
} | ||
} | ||
return QChar(); | ||
} | ||
|
||
QVector<ParenthesesPos> BlockData::parentheses() const | ||
{ | ||
return mParentheses; | ||
} | ||
|
||
void BlockData::setParentheses(const QVector<ParenthesesPos> &parentheses, const NestingImpact &nestingImpact) | ||
{ | ||
mParentheses = parentheses; | ||
mNestingImpact = nestingImpact; | ||
} | ||
|
||
|
||
} // namespace syntax | ||
} // namespace studio | ||
} // namespace gams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef GAMS_STUDIO_BLOCKDATA_H | ||
#define GAMS_STUDIO_BLOCKDATA_H | ||
|
||
#include <QTextBlock> | ||
|
||
namespace gams { | ||
namespace studio { | ||
namespace syntax { | ||
|
||
struct NestingImpact | ||
{ | ||
NestingImpact() {} | ||
void addCloser() { --mImpact; if (mImpact<mMaxDepth) mMaxDepth = mImpact; } | ||
void addOpener() { ++mImpact; } | ||
int impact() { return mImpact; } | ||
int leftOpen() { return mMaxDepth; } | ||
int rightOpen() { return mImpact - mMaxDepth; } | ||
private: | ||
short mImpact = 0; | ||
short mMaxDepth = 0; | ||
}; | ||
|
||
struct ParenthesesPos | ||
{ | ||
ParenthesesPos() : character(QChar()), relPos(-1) {} | ||
ParenthesesPos(QChar _character, int _relPos) : character(_character), relPos(_relPos) {} | ||
QChar character; | ||
int relPos; | ||
}; | ||
|
||
class BlockData : public QTextBlockUserData | ||
{ | ||
public: | ||
BlockData() {} | ||
~BlockData(); | ||
static BlockData *fromTextBlock(QTextBlock block); | ||
QChar charForPos(int relPos); | ||
bool isEmpty() {return mParentheses.isEmpty();} | ||
QVector<ParenthesesPos> parentheses() const; | ||
void setParentheses(const QVector<ParenthesesPos> &parentheses, const NestingImpact &nestingImpact); | ||
NestingImpact nestingImpact() const { return mNestingImpact; } | ||
int &foldCount() { return mFoldCount; } | ||
bool isFolded() const { return mFoldCount; } | ||
void setFoldCount(int foldCount) { mFoldCount = foldCount; } | ||
|
||
private: | ||
// if extending the data remember to enhance isEmpty() | ||
QVector<ParenthesesPos> mParentheses; | ||
NestingImpact mNestingImpact; | ||
int mFoldCount = 0; | ||
}; | ||
|
||
} // namespace syntax | ||
} // namespace studio | ||
} // namespace gams | ||
|
||
#endif // GAMS_STUDIO_BLOCKDATA_H |
Oops, something went wrong.