@@ -178,6 +178,8 @@ boost::optional<ConnectionId> NetworkEditor::requestConnection(const PortDescrip
178178
179179namespace
180180{
181+ const int TagTextKey = 123 ;
182+
181183 ModuleProxyWidget* findById (const QList<QGraphicsItem*>& list, const std::string& id)
182184 {
183185 Q_FOREACH (QGraphicsItem* item, list)
@@ -775,38 +777,31 @@ class NetworkSearchEngine
775777 ResultList results;
776778 Q_FOREACH (auto item, scene_->items ())
777779 {
780+ ResultList subresults;
778781 if (auto w = dynamic_cast <ModuleProxyWidget*>(item))
779782 {
780- qDebug () << " module widget. should search module id, state keys" ;
781- qDebug () << w;
782- auto subresults = searchItem (w, text);
783- results.insert (results.end (), subresults.begin (), subresults.end ());
784- }
785- else if (auto c = dynamic_cast <ConnectionLine*>(item))
786- {
787- qDebug () << " connection line. should search note--or maybe not." ;
788- qDebug () << item;
783+ subresults = searchItem (w, text);
789784 }
790- else if (auto text = dynamic_cast <QGraphicsTextItem*>(item))
785+ // else if (auto c = dynamic_cast<ConnectionLine*>(item))
786+ // {
787+ // //qDebug() << "connection line. should search note--or maybe not.";
788+ // //qDebug() << item;
789+ // }
790+ else if (auto t = dynamic_cast <QGraphicsTextItem*>(item))
791791 {
792- qDebug () << " note. should search text." ;
793- qDebug () << text;
792+ subresults = searchItem (t, text);
794793 }
795- else if (auto stext = dynamic_cast <QGraphicsSimpleTextItem*>(item))
794+ else if (auto s = dynamic_cast <QGraphicsSimpleTextItem*>(item))
796795 {
797- qDebug () << " tag label. should search text." ;
798- qDebug () << stext;
796+ subresults = searchItem (s, text);
799797 }
800798 else
801799 {
802800 // qDebug() << "something else";
803801 // qDebug() << item;
804802 }
805-
803+ results. insert (results. end (), subresults. begin (), subresults. end ());
806804 }
807- // qDebug() << "need to search for" << text;
808- // std::function<void()> blank;
809- // return { {"Module", "CreateLatVol:0", blank}, {"Module note", "note contents", blank}};
810805 return results;
811806 }
812807private:
@@ -818,14 +813,50 @@ class NetworkSearchEngine
818813 {
819814 results.emplace_back (" Module" ,
820815 QString::fromStdString (id),
821- [mod]() { mod->showAndColor (Qt::yellow ); },
816+ [mod]() { mod->showAndColor (Qt::green ); },
822817 tagColor_ (mod->data (TagDataKey).toInt ()));
823818 }
824819
825820 // TODO: state keys and values
826821
827822 return results;
828823 }
824+
825+ ResultList searchItem (QGraphicsTextItem* note, const QString& text) const
826+ {
827+ ResultList results;
828+ auto cursor = note->document ()->find (text);
829+ if (!cursor.isNull ())
830+ {
831+ results.emplace_back (" Note" ,
832+ " ..." + note->toPlainText ().mid (cursor.position () - 10 , 20 ) + " ..." ,
833+ [note, text]() { ModuleProxyWidget::ensureItemVisible (note); selectNote (note, text); },
834+ Qt::white);
835+ }
836+ return results;
837+ }
838+
839+ ResultList searchItem (QGraphicsSimpleTextItem* tag, const QString& text) const
840+ {
841+ ResultList results;
842+ if (tag->text ().contains (text, Qt::CaseInsensitive))
843+ {
844+ results.emplace_back (" Tag" ,
845+ tag->text (),
846+ [tag]() { ModuleProxyWidget::ensureItemVisible (tag); },
847+ tagColor_ (tag->data (TagTextKey).toInt ()));
848+ }
849+ return results;
850+ }
851+
852+ static void selectNote (QGraphicsTextItem* note, const QString& text)
853+ {
854+ auto doc = note->document ();
855+ QTextCursor cur (doc->find (text));
856+ note->setTextCursor (cur);
857+ // QTimer::singleShot(4000, &cur, SLOT(networkTimedOut()));
858+ }
859+
829860 QGraphicsScene* scene_;
830861 TagColorFunc tagColor_;
831862};
@@ -1597,8 +1628,6 @@ namespace
15971628 int tagNumber_;
15981629 NetworkEditor* ned_;
15991630 };
1600-
1601- const int TagTextKey = 123 ;
16021631}
16031632
16041633void NetworkEditor::saveTagGroupRectInFile ()
0 commit comments