Skip to content

Commit

Permalink
Added YQPkgSecondaryFilterView base class
Browse files Browse the repository at this point in the history
For sharing the functionality for the views containing a secondary filter
  • Loading branch information
lslezak committed Jun 29, 2018
1 parent e673918 commit 964ff0d
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 508 deletions.
2 changes: 2 additions & 0 deletions SOURCECONF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SET( ${TARGETLIB}_SOURCES
YQPkgRepoList.cc
YQPkgRpmGroupTagsFilterView.cc
YQPkgSearchFilterView.cc
YQPkgSecondaryFilterView.cc
YQPkgSelDescriptionView.cc
YQPkgSelMapper.cc
YQPkgServiceFilterView.cc
Expand Down Expand Up @@ -83,6 +84,7 @@ SET( ${TARGETLIB}_HEADERS
YQPkgRepoList.h
YQPkgRpmGroupTagsFilterView.h
YQPkgSearchFilterView.h
YQPkgSecondaryFilterView.h
YQPkgSelDescriptionView.h
YQPkgSelList.h
YQPkgSelMapper.h
Expand Down
179 changes: 5 additions & 174 deletions src/YQPkgRepoFilterView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "YQPkgSearchFilterView.h"
#include "YQPkgStatusFilterView.h"
#include "YQi18n.h"
#include "YQZypp.h"


YQPkgRepoFilterView::YQPkgRepoFilterView( QWidget * parent )
: QWidget( parent )
: YQPkgSecondaryFilterView( parent )
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0,0,0,0);

QSplitter * splitter = new QSplitter( Qt::Vertical, this );
YUI_CHECK_NEW( splitter );

layout->addWidget( splitter );

_repoList = new YQPkgRepoList( this );
splitter->addWidget(_repoList);

YUI_CHECK_NEW( _repoList );
_repoList->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert

// Directly propagate signals filterStart() and filterFinished()
// from primary filter to the outside

connect( _repoList, SIGNAL( filterStart() ),
this, SIGNAL( filterStart() ) );

connect( _repoList, SIGNAL( filterFinished() ),
this, SIGNAL( filterFinished() ) );


// Redirect filterMatch() and filterNearMatch() signals to secondary filter

connect( _repoList, SIGNAL( filterMatch ( ZyppSel, ZyppPkg ) ),
this, SLOT ( primaryFilterMatch ( ZyppSel, ZyppPkg ) ) );

connect( _repoList, SIGNAL( filterNearMatch ( ZyppSel, ZyppPkg ) ),
this, SLOT ( primaryFilterNearMatch ( ZyppSel, ZyppPkg ) ) );

layoutSecondaryFilters( splitter );

splitter->setStretchFactor(0, 5);
splitter->setStretchFactor(1, 1);
splitter->setStretchFactor(2, 3);


init(_repoList);
}


Expand All @@ -116,149 +81,15 @@ YQPkgRepoFilterView::selectedRepo() const
return zypp::Repository::noRepository;
}

QWidget *
YQPkgRepoFilterView::layoutSecondaryFilters( QWidget * parent )
{
QWidget *vbox = new QWidget( parent );
YUI_CHECK_NEW( vbox );

QVBoxLayout *layout = new QVBoxLayout();
YUI_CHECK_NEW( layout );

vbox->setLayout( layout );
layout->setContentsMargins( 0, 0, 0, 0 );

// Translators: This is a combo box where the user can apply a secondary filter
// in addition to the primary filter by repository - one of
// "All packages", "RPM groups", "search", "summary"
//
// And yes, the colon really belongs there since this is one of the very
// few cases where a combo box label is left to the combo box rather than
// above it.
_secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ));
YUI_CHECK_NEW( _secondaryFilters );
layout->addWidget(_secondaryFilters);

//
// All Packages
//

_allPackages = new QWidget( this );
YUI_CHECK_NEW( _allPackages );
_secondaryFilters->addPage( _( "All Packages" ), _allPackages );


// Unmaintaned packages: Packages that are not provided in any of
// the configured repositories

_unmaintainedPackages = new QWidget( this );
YUI_CHECK_NEW( _unmaintainedPackages );
_secondaryFilters->addPage( _( "Unmaintained Packages" ), _unmaintainedPackages );

//
// RPM Groups
//

_rpmGroupTagsFilterView = new YQPkgRpmGroupTagsFilterView( this );
YUI_CHECK_NEW( _rpmGroupTagsFilterView );
_secondaryFilters->addPage( _( "Package Groups" ), _rpmGroupTagsFilterView );

connect( _rpmGroupTagsFilterView, SIGNAL( filterStart() ),
_repoList, SLOT ( filter() ) );


//
// Package search view
//

_searchFilterView = new YQPkgSearchFilterView( this );
YUI_CHECK_NEW( _searchFilterView );
_secondaryFilters->addPage( _( "Search" ), _searchFilterView );

connect( _searchFilterView, SIGNAL( filterStart() ),
_repoList, SLOT ( filter() ) );

connect( _secondaryFilters, &QY2ComboTabWidget::currentChanged,
this, &YQPkgRepoFilterView::filter );


//
// Status change view
//

_statusFilterView = new YQPkgStatusFilterView( parent );
YUI_CHECK_NEW( _statusFilterView );
_secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );

connect( _statusFilterView, SIGNAL( filterStart() ),
_repoList, SLOT ( filter() ) );


return _secondaryFilters;
}


void YQPkgRepoFilterView::filter()
void YQPkgRepoFilterView::primaryFilter()
{
_repoList->filter();
}


void YQPkgRepoFilterView::filterIfVisible()
void YQPkgRepoFilterView::primaryFilterIfVisible()
{
_repoList->filterIfVisible();
}


void YQPkgRepoFilterView::primaryFilterMatch( ZyppSel selectable,
ZyppPkg pkg )
{
if ( secondaryFilterMatch( selectable, pkg ) )
emit filterMatch( selectable, pkg );
}


void YQPkgRepoFilterView::primaryFilterNearMatch( ZyppSel selectable,
ZyppPkg pkg )
{
if ( secondaryFilterMatch( selectable, pkg ) )
emit filterNearMatch( selectable, pkg );
}


bool
YQPkgRepoFilterView::secondaryFilterMatch( ZyppSel selectable,
ZyppPkg pkg )
{
if ( _allPackages->isVisible() )
{
return true;
}
else if ( _unmaintainedPackages->isVisible() )
{
return ( selectable->availableSize() == 0 );
}
else if ( _rpmGroupTagsFilterView->isVisible() )
{
return _rpmGroupTagsFilterView->check( selectable, pkg );
}
else if ( _searchFilterView->isVisible() )
{
return _searchFilterView->check( selectable, pkg );
}
else if ( _statusFilterView->isVisible() )
{
return _statusFilterView->check( selectable, pkg );
}
else
{
return true;
}
}






#include "YQPkgRepoFilterView.moc"
91 changes: 5 additions & 86 deletions src/YQPkgRepoFilterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef YQPkgRepoFilterView_h
#define YQPkgRepoFilterView_h

#include "YQZypp.h"
#include <QWidget>

#include "YQPkgSecondaryFilterView.h"

class QWidget;
class YQPkgRepoList;
class QY2ComboTabWidget;
class YQPkgRpmGroupTagsFilterView;
class YQPkgSearchFilterView;
class YQPkgStatusFilterView;


class YQPkgRepoFilterView : public QWidget
class YQPkgRepoFilterView : public YQPkgSecondaryFilterView
{
Q_OBJECT

Expand All @@ -73,89 +67,14 @@ class YQPkgRepoFilterView : public QWidget
*/
zypp::Repository selectedRepo() const;

signals:

/**
* Emitted when the filtering starts. Use this to clear package lists
* etc. prior to adding new entries.
**/
void filterStart();

/**
* Emitted during filtering for each pkg that matches the filter
* and the candidate package comes from the respective repository
**/
void filterMatch( ZyppSel selectable,
ZyppPkg pkg );

/**
* Emitted during filtering for each pkg that matches the filter
* and the candidate package does not come from the respective repository
**/
void filterNearMatch( ZyppSel selectable,
ZyppPkg pkg );

/**
* Emitted when filtering is finished.
**/
void filterFinished();

public slots:

/**
* Filter according to the view's rules and current selection.
* Emits those signals:
* filterStart()
* filterMatch() for each pkg that matches the filter
* filterFinished()
**/
void filter();

/**
* Same as filter(), but only if this widget is currently visible.
**/
void filterIfVisible();


protected slots:

/**
* Propagate a filter match from the primary filter
* and appy any selected secondary filter(s) to it
**/
void primaryFilterMatch( ZyppSel selectable,
ZyppPkg pkg );

/**
* Propagate a filter near match from the primary filter
* and appy any selected secondary filter(s) to it
**/
void primaryFilterNearMatch( ZyppSel selectable,
ZyppPkg pkg );

protected:

/**
* Widget layout for the secondary filters
**/
QWidget * layoutSecondaryFilters( QWidget * parent );

/**
* Check if pkg matches the the currently selected secondary filter
**/
bool secondaryFilterMatch( ZyppSel selectable,
ZyppPkg pkg );

virtual void primaryFilter();
virtual void primaryFilterIfVisible();

// Data members

YQPkgRepoList * _repoList;
QY2ComboTabWidget * _secondaryFilters;
QWidget * _allPackages;
QWidget *_unmaintainedPackages;
YQPkgRpmGroupTagsFilterView * _rpmGroupTagsFilterView;
YQPkgSearchFilterView * _searchFilterView;
YQPkgStatusFilterView * _statusFilterView;
};


Expand Down
Loading

0 comments on commit 964ff0d

Please sign in to comment.