Skip to content

Commit

Permalink
Reduce the complexity of some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Nov 23, 2023
1 parent 4e8a87c commit 3e24a01
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 60 deletions.
2 changes: 1 addition & 1 deletion final/widget/flistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ inline void FListView::afterInsertion()
}

//----------------------------------------------------------------------
void FListView::adjustListBeforeRemoval (FListViewItem* item)
void FListView::adjustListBeforeRemoval (const FListViewItem* item)
{
const auto* current_item = static_cast<FListViewItem*>(*selection.current_iter);
const auto* first_item = data.itemlist.front();
Expand Down
2 changes: 1 addition & 1 deletion final/widget/flistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class FListView : public FWidget
auto determineLineWidth (FListViewItem*) -> std::size_t;
void beforeInsertion (FListViewItem*);
void afterInsertion();
void adjustListBeforeRemoval (FListViewItem*);
void adjustListBeforeRemoval (const FListViewItem*);
void removeItemFromParent (FListViewItem*);
void updateListAfterRemoval();
void recalculateHorizontalBar (std::size_t);
Expand Down
125 changes: 68 additions & 57 deletions final/widget/ftextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,67 +279,13 @@ void FTextView::insert (const FString& str, int pos)
if ( pos < 0 || pos >= int(getRows()) )
pos = int(getRows());

auto showHorizontallyScrollable = [this] ()
for (auto&& line : splitTextLines(str)) // Line loop
{
if ( isShown() && isHorizontallyScrollable() )
hbar->show();
};

auto&& text_split = \
[&str] ()
{
if ( str.isEmpty() )
{
FStringList list{};
list.emplace_back("");
return list;
}

const auto& string = str.rtrim().expandTabs(getFOutput()->getTabstop());
return string.split("\n");
}();

for (auto&& line : text_split) // Line loop
{
line = line.removeBackspaces()
.removeDel()
.replaceControlCodes()
.rtrim();
const auto column_width = getColumnWidth(line);

if ( column_width > max_line_width )
{
max_line_width = column_width;

if ( column_width > getTextWidth() )
{
const int hmax = ( max_line_width > getTextWidth() )
? int(max_line_width) - int(getTextWidth())
: 0;
hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getTextWidth()));
hbar->calculateSliderValues();
showHorizontallyScrollable();
}
}

data.emplace (data.cbegin() + pos, std::move(line));
processLine(std::move(line), pos);
pos++;
}

const int vmax = ( getRows() > getTextHeight() )
? int(getRows()) - int(getTextHeight())
: 0;
vbar->setMaximum (vmax);
vbar->setPageSize (int(getRows()), int(getTextHeight()));
vbar->calculateSliderValues();

if ( isShown() && ! vbar->isShown() && isVerticallyScrollable() )
vbar->show();

if ( isShown() && vbar->isShown() && ! isVerticallyScrollable() )
vbar->hide();

updateVerticalScrollBar();
processChanged();
}

Expand Down Expand Up @@ -689,6 +635,71 @@ inline auto FTextView::isPrintable (wchar_t ch) const -> bool
|| (! utf8 && std::isprint(char(ch))) );
}

//----------------------------------------------------------------------
inline auto FTextView::splitTextLines (const FString& str) const -> FStringList
{
if ( str.isEmpty() )
{
FStringList list{};
list.emplace_back("");
return list;
}

const auto& string = str.rtrim().expandTabs(getFOutput()->getTabstop());
return string.split("\n");
}

//----------------------------------------------------------------------
inline void FTextView::processLine (FString&& line, int pos)
{
line = line.removeBackspaces()
.removeDel()
.replaceControlCodes()
.rtrim();

data.emplace (data.cbegin() + pos, std::move(line));
updateHorizontalScrollBar (getColumnWidth(line));
}

//----------------------------------------------------------------------
inline void FTextView::updateVerticalScrollBar()
{
const int vmax = ( getRows() > getTextHeight() )
? int(getRows()) - int(getTextHeight())
: 0;
vbar->setMaximum (vmax);
vbar->setPageSize (int(getRows()), int(getTextHeight()));
vbar->calculateSliderValues();

if ( isShown() && ! vbar->isShown() && isVerticallyScrollable() )
vbar->show();

if ( isShown() && vbar->isShown() && ! isVerticallyScrollable() )
vbar->hide();
}

//----------------------------------------------------------------------
inline void FTextView::updateHorizontalScrollBar (std::size_t column_width)
{
if ( column_width <= max_line_width )
return;

max_line_width = column_width;

if ( column_width <= getTextWidth() )
return;

const int hmax = ( max_line_width > getTextWidth() )
? int(max_line_width) - int(getTextWidth())
: 0;
hbar->setMaximum (hmax);
hbar->setPageSize (int(max_line_width), int(getTextWidth()));
hbar->calculateSliderValues();

if ( isShown() && isHorizontallyScrollable() )
hbar->show();
}

//----------------------------------------------------------------------
void FTextView::processChanged() const
{
Expand Down
4 changes: 4 additions & 0 deletions final/widget/ftextview.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ class FTextView : public FWidget
, const std::vector<FTextHighlight>& );
auto useFDialogBorder() const -> bool;
auto isPrintable (wchar_t) const -> bool;
auto splitTextLines (const FString&) const -> FStringList;
void processLine (FString&&, int);
void updateVerticalScrollBar();
void updateHorizontalScrollBar (std::size_t);
void processChanged() const;
void changeOnResize() const;

Expand Down
2 changes: 1 addition & 1 deletion test/fkeyboard-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3171,7 +3171,7 @@ void FKeyboardTest::init()
// Copy the section with the fixed escape sequences
auto& fkey_cap_table = finalcut::FKeyMap::getInstance().getKeyCapMap();
std::size_t first = 150;
std::size_t last = fkey_cap_table.size();
std::size_t last = fkey_cap_table.size() - 1;
assert ( last > first );
std::copy ( &fkey_cap_table[first].num, &fkey_cap_table[last].num, &test::fkey[first].num);

Expand Down

0 comments on commit 3e24a01

Please sign in to comment.