Commit 8e1042dd authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Martin Tobias Holmedahl Sandsmark
Browse files

Fix searching for sensors which aren't visible

parent 902e5bc7
......@@ -37,7 +37,6 @@ ki18n_wrap_ui( libsensordisplays_SRCS
)
set(ksysguard_KDEINIT_SRCS ${libsensordisplays_SRCS}
ksortfilterproxymodel.cpp
SensorBrowser.cpp
WorkSheet.cpp
WorkSheetSettings.cpp
......
......@@ -424,14 +424,15 @@ SensorBrowserWidget::~SensorBrowserWidget()
SensorBrowserTreeWidget::SensorBrowserTreeWidget( QWidget* parent, KSGRD::SensorManager* sm ) : QTreeView( parent ), mSensorManager( sm )
{
mSortFilterProxyModel.setSourceModel(&mSensorBrowserModel);
mSortFilterProxyModel.setShowAllChildren(true);
mSortFilterProxyModel.setRecursiveFilteringEnabled(true);
mSortFilterProxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
setModel(&mSortFilterProxyModel);
connect(mSensorManager, &KSGRD::SensorManager::update, &mSensorBrowserModel, &SensorBrowserModel::update);
connect(mSensorManager, &KSGRD::SensorManager::hostAdded, &mSensorBrowserModel, &SensorBrowserModel::hostAdded);
connect(mSensorManager, &KSGRD::SensorManager::hostConnectionLost, &mSensorBrowserModel, &SensorBrowserModel::hostRemoved);
// connect( mSensorManager, SIGNAL(hostAdded(KSGRD::SensorAgent*,QString)), SLOT(updateView()) );
// connect( mSensorManager, SIGNAL(hostConnectionLost(QString)), SLOT(updateView()) );
connect(&mSortFilterProxyModel, &KSortFilterProxyModel::rowsInserted, this, &SensorBrowserTreeWidget::updateView);
connect(&mSortFilterProxyModel, &QSortFilterProxyModel::rowsInserted, this, &SensorBrowserTreeWidget::updateView);
setDragDropMode(QAbstractItemView::DragOnly);
setUniformRowHeights(true);
......
......@@ -28,7 +28,7 @@
#include <QMap>
#include <QHash>
#include <ksgrd/SensorClient.h>
#include "ksortfilterproxymodel.h"
#include <QSortFilterProxyModel>
class QMouseEvent;
......@@ -111,7 +111,7 @@ class SensorBrowserTreeWidget : public QTreeView
{ return mSensorBrowserModel.listHosts(); }
QStringList listSensors( const QString &hostName ) const
{ return mSensorBrowserModel.listSensors(hostName); }
KSortFilterProxyModel & model()
QSortFilterProxyModel & model()
{ return mSortFilterProxyModel; }
public Q_SLOTS:
......@@ -128,7 +128,7 @@ class SensorBrowserTreeWidget : public QTreeView
QString mDragText;
SensorBrowserModel mSensorBrowserModel;
KSortFilterProxyModel mSortFilterProxyModel;
QSortFilterProxyModel mSortFilterProxyModel;
};
/**
......
/*
* Copyright (C) 2007-2008 Omat Holding B.V. <info@omat.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "ksortfilterproxymodel.h"
/**
* Private class that helps to provide binary compatibility between releases.
* @internal
*/
//@cond PRIVATE
class KSortFilterProxyModelPrivate {
public:
KSortFilterProxyModelPrivate() {
}
~KSortFilterProxyModelPrivate() {}
bool showAllChildren = false;
};
KSortFilterProxyModel::KSortFilterProxyModel(QObject * parent)
: QSortFilterProxyModel(parent), d_ptr( new KSortFilterProxyModelPrivate )
{
}
KSortFilterProxyModel::~KSortFilterProxyModel()
{
delete d_ptr;
}
bool KSortFilterProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
{
if( filterRegExp().isEmpty() ) return true; //Shortcut for common case
if( QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) )
return true;
//one of our children might be accepted, so accept this row if one of our children are accepted.
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
for(int i = 0 ; i < sourceModel()->rowCount(source_index); i++) {
if(filterAcceptsRow(i, source_index)) return true;
}
//one of our parents might be accepted, so accept this row if one of our parents is accepted.
if(d_ptr->showAllChildren) {
QModelIndex parent_index = source_parent;
while(parent_index.isValid()) {
int row = parent_index.row();
parent_index = parent_index.parent();
if(QSortFilterProxyModel::filterAcceptsRow(row, parent_index)) return true;
}
}
return false;
}
bool KSortFilterProxyModel::showAllChildren() const
{
return d_ptr->showAllChildren;
}
void KSortFilterProxyModel::setShowAllChildren(bool showAllChildren)
{
if(showAllChildren == d_ptr->showAllChildren)
return;
d_ptr->showAllChildren = showAllChildren;
invalidateFilter();
}
/*
* Copyright (C) 2009 John Tapsell <tapsell@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KSORTFILTERPROXYMODEL_H
#define KSORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
/**
* @class KSortFilterProxyModel
*
* This class extends QSortFilterProxyModel to allow filtering for a matching child
* in a tree.
* It can also show all the children of a matching parent, if setShowAllChildren is set.
*
* @author John Tapsell <tapsell@kde.org>
* @since 4.4
*/
class KSortFilterProxyModelPrivate;
class KSortFilterProxyModel
: public QSortFilterProxyModel
{
Q_OBJECT
public:
/*! Constructs a sorting filter model with the given parent. */
explicit KSortFilterProxyModel(QObject * parent = nullptr);
/*! Destroys this sorting filter model. */
~KSortFilterProxyModel() override;
/*! Whether to show the children of a matching parent.
* This is false by default. */
bool showAllChildren() const;
/*! Set whether to show the children of a matching parent.
* This is false by default. */
void setShowAllChildren(bool showAllChildren);
protected:
/*! \reimp */
bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const override;
KSortFilterProxyModelPrivate * const d_ptr;
Q_DISABLE_COPY( KSortFilterProxyModel )
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment