Added simple search capability to TemplatePicker.

This commit is contained in:
Jim Evins
2013-11-12 22:42:51 -05:00
parent 7f3adc818b
commit 5ce9121801
9 changed files with 132 additions and 6 deletions
+2
View File
@@ -15,6 +15,7 @@ set (glabels_sources
MergeField.cpp
MergeRecord.cpp
TemplatePicker.cpp
TemplatePickerItem.cpp
TextNode.cpp
NewLabelDialog.cpp
)
@@ -45,6 +46,7 @@ include (${QT_USE_FILE})
include_directories (
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${glabels_qt_SOURCE_DIR}
)
+9
View File
@@ -32,6 +32,15 @@ namespace gLabels
QList<libglabels::Template*> tmplates = libglabels::Db::templates();
templatePicker->setTemplates( tmplates );
connect( searchEntry, SIGNAL(textChanged(const QString &)),
this, SLOT(searchEntryTextChanged(const QString &)) );
}
void NewLabelDialog::searchEntryTextChanged( const QString &text )
{
templatePicker->applyFilter( text );
}
}
+2 -2
View File
@@ -34,8 +34,8 @@ namespace gLabels
public:
NewLabelDialog( QWidget *parent );
private:
private slots:
void searchEntryTextChanged( const QString &text );
};
+23 -3
View File
@@ -20,9 +20,10 @@
#include "TemplatePicker.h"
#include <QListWidgetItem>
#include <QIcon>
#include "TemplatePickerItem.h"
namespace gLabels
{
@@ -42,9 +43,28 @@ namespace gLabels
{
foreach (libglabels::Template *tmplate, tmplates)
{
QListWidgetItem *item = new QListWidgetItem( tmplate->name(), this );
item->setIcon( QIcon(tmplate->preview()) );
TemplatePickerItem *item = new TemplatePickerItem( tmplate, this );
}
}
void TemplatePicker::applyFilter( const QString &searchString )
{
foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) )
{
TemplatePickerItem *tPitem = dynamic_cast<TemplatePickerItem *>(item);
if ( tPitem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) )
{
item->setHidden( false );
}
else
{
item->setHidden( true );
}
}
}
}
+2
View File
@@ -40,6 +40,8 @@ namespace gLabels
void setTemplates( const QList <libglabels::Template*> &tmplates );
void applyFilter( const QString &searchString );
private:
+42
View File
@@ -0,0 +1,42 @@
/* TemplatePickerItem.cpp
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TemplatePickerItem.h"
#include <QListWidgetItem>
#include <QIcon>
#include <QHBoxLayout>
namespace gLabels
{
TemplatePickerItem::TemplatePickerItem( libglabels::Template *tmplate,
QListWidget *parent = 0 )
: QListWidgetItem(parent)
{
mTmplate = tmplate;
setIcon( QIcon(tmplate->preview()) );
setText( tmplate->name() );
}
}
+49
View File
@@ -0,0 +1,49 @@
/* TemplatePickerItem.h
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_TemplatePickerItem_h
#define glabels_TemplatePickerItem_h
#include <QListWidget>
#include <QLabel>
#include "libglabels/Template.h"
namespace gLabels
{
class TemplatePickerItem : public QListWidgetItem
{
public:
TemplatePickerItem( libglabels::Template *tmplate, QListWidget *parent );
inline const libglabels::Template *tmplate() const { return mTmplate; }
private:
libglabels::Template *mTmplate;
};
}
#endif // glabels_TemplatePickerItem_h
+2
View File
@@ -38,10 +38,12 @@ int main( int argc, char **argv )
Db::init();
////// TEMPORARY TESTING ////////
#if 0
Db::printKnownPapers();
Db::printKnownCategories();
Db::printKnownVendors();
Db::printKnownTemplates();
#endif
/////////////////////////////////
MainWindow mainWin;
+1 -1
View File
@@ -271,7 +271,7 @@
<customwidget>
<class>gLabels::TemplatePicker</class>
<extends>QListWidget</extends>
<header>../../app/TemplatePicker.h</header>
<header>TemplatePicker.h</header>
</customwidget>
</customwidgets>
<resources/>