On 31 May 2010 15:39, Sebastian Trüg <[email protected]> wrote:
> It does make sense but certainly not as a default. So it would have to
> be configurable. As with AnnotationMenu I would prefer configuration
> flags over boolean parameters.
Done.
There still was one problem (that had been a problem before these
changes were made): the LineEdit connections were never made for the
default case, as the condition always evaluates to false (since we set
NoFlags, which equals the default value that has already been set).
The solutions I saw are these two (from which I chose the second one):
1. We make the initial connections in the constructor (this results in
code duplication),
2. We set AllFlags as the default value for the flags first (in the
Private constructor), then set NoFlags.
Is there a better solution?
Cheers,
Oszkar
Index: lib/gui/annotationmenu.cpp
===================================================================
--- lib/gui/annotationmenu.cpp (revision 1130116)
+++ lib/gui/annotationmenu.cpp (working copy)
@@ -554,7 +554,7 @@
kDebug();
if ( !m_searchMenu ) {
m_searchMenu = new SearchMenu( menu );
- m_searchMenu->setSearchWhileYouTypeEnabled( true );
+ m_searchMenu->setConfigurationFlags( SearchMenu::SearchWhileYouType );
q->connect( m_searchMenu, SIGNAL( resultTriggered( Nepomuk::Query::Result ) ),
SLOT( _k_searchResultTriggered( Nepomuk::Query::Result ) ) );
}
Index: searchmenu.h
===================================================================
--- searchmenu.h (revision 1132519)
+++ searchmenu.h (working copy)
@@ -48,9 +48,17 @@
SearchMenu( QWidget* parent = 0 );
~SearchMenu();
- void setSearchWhileYouTypeEnabled( bool enabled );
- bool searchWhileYouTypeEnabled() const;
+ enum ConfigurationFlag {
+ NoFlags = 0x0,
+ SearchWhileYouType = 0x1,
+ SearchOnSetCoreTerm = 0x2,
+ AllFlags = 0x3
+ };
+ Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
+ void setConfigurationFlags( ConfigurationFlags flags );
+ ConfigurationFlags configurationFlags() const;
+
/**
* Set a basic term to always restrict the query.
* By default this is an invalid Term, meaning results
@@ -73,4 +81,6 @@
};
}
+Q_DECLARE_OPERATORS_FOR_FLAGS( Nepomuk::SearchMenu::ConfigurationFlags )
+
#endif
Index: searchmenu.cpp
===================================================================
--- searchmenu.cpp (revision 1132519)
+++ searchmenu.cpp (working copy)
@@ -43,7 +43,7 @@
{
public:
Private()
- : m_swytEnabled( false ) {
+ : m_configFlags( SearchMenu::AllFlags ) {
}
QAction* createResultAction( const Query::Result& result ) const;
@@ -55,7 +55,7 @@
void _k_aboutToShow();
Query::Term m_coreQueryTerm;
- bool m_swytEnabled;
+ SearchMenu::ConfigurationFlags m_configFlags;
KLineEdit* m_lineEdit;
QWidgetAction* m_editAction;
@@ -91,7 +91,7 @@
const QString queryString = m_lineEdit->text();
- if ( !queryString.isEmpty() ) {
+ if (!queryString.isEmpty() || m_coreQueryTerm.isValid()) {
// create the busy action
if ( !m_busyAction ) {
m_busyAction = q->createBusyAction( q );
@@ -164,7 +164,7 @@
connect( this, SIGNAL( aboutToShow() ), this, SLOT( _k_aboutToShow() ) );
- setSearchWhileYouTypeEnabled( false );
+ setConfigurationFlags(SearchMenu::NoFlags);
}
@@ -174,10 +174,10 @@
}
-void Nepomuk::SearchMenu::setSearchWhileYouTypeEnabled( bool enabled )
-{
- if ( d->m_swytEnabled != enabled ) {
- if ( enabled ) {
+void Nepomuk::SearchMenu::setConfigurationFlags( ConfigurationFlags flags )
+{
+ if ( ( d->m_configFlags & SearchMenu::SearchWhileYouType ) != (flags & SearchMenu::SearchWhileYouType ) ) {
+ if ( flags & SearchMenu::SearchWhileYouType ) {
connect( d->m_lineEdit, SIGNAL( textEdited( QString ) ),
this, SLOT( _k_query() ) );
disconnect( d->m_lineEdit, SIGNAL( returnPressed() ),
@@ -189,20 +189,24 @@
disconnect( d->m_lineEdit, SIGNAL( textEdited( QString ) ),
this, SLOT( _k_query() ) );
}
- d->m_swytEnabled = enabled;
}
+
+ d->m_configFlags = flags;
}
-bool Nepomuk::SearchMenu::searchWhileYouTypeEnabled() const
+Nepomuk::SearchMenu::ConfigurationFlags Nepomuk::SearchMenu::configurationFlags() const
{
- return d->m_swytEnabled;
+ return d->m_configFlags;
}
void Nepomuk::SearchMenu::setCoreQueryTerm( const Query::Term& term )
{
d->m_coreQueryTerm = term;
+ if( d->m_configFlags & SearchMenu::SearchOnSetCoreTerm ) {
+ d->_k_query();
+ }
}
#include "searchmenu.moc"
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk