• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

querymatch.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "querymatch.h"
00021 
00022 #include <QAction>
00023 #include <QPointer>
00024 #include <QVariant>
00025 #include <QSharedData>
00026 #include <QStringList>
00027 #include <QIcon>
00028 
00029 #include <kdebug.h>
00030 
00031 #include "abstractrunner.h"
00032 
00033 namespace Plasma
00034 {
00035 
00036 class QueryMatchPrivate : public QSharedData
00037 {
00038     public:
00039         QueryMatchPrivate(AbstractRunner *r)
00040             : QSharedData(),
00041               runner(r),
00042               type(QueryMatch::ExactMatch),
00043               enabled(true),
00044               relevance(.7),
00045               selAction(0)
00046         {
00047         }
00048 
00049         QPointer<AbstractRunner> runner;
00050         QueryMatch::Type type;
00051         QString id;
00052         QString text;
00053         QString subtext;
00054         QIcon icon;
00055         QVariant data;
00056         bool enabled;
00057         qreal relevance;
00058         QAction *selAction;
00059 };
00060 
00061 QueryMatch::QueryMatch(AbstractRunner *runner)
00062     : d(new QueryMatchPrivate(runner))
00063 {
00064     if (runner) {
00065         d->id = runner->id();
00066     }
00067 //    kDebug() << "new match created";
00068 }
00069 
00070 QueryMatch::QueryMatch(const QueryMatch &other)
00071     : d(other.d)
00072 {
00073 }
00074 
00075 QueryMatch::~QueryMatch()
00076 {
00077 }
00078 
00079 bool QueryMatch::isValid() const
00080 {
00081     return d->runner != 0;
00082 }
00083 
00084 QString QueryMatch::id() const
00085 {
00086     return d->id;
00087 }
00088 
00089 void QueryMatch::setType(Type type)
00090 {
00091     d->type = type;
00092 }
00093 
00094 QueryMatch::Type QueryMatch::type() const
00095 {
00096     return d->type;
00097 }
00098 
00099 void QueryMatch::setRelevance(qreal relevance)
00100 {
00101     d->relevance = qMax(qreal(0.0), qMin(qreal(1.0), relevance));
00102 }
00103 
00104 qreal QueryMatch::relevance() const
00105 {
00106     return d->relevance;
00107 }
00108 
00109 AbstractRunner* QueryMatch::runner() const
00110 {
00111     return d->runner;
00112 }
00113 
00114 void QueryMatch::setText(const QString &text)
00115 {
00116     d->text = text;
00117 }
00118 
00119 void QueryMatch::setSubtext(const QString &subtext)
00120 {
00121     d->subtext = subtext;
00122 }
00123 
00124 void QueryMatch::setData(const QVariant & data)
00125 {
00126     d->data = data;
00127     setId(data.toString());
00128 }
00129 
00130 void QueryMatch::setId(const QString &id)
00131 {
00132     if (d->runner) {
00133         d->id = d->runner->id();
00134     }
00135 
00136     if (!id.isEmpty()) {
00137         d->id.append('_').append(id);
00138     }
00139 }
00140 
00141 void QueryMatch::setIcon(const QIcon &icon)
00142 {
00143     d->icon = icon;
00144 }
00145 
00146 QVariant QueryMatch::data() const
00147 {
00148     return d->data;
00149 }
00150 
00151 QString QueryMatch::text() const
00152 {
00153     return d->text;
00154 }
00155 
00156 QString QueryMatch::subtext() const
00157 {
00158     return d->subtext;
00159 }
00160 
00161 QIcon QueryMatch::icon() const
00162 {
00163     return d->icon;
00164 }
00165 
00166 void QueryMatch::setEnabled(bool enabled)
00167 {
00168     d->enabled = enabled;
00169 }
00170 
00171 bool QueryMatch::isEnabled() const
00172 {
00173     return d->enabled && d->runner;
00174 }
00175 
00176 QAction* QueryMatch::selectedAction() const
00177 {
00178     return d->selAction;
00179 }
00180 
00181 void QueryMatch::setSelectedAction(QAction *action)
00182 {
00183     d->selAction = action;
00184 }
00185 
00186 bool QueryMatch::operator<(const QueryMatch &other) const
00187 {
00188     if (d->type == other.d->type) {
00189         if (isEnabled() != other.isEnabled()) {
00190             return other.isEnabled();
00191         }
00192 
00193         if (d->relevance != other.d->relevance) {
00194             return d->relevance < other.d->relevance;
00195         }
00196 
00197         // when resorting to sort by alpha, we want the
00198         // reverse sort order!
00199         return d->text > other.d->text;
00200     }
00201 
00202     return d->type < other.d->type;
00203 }
00204 
00205 QueryMatch &QueryMatch::operator=(const QueryMatch &other)
00206 {
00207     if (d != other.d) {
00208         d = other.d;
00209     }
00210 
00211     return *this;
00212 }
00213 
00214 void QueryMatch::run(const RunnerContext &context) const
00215 {
00216     //kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype();
00217     if (d->runner) {
00218         d->runner->run(context, *this);
00219     }
00220 }
00221 
00222 } // Plasma namespace
00223 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal