Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PersistentCopy(). #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/filtersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FiltersDialog::FiltersDialog( QWidget* parent ) : QDialog( parent )
// Reload the filter list from disk (in case it has been changed
// by another glogg instance) and copy it to here.
GetPersistentInfo().retrieve( "filterSet" );
filterSet = PersistentCopy<FilterSet>( "filterSet" );
filterSet = *Persistent<FilterSet>( "filterSet" );

populateColors();
populateFilterList();
Expand Down Expand Up @@ -69,7 +69,7 @@ FiltersDialog::FiltersDialog( QWidget* parent ) : QDialog( parent )
connect( backColorBox, SIGNAL( activated( int ) ),
this, SLOT( updateFilterProperties() ) );

if ( !filterSet->filterList.empty() ) {
if ( !filterSet.filterList.empty() ) {
filterListWidget->setCurrentItem( filterListWidget->item( 0 ) );
}
}
Expand All @@ -84,7 +84,7 @@ void FiltersDialog::on_addFilterButton_clicked()

Filter newFilter = Filter( DEFAULT_PATTERN, DEFAULT_IGNORE_CASE,
DEFAULT_FORE_COLOUR, DEFAULT_BACK_COLOUR );
filterSet->filterList << newFilter;
filterSet.filterList << newFilter;

// Add and select the newly created filter
filterListWidget->addItem( DEFAULT_PATTERN );
Expand All @@ -97,7 +97,7 @@ void FiltersDialog::on_removeFilterButton_clicked()
LOG(logDEBUG) << "on_removeFilterButton_clicked() index " << index;

if ( index >= 0 ) {
filterSet->filterList.removeAt( index );
filterSet.filterList.removeAt( index );
filterListWidget->setCurrentRow( -1 );
delete filterListWidget->takeItem( index );

Expand All @@ -112,7 +112,7 @@ void FiltersDialog::on_upFilterButton_clicked()
LOG(logDEBUG) << "on_upFilterButton_clicked() index " << index;

if ( index > 0 ) {
filterSet->filterList.move( index, index - 1 );
filterSet.filterList.move( index, index - 1 );

QListWidgetItem* item = filterListWidget->takeItem( index );
filterListWidget->insertItem( index - 1, item );
Expand All @@ -126,7 +126,7 @@ void FiltersDialog::on_downFilterButton_clicked()
LOG(logDEBUG) << "on_downFilterButton_clicked() index " << index;

if ( ( index >= 0 ) && ( index < ( filterListWidget->count() - 1 ) ) ) {
filterSet->filterList.move( index, index + 1 );
filterSet.filterList.move( index, index + 1 );

QListWidgetItem* item = filterListWidget->takeItem( index );
filterListWidget->insertItem( index + 1, item );
Expand All @@ -142,7 +142,7 @@ void FiltersDialog::on_buttonBox_clicked( QAbstractButton* button )
if ( ( role == QDialogButtonBox::AcceptRole )
|| ( role == QDialogButtonBox::ApplyRole ) ) {
// Copy the filter set and persist it to disk
*( Persistent<FilterSet>( "filterSet" ) ) = *filterSet;
*( Persistent<FilterSet>( "filterSet" ) ) = filterSet;
GetPersistentInfo().save( "filterSet" );
emit optionsChanged();
}
Expand All @@ -164,7 +164,7 @@ void FiltersDialog::updatePropertyFields()
LOG(logDEBUG) << "updatePropertyFields(), row = " << selectedRow_;

if ( selectedRow_ >= 0 ) {
const Filter& currentFilter = filterSet->filterList.at( selectedRow_ );
const Filter& currentFilter = filterSet.filterList.at( selectedRow_ );

patternEdit->setText( currentFilter.pattern() );
patternEdit->setEnabled( true );
Expand Down Expand Up @@ -206,7 +206,7 @@ void FiltersDialog::updateFilterProperties()

// If a row is selected
if ( selectedRow_ >= 0 ) {
Filter& currentFilter = filterSet->filterList[selectedRow_];
Filter& currentFilter = filterSet.filterList[selectedRow_];

// Update the internal data
currentFilter.setPattern( patternEdit->text() );
Expand Down Expand Up @@ -292,7 +292,7 @@ void FiltersDialog::populateColors()
void FiltersDialog::populateFilterList()
{
filterListWidget->clear();
foreach ( Filter filter, filterSet->filterList ) {
foreach ( Filter filter, filterSet.filterList ) {
QListWidgetItem* new_item = new QListWidgetItem( filter.pattern() );
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
new_item->setForeground( QBrush( QColor( filter.foreColorName() ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/filtersdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FiltersDialog : public QDialog, public Ui::FiltersDialog
private:
// Temporary filterset modified by the dialog
// it is copied from the one in Config()
std::shared_ptr<FilterSet> filterSet;
FilterSet filterSet;

// Index of the row currently selected or -1 if none.
int selectedRow_;
Expand Down
8 changes: 0 additions & 8 deletions src/persistentinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,4 @@ std::shared_ptr<T> Persistent( const char* name )
GetPersistentInfo().getPersistable( QString( name ) );
return std::dynamic_pointer_cast<T>(p);
}

template<typename T>
std::shared_ptr<T> PersistentCopy( const char* name )
{
std::shared_ptr<Persistable> p =
GetPersistentInfo().getPersistable( QString( name ) );
return std::make_shared<T>( *( std::dynamic_pointer_cast<T>(p) ) );
}
#endif