]> cloud.milkyroute.net Git - dolphin.git/commitdiff
initial code to provide a Nepomuk query string out of the search criterions
authorPeter Penz <peter.penz19@gmail.com>
Thu, 12 Nov 2009 22:03:07 +0000 (22:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 12 Nov 2009 22:03:07 +0000 (22:03 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1048202

src/search/dolphinsearchbox.cpp
src/search/dolphinsearchoptionsconfigurator.cpp
src/search/dolphinsearchoptionsconfigurator.h
src/search/searchcriterionselector.cpp
src/search/searchcriterionselector.h
src/search/searchcriterionvalue.cpp
src/search/searchcriterionvalue.h

index 6664050146030cd081b1a18a9e4ccaf0b27d7502..c9a86111f643e5611678af7340c1250998731082 100644 (file)
@@ -277,7 +277,6 @@ bool DolphinSearchBox::event(QEvent* event)
     return QWidget::event(event);
 }
 
-#include <kdebug.h>
 bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
 {
     if ((watched == m_searchInput) && (event->type() == QEvent::FocusIn)) {
@@ -287,7 +286,6 @@ bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
         if (m_completer == 0) {
             m_completer = new DolphinSearchCompleter(m_searchInput);
         }
-        kDebug() << "---- got focus! is visible? " << isVisible();
         emit requestSearchOptions();
     }
 
index 81aee12a9d5e13113cf7e17ddfa4eaa3ecf85f19..6271350cc21138dceeecc92b8b3119b99c66008c 100644 (file)
 #include <QShowEvent>
 #include <QVBoxLayout>
 
+#include <kdebug.h>
+
 DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
     QWidget(parent),
     m_initialized(false),
     m_searchFromBox(0),
     m_searchWhatBox(0),
     m_addSelectorButton(0),
-    m_vBoxLayout(0)
+    m_vBoxLayout(0),
+    m_criterions()
 {
     m_vBoxLayout = new QVBoxLayout(this);
 
@@ -118,9 +121,9 @@ void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
         Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
         Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
         Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag) == 2);
-        addSelector(dateCriterion);
-        addSelector(sizeCriterion);
-        addSelector(tagCriterion);
+        addCriterion(dateCriterion);
+        addCriterion(sizeCriterion);
+        addCriterion(tagCriterion);
 
         m_initialized = true;
     }
@@ -130,14 +133,28 @@ void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
 void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
 {
     SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Tag, this);
-    addSelector(selector);
+    addCriterion(selector);
+}
+
+void DolphinSearchOptionsConfigurator::slotCriterionChanged()
+{
+    QString searchOptions;
+    foreach (const SearchCriterionSelector* criterion, m_criterions) {
+        searchOptions += criterion->queryString() + ' ';
+    }
+    kDebug() << "Search option string:" << searchOptions;
+    emit searchOptionsChanged(searchOptions);
 }
 
 void DolphinSearchOptionsConfigurator::removeCriterion()
 {
-    QWidget* criterion = qobject_cast<QWidget*>(sender());
+    SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
     Q_ASSERT(criterion != 0);
     m_vBoxLayout->removeWidget(criterion);
+
+    const int index = m_criterions.indexOf(criterion);
+    m_criterions.removeAt(index);
+
     criterion->deleteLater();
 
     updateSelectorButton();
@@ -175,14 +192,17 @@ void DolphinSearchOptionsConfigurator::saveQuery()
     dialog.exec(); // TODO...
 }
 
-void DolphinSearchOptionsConfigurator::addSelector(SearchCriterionSelector* selector)
+void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
 {
-    connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+    connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+    connect(criterion, SIGNAL(criterionChanged()), this, SLOT(slotCriterionChanged()));
 
     // insert the new selector before the lastLineLayout and the KSeparator at the bottom
     const int index = m_vBoxLayout->count() - 2;
-    m_vBoxLayout->insertWidget(index, selector);
+    m_vBoxLayout->insertWidget(index, criterion);
     updateSelectorButton();
+
+    m_criterions.append(criterion);
 }
 
 #include "dolphinsearchoptionsconfigurator.moc"
index d384f529649d0e254368b04c049b74342684ddc8..46950e42256e2408faea96658a736860f689dbf2 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef DOLPHINSEARCHOPTIONSCONFIGURATOR_H
 #define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
 
+#include <QList>
 #include <QWidget>
 
 class KComboBox;
@@ -38,12 +39,17 @@ public:
     DolphinSearchOptionsConfigurator(QWidget* parent = 0);
     virtual ~DolphinSearchOptionsConfigurator();
 
+signals:
+    void searchOptionsChanged(const QString& options);
+
 protected:
     virtual void showEvent(QShowEvent* event);
 
 private slots:
     void slotAddSelectorButtonClicked();
 
+    void slotCriterionChanged();
+
     void removeCriterion();
 
     /**
@@ -62,7 +68,7 @@ private:
      * Adds the new search description selector to the bottom
      * of the layout.
      */
-    void addSelector(SearchCriterionSelector* selector);
+    void addCriterion(SearchCriterionSelector* selector);
 
 private:
     bool m_initialized;
@@ -70,6 +76,7 @@ private:
     KComboBox* m_searchWhatBox;
     QPushButton* m_addSelectorButton;
     QVBoxLayout* m_vBoxLayout;
+    QList<SearchCriterionSelector*> m_criterions;
 };
 
 #endif
index 08987153a201c2bbeb3f4f1970ead978707190cd..34756cc30757b184c5507453cdc75391ab861a48 100644 (file)
@@ -73,6 +73,63 @@ SearchCriterionSelector::~SearchCriterionSelector()
 {
 }
 
+QString SearchCriterionSelector::queryString() const
+{
+    if (m_valueWidget == 0) {
+        return QString();
+    }
+
+    const int descIndex = m_descriptionsBox->currentIndex();
+    const SearchCriterionDescription& descr = m_descriptions[descIndex];
+
+    const int compIndex = m_comparatorBox->currentIndex();
+    const SearchCriterionDescription::Comparator& comp = descr.comparators()[compIndex];
+
+    return comp.prefix + descr.identifier() + comp.operation +
+           '"' + m_valueWidget->value() + '"';
+}
+
+void SearchCriterionSelector::slotDescriptionChanged(int index)
+{
+    if (m_valueWidget != 0) {
+        m_valueWidget->hide();
+        m_layout->removeWidget(m_valueWidget);
+        m_valueWidget = 0;
+        // the value widget is obtained by the Search Criterion
+        // Selector instance and may not get deleted
+    }
+
+    // add comparator items
+    disconnect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
+    m_comparatorBox->clear();
+
+    const SearchCriterionDescription& description = m_descriptions[index];
+    foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) {
+        m_comparatorBox->addItem(comp.name);
+    }
+
+    // add value widget
+    m_valueWidget = description.valueWidget();
+    m_layout->insertWidget(2, m_valueWidget);
+
+    m_comparatorBox->setCurrentIndex(0);
+    slotComparatorChanged(0);
+    connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
+}
+
+void SearchCriterionSelector::slotComparatorChanged(int index)
+{
+    Q_ASSERT(index >= 0);
+
+    // only show the value widget if an operation is defined by the comparator
+    const int descIndex = m_descriptionsBox->currentIndex();
+    const SearchCriterionDescription& descr = m_descriptions[descIndex];
+    const SearchCriterionDescription::Comparator& comp = descr.comparators()[index];
+    m_valueWidget->setVisible(!comp.operation.isEmpty());
+
+    emit criterionChanged();
+}
+
 void SearchCriterionSelector::createDescriptions()
 {
     Q_ASSERT(m_descriptionsBox != 0);
@@ -98,8 +155,8 @@ void SearchCriterionSelector::createDescriptions()
 
     DateValue* dateValue = new DateValue(this);
     dateValue->hide();
-    SearchCriterionDescription date(i18nc("@label", "Date"),
-                                    "sourceModified",
+    SearchCriterionDescription date(i18nc("@label", "Date:"),
+                                    "lastModified",
                                     dateComps,
                                     dateValue);
 
@@ -109,7 +166,7 @@ void SearchCriterionSelector::createDescriptions()
 
     SizeValue* sizeValue = new SizeValue(this);
     sizeValue->hide();
-    SearchCriterionDescription size(i18nc("@label", "Size"),
+    SearchCriterionDescription size(i18nc("@label", "Size:"),
                                     "contentSize",
                                     sizeComps,
                                     sizeValue);
@@ -117,11 +174,11 @@ void SearchCriterionSelector::createDescriptions()
     // add "Tag" description
     QList<SearchCriterionDescription::Comparator> tagComps;
     tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All")));
-    tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), "=="));
+    tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), ":"));
 
     TagValue* tagValue = new TagValue(this);
     tagValue->hide();
-    SearchCriterionDescription tag(i18nc("@label", "Tag"),
+    SearchCriterionDescription tag(i18nc("@label", "Tag:"),
                                    "tag",
                                    tagComps,
                                    tagValue);
@@ -133,54 +190,13 @@ void SearchCriterionSelector::createDescriptions()
     m_descriptions.append(size);
     m_descriptions.append(tag);
 
-    // add all descriptions to the combo box
-    const int count = m_descriptions.count();
-    for (int i = 0; i < count; ++i) {
-        m_descriptionsBox->addItem(m_descriptions[i].name(), i);
-    }
-}
-
-void SearchCriterionSelector::slotDescriptionChanged(int index)
-{
-    if (m_valueWidget != 0) {
-        m_valueWidget->hide();
-        m_layout->removeWidget(m_valueWidget);
-        m_valueWidget = 0;
-        // the value widget is obtained by the Search Criterion
-        // Selector instance and may not get deleted
-    }
-
-    // add comparator items
-    disconnect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
-    m_comparatorBox->clear();
-
-    const SearchCriterionDescription& description = m_descriptions[index];
-    foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) {
-        m_comparatorBox->addItem(comp.name);
+    // add all descriptions to the combo box and connect the value widgets
+    int i = 0;
+    foreach (const SearchCriterionDescription& desc, m_descriptions) {
+        m_descriptionsBox->addItem(desc.name(), i);
+        connect(desc.valueWidget(), SIGNAL(valueChanged(QString)), this, SIGNAL(criterionChanged()));
+        ++i;
     }
-
-    // add value widget
-    m_valueWidget = description.valueWidget();
-    m_layout->insertWidget(2, m_valueWidget);
-
-    m_comparatorBox->setCurrentIndex(0);
-    slotComparatorChanged(0);
-    connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
-}
-
-void SearchCriterionSelector::slotComparatorChanged(int index)
-{
-    Q_ASSERT(index >= 0);
-
-    // only show the value widget if an operation is defined by the comparator
-    const int descIndex = m_descriptionsBox->currentIndex();
-    const SearchCriterionDescription& descr = m_descriptions[descIndex];
-    const SearchCriterionDescription::Comparator& comp = descr.comparators()[index];
-    m_valueWidget->setVisible(!comp.operation.isEmpty());
-
-    // create query string
-    const QString queryString = comp.prefix + descr.identifier() + comp.operation + m_valueWidget->value();
-    emit criterionChanged(queryString);
 }
 
 #include "searchcriterionselector.moc"
index abaed2d0a9bc478636363e5ab38d91b24264be34..c6c3b22e09743d6e639b70025858c9f650123498 100644 (file)
@@ -50,6 +50,8 @@ public:
     SearchCriterionSelector(Type type, QWidget* parent = 0);
     virtual ~SearchCriterionSelector();
 
+    QString queryString() const;
+
 signals:
     /**
      * Is emitted if the criterion selector should be removed
@@ -57,11 +59,8 @@ signals:
      */
     void removeCriterion();
 
-    /**
-     * Is emitted if the user changed the search criterion.
-     * \p queryString represents a Nepomuk conform query string.
-     */
-    void criterionChanged(const QString& queryString);
+    /** Is emitted if the user has changed the search criterion. */
+    void criterionChanged();
 
 private slots:
     void slotDescriptionChanged(int index);
index 531db3e01c6cb08aa26e10efe7c430d6cd2357e7..7bf83e94fff19c347da305817b40dda270cb7651 100644 (file)
 
 #include "searchcriterionvalue.h"
 
+#include <kdatewidget.h>
 #include <klineedit.h>
 #include <klocale.h>
 
 #include <nepomuk/tag.h>
 
 #include <QComboBox>
-#include <QDateEdit>
+#include <QDate>
+#include <QIntValidator>
 #include <QLabel>
 #include <QHBoxLayout>
 #include <QShowEvent>
@@ -44,13 +46,13 @@ SearchCriterionValue::~SearchCriterionValue()
 
 DateValue::DateValue(QWidget* parent) :
     SearchCriterionValue(parent),
-    m_dateEdit(0)
+    m_dateWidget(0)
 {
-    m_dateEdit = new QDateEdit(this);
+    m_dateWidget = new KDateWidget(QDate::currentDate(), this);
 
     QHBoxLayout* layout = new QHBoxLayout(this);
     layout->setMargin(0);
-    layout->addWidget(m_dateEdit);
+    layout->addWidget(m_dateWidget);
 }
 
 DateValue::~DateValue()
@@ -59,7 +61,7 @@ DateValue::~DateValue()
 
 QString DateValue::value() const
 {
-    return QString();
+    return m_dateWidget->date().toString(Qt::ISODate);
 }
 
 // -------------------------------------------------------------------------
@@ -74,6 +76,9 @@ TagValue::TagValue(QWidget* parent) :
     QHBoxLayout* layout = new QHBoxLayout(this);
     layout->setMargin(0);
     layout->addWidget(m_tags);
+
+    connect(m_tags, SIGNAL(activated(QString)),
+            this, SIGNAL(valueChanged(QString)));
 }
 
 TagValue::~TagValue()
@@ -82,7 +87,7 @@ TagValue::~TagValue()
 
 QString TagValue::value() const
 {
-    return QString();
+    return m_tags->currentText();
 }
 
 void TagValue::showEvent(QShowEvent* event)
@@ -109,6 +114,8 @@ SizeValue::SizeValue(QWidget* parent) :
 {
     m_lineEdit = new KLineEdit(this);
     m_lineEdit->setClearButtonShown(true);
+    m_lineEdit->setValidator(new QIntValidator(this));
+    m_lineEdit->setAlignment(Qt::AlignRight);
 
     m_units = new QComboBox(this);
     // TODO: check the KByte vs. KiByte dilemma :-/
@@ -117,6 +124,10 @@ SizeValue::SizeValue(QWidget* parent) :
     m_units->addItem(i18nc("@label", "MByte"));
     m_units->addItem(i18nc("@label", "GByte"));
 
+    // set 1 MByte as default
+    m_lineEdit->setText("1");
+    m_units->setCurrentIndex(2);
+
     QHBoxLayout* layout = new QHBoxLayout(this);
     layout->setMargin(0);
     layout->addWidget(m_lineEdit);
index 5144c7181fe73b3d5a5ad17589c53f2f12621958..972b95f7a75560f01aff5fb02f0bb3908b292f70 100644 (file)
@@ -24,7 +24,7 @@
 #include <QWidget>
 
 class QComboBox;
-class QDateEdit;
+class KDateWidget;
 class KLineEdit;
 
 /**
@@ -58,7 +58,7 @@ public:
     virtual QString value() const;
     
 private:
-    QDateEdit* m_dateEdit;
+    KDateWidget* m_dateWidget;
 };