Skip to content

Commit

Permalink
Performance optimization of tables rendering + resize strategy choice…
Browse files Browse the repository at this point in the history
… robustness dvorka#910
  • Loading branch information
dvorka committed Mar 3, 2019
1 parent 9f604a4 commit 5f0c64d
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 91 deletions.
20 changes: 8 additions & 12 deletions app/src/qt/assoc_leaderboard_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AssocLeaderboardView::AssocLeaderboardView(QWidget* parent)
verticalHeader()->setVisible(false);
// BEFARE this kills performance: verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

// IMPORTANT this must be in constructors - causes CPU high consuption loop if in paintEvent()!
// IMPORTANT this must be in constructors - causes CPU high consuption loop if in an event handler
verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);

setSortingEnabled(false);
Expand All @@ -36,24 +36,20 @@ AssocLeaderboardView::AssocLeaderboardView(QWidget* parent)
setSelectionMode(QAbstractItemView::SingleSelection);
}

AssocLeaderboardView::~AssocLeaderboardView()
void AssocLeaderboardView::resizeEvent(QResizeEvent* event)
{
}

void AssocLeaderboardView::paintEvent(QPaintEvent* event)
{
MF_DEBUG("AssocLeaderboardView::paintEvent" << event << std::endl);

// ensure that 1st column gets the remaining space from others
// IMPROVE may kill performance
this->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
MF_DEBUG("AssocLeaderboardView::resizeEvent " << event << std::endl);

if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

// % associativity
this->setColumnWidth(1, this->fontMetrics().averageCharWidth()*12);

QTableView::paintEvent(event);
QTableView::resizeEvent(event);
}

} // m8r namespace
4 changes: 2 additions & 2 deletions app/src/qt/assoc_leaderboard_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class AssocLeaderboardView : public QTableView
AssocLeaderboardView(const AssocLeaderboardView&&) = delete;
AssocLeaderboardView &operator=(const AssocLeaderboardView&) = delete;
AssocLeaderboardView &operator=(const AssocLeaderboardView&&) = delete;
~AssocLeaderboardView();
virtual ~AssocLeaderboardView() override {}

virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
};

}
Expand Down
20 changes: 8 additions & 12 deletions app/src/qt/ner_leaderboard_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ NerLeaderboardView::NerLeaderboardView(QWidget* parent)
verticalHeader()->setVisible(false);
// BEFARE this kills performance: verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

// IMPORTANT this must b in constructors - causes CPU high consuption loop if in paintEvent()!
// IMPORTANT this must b in constructors - causes CPU high consuption loop if in an event handler
verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);

setSortingEnabled(true);
Expand All @@ -40,26 +40,22 @@ NerLeaderboardView::NerLeaderboardView(QWidget* parent)
setItemDelegate(delegate);
}

NerLeaderboardView::~NerLeaderboardView()
void NerLeaderboardView::resizeEvent(QResizeEvent* event)
{
}

void NerLeaderboardView::paintEvent(QPaintEvent* event)
{
MF_DEBUG("NerLeaderboardView::paintEvent" << event << std::endl);

// ensure that 1st column gets the remaining space from others
// IMPROVE may kill performance
this->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
MF_DEBUG("NerLeaderboardView::resizeEvent " << event << std::endl);

if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

// type
this->setColumnWidth(1, this->fontMetrics().averageCharWidth()*15);
// %
this->setColumnWidth(2, this->fontMetrics().averageCharWidth()*12);

QTableView::paintEvent(event);
QTableView::resizeEvent(event);
}

} // m8r namespace
4 changes: 2 additions & 2 deletions app/src/qt/ner_leaderboard_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class NerLeaderboardView : public QTableView
NerLeaderboardView(const NerLeaderboardView&&) = delete;
NerLeaderboardView &operator=(const NerLeaderboardView&) = delete;
NerLeaderboardView &operator=(const NerLeaderboardView&&) = delete;
~NerLeaderboardView();
virtual ~NerLeaderboardView() override {}

virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
};

}
Expand Down
7 changes: 4 additions & 3 deletions app/src/qt/notes_table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ NotesTableView::NotesTableView(QWidget *parent)

verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

QHeaderView* header = this->horizontalHeader();
// IMPORTANT resize mode MUST NOT be set in paintEvent, otherwise it causes high CPU consumption loop
header->setSectionResizeMode(QHeaderView::Stretch);
if(horizontalHeader()->length() > 0) {
// IMPORTANT resize mode MUST NOT be set in paint event, otherwise it causes high CPU consumption loop
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
}

} // m8r namespace
10 changes: 0 additions & 10 deletions app/src/qt/organizer_quadrant_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,4 @@ OrganizerQuadrantView::OrganizerQuadrantView(QWidget* parent)
setSelectionMode(QAbstractItemView::SingleSelection);
}

OrganizerQuadrantView::~OrganizerQuadrantView()
{
}

void OrganizerQuadrantView::paintEvent(QPaintEvent* event)
{
MF_DEBUG("OrganizerQuadrantView::paintEvent" << event << std::endl);
QTableView::paintEvent(event);
}

} // m8r namespace
4 changes: 1 addition & 3 deletions app/src/qt/organizer_quadrant_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class OrganizerQuadrantView : public QTableView
OrganizerQuadrantView(const OrganizerQuadrantView&&) = delete;
OrganizerQuadrantView &operator=(const OrganizerQuadrantView&) = delete;
OrganizerQuadrantView &operator=(const OrganizerQuadrantView&&) = delete;
~OrganizerQuadrantView();

virtual void paintEvent(QPaintEvent* event) override;
virtual ~OrganizerQuadrantView() {}
};

}
Expand Down
15 changes: 7 additions & 8 deletions app/src/qt/outline_tree_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ OutlineTreeView::OutlineTreeView(QWidget* parent)
// disable TAB and Ctrl+O up/down navigation (Ctrl+O no longer bound)
setTabKeyNavigation(false);

// BEVARE: this call cannot go paint() otherwise leads to loop and crazy CPU
verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
}

Expand Down Expand Up @@ -107,14 +106,14 @@ void OutlineTreeView::keyPressEvent(QKeyEvent* event)
QWidget::keyPressEvent(event);
}

void OutlineTreeView::paintEvent(QPaintEvent* event)
void OutlineTreeView::resizeEvent(QResizeEvent* event)
{
MF_DEBUG("OutlineTreeView::paintEvent" << event << std::endl);

// SUSPECTED to cause high CPU consumption due paint() event loop
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
MF_DEBUG("OutlineTreeView::resizeEvent " << event << std::endl);

if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

int normalizedWidth = width()/fontMetrics().averageCharWidth();
Expand All @@ -133,7 +132,7 @@ void OutlineTreeView::paintEvent(QPaintEvent* event)
// pretty
this->setColumnWidth(4, this->fontMetrics().averageCharWidth()*12);

QTableView::paintEvent(event);
QTableView::resizeEvent(event);
}

} // m8r namespace
2 changes: 1 addition & 1 deletion app/src/qt/outline_tree_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class OutlineTreeView : public QTableView
OutlineTreeView &operator=(const OutlineTreeView&&) = delete;

virtual void keyPressEvent(QKeyEvent* event) override;
virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
void refreshNotes(const QModelIndex& from, const QModelIndex& to) { dataChanged(from, to); }

signals:
Expand Down
11 changes: 5 additions & 6 deletions app/src/qt/outlines_table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ OutlinesTableView::OutlinesTableView(QWidget *parent)
// BEFARE ::ResizeToContents this kills performance - use ::Fixed instead:
// verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// IMPORTANT resize mode MUST NOT be set in paintEvent, otherwise it causes high CPU consumption loop

setSortingEnabled(true);

Expand All @@ -41,12 +40,12 @@ OutlinesTableView::OutlinesTableView(QWidget *parent)

void OutlinesTableView::resizeEvent(QResizeEvent* event)
{
MF_DEBUG("OutlinesTableView::resizeEvent" << event << std::endl);

// ensure that 1st column gets the remaining space from others
// IMPROVE may kill performance
this->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
MF_DEBUG("OutlinesTableView::resizeEvent " << event << std::endl);

if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

// importance/urgency
Expand Down
1 change: 1 addition & 0 deletions app/src/qt/outlines_table_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OutlinesTableView : public QTableView
OutlinesTableView(const OutlinesTableView&&) = delete;
OutlinesTableView &operator=(const OutlinesTableView&) = delete;
OutlinesTableView &operator=(const OutlinesTableView&&) = delete;
virtual ~OutlinesTableView() override {}

int getColumnCount() { return COLUMN_COUNT; }

Expand Down
19 changes: 7 additions & 12 deletions app/src/qt/recent_notes_table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@ RecentNotesTableView::RecentNotesTableView(QWidget* parent)
setSelectionMode(QAbstractItemView::SingleSelection);
}

RecentNotesTableView::~RecentNotesTableView()
void RecentNotesTableView::resizeEvent(QResizeEvent* event)
{
}

void RecentNotesTableView::paintEvent(QPaintEvent* event)
{
MF_DEBUG("RecentNotesTableView::paintEvent" << event << std::endl);
MF_DEBUG("RecentNotesTableView::resizeEvent " << event << std::endl);

// ensure that 1st column gets the remaining space from others
// IMPROVE may kill performance
this->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

// N
if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

// O
Expand All @@ -65,7 +60,7 @@ void RecentNotesTableView::paintEvent(QPaintEvent* event)
// pretty
this->setColumnWidth(5, this->fontMetrics().averageCharWidth()*12);

QTableView::paintEvent(event);
QTableView::resizeEvent(event);
}

} // m8r namespace
4 changes: 2 additions & 2 deletions app/src/qt/recent_notes_table_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class RecentNotesTableView : public QTableView
RecentNotesTableView(const RecentNotesTableView&&) = delete;
RecentNotesTableView &operator=(const RecentNotesTableView&) = delete;
RecentNotesTableView &operator=(const RecentNotesTableView&&) = delete;
~RecentNotesTableView();
virtual ~RecentNotesTableView() override {}

virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
};

}
Expand Down
18 changes: 7 additions & 11 deletions app/src/qt/tags_table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@ TagsTableView::TagsTableView(QWidget* parent)
setSelectionMode(QAbstractItemView::SingleSelection);
}

TagsTableView::~TagsTableView()
void TagsTableView::resizeEvent(QResizeEvent* event)
{
}

void TagsTableView::paintEvent(QPaintEvent* event)
{
MF_DEBUG("TagsTableView::paintEvent" << event << std::endl);

// ensure that 1st column gets the remaining space from others
// IMPROVE may kill performance
this->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
MF_DEBUG("TagsTableView::resizeEvent " << event << std::endl);

if(horizontalHeader()->length() > 0) {
// ensure that 1st column gets the remaining space from others
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
verticalHeader()->setDefaultSectionSize(fontMetrics().height()*1.5);

// cardinality
this->setColumnWidth(1, this->fontMetrics().averageCharWidth()*6);

QTableView::paintEvent(event);
QTableView::resizeEvent(event);
}

} // m8r namespace
4 changes: 2 additions & 2 deletions app/src/qt/tags_table_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class TagsTableView : public QTableView
TagsTableView(const TagsTableView&&) = delete;
TagsTableView &operator=(const TagsTableView&) = delete;
TagsTableView &operator=(const TagsTableView&&) = delete;
~TagsTableView();
virtual ~TagsTableView() override {}

virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
};

}
Expand Down
6 changes: 2 additions & 4 deletions app/src/qt/widgets/line_number_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ LineNumberPanel::LineNumberPanel(NoteEditorView* editor)
mdEditor = editor;
}

LineNumberPanel::~LineNumberPanel()
{
}

QSize LineNumberPanel::sizeHint() const
{
return QSize(mdEditor->lineNumberPanelWidth(), 0);
Expand All @@ -40,6 +36,8 @@ void LineNumberPanel::paintEvent(QPaintEvent* event)
MF_DEBUG("LineNumberPanel::paintEvent" << event << std::endl);

mdEditor->lineNumberPanelPaintEvent(event);

QWidget::paintEvent(event);
}

}
2 changes: 1 addition & 1 deletion app/src/qt/widgets/line_number_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LineNumberPanel : public QWidget
LineNumberPanel(const LineNumberPanel&&) = delete;
LineNumberPanel &operator=(const LineNumberPanel&) = delete;
LineNumberPanel &operator=(const LineNumberPanel&&) = delete;
~LineNumberPanel();
virtual ~LineNumberPanel() override {}

QSize sizeHint() const override;

Expand Down

0 comments on commit 5f0c64d

Please sign in to comment.