1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 03:45:56 +01:00

Don't crash when adding new columns to a stretch header view.

Fixes issue 2562
This commit is contained in:
David Sansome 2012-01-04 18:45:08 +00:00
parent 11619c9484
commit bfd725f2ed
3 changed files with 16 additions and 3 deletions

View File

@ -89,6 +89,7 @@ PlaylistView::PlaylistView(QWidget *parent)
setting_initial_header_layout_(false), setting_initial_header_layout_(false),
upgrading_from_qheaderview_(false), upgrading_from_qheaderview_(false),
read_only_settings_(true), read_only_settings_(true),
upgrading_from_version_(-1),
glow_enabled_(true), glow_enabled_(true),
currently_glowing_(false), currently_glowing_(false),
glow_intensity_step_(0), glow_intensity_step_(0),
@ -255,6 +256,8 @@ void PlaylistView::LoadGeometry() {
// New columns that we add are visible by default if the user has upgraded // New columns that we add are visible by default if the user has upgraded
// Clementine. Hide them again here // Clementine. Hide them again here
const int state_version = settings.value("state_version", 0).toInt(); const int state_version = settings.value("state_version", 0).toInt();
upgrading_from_version_ = state_version;
if (state_version < 1) { if (state_version < 1) {
header_->HideSection(Playlist::Column_Rating); header_->HideSection(Playlist::Column_Rating);
header_->HideSection(Playlist::Column_PlayCount); header_->HideSection(Playlist::Column_PlayCount);
@ -267,9 +270,6 @@ void PlaylistView::LoadGeometry() {
if (state_version < 3) { if (state_version < 3) {
header_->HideSection(Playlist::Column_Comment); header_->HideSection(Playlist::Column_Comment);
} }
if (state_version < 4) {
header_->SetColumnWidth(Playlist::Column_Source, 0.05);
}
// Make sure at least one column is visible // Make sure at least one column is visible
bool all_hidden = true; bool all_hidden = true;
@ -898,6 +898,13 @@ void PlaylistView::ReloadSettings() {
setting_initial_header_layout_ = false; setting_initial_header_layout_ = false;
} }
if (upgrading_from_version_ != -1) {
if (upgrading_from_version_ < 4) {
header_->SetColumnWidth(Playlist::Column_Source, 0.05);
}
upgrading_from_version_ = -1;
}
column_alignment_ = s.value("column_alignments").value<ColumnAlignmentMap>(); column_alignment_ = s.value("column_alignments").value<ColumnAlignmentMap>();
if (column_alignment_.isEmpty()) { if (column_alignment_.isEmpty()) {
column_alignment_ = DefaultColumnAlignment(); column_alignment_ = DefaultColumnAlignment();

View File

@ -168,6 +168,7 @@ class PlaylistView : public QTreeView {
bool setting_initial_header_layout_; bool setting_initial_header_layout_;
bool upgrading_from_qheaderview_; bool upgrading_from_qheaderview_;
bool read_only_settings_; bool read_only_settings_;
int upgrading_from_version_;
bool background_enabled_; bool background_enabled_;

View File

@ -271,6 +271,11 @@ bool StretchHeaderView::RestoreState(const QByteArray& data) {
} }
} }
// Have we added more columns since the last time?
while (column_widths_.count() < count()) {
column_widths_ << 0;
}
if (stretch_enabled_) { if (stretch_enabled_) {
// In stretch mode, we've already set the proportional column widths so apply // In stretch mode, we've already set the proportional column widths so apply
// them now. // them now.