Skip to content

Commit c8adcfd

Browse files
committed
Notes and tags searchable
1 parent daa7952 commit c8adcfd

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

src/Interface/Application/ModuleProxyWidget.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ ModuleProxyWidget::~ModuleProxyWidget()
149149

150150
void ModuleProxyWidget::showAndColor(const QColor& color)
151151
{
152+
animateColor_ = color;
152153
timeLine_ = new QTimeLine(4000, this);
153154
connect(timeLine_, SIGNAL(valueChanged(qreal)), this, SLOT(colorAnimate(qreal)));
154155
timeLine_->start();
@@ -169,7 +170,7 @@ void ModuleProxyWidget::colorAnimate(qreal val)
169170
if (!effect)
170171
{
171172
auto colorize = new QGraphicsColorizeEffect;
172-
colorize->setColor(Qt::green);
173+
colorize->setColor(animateColor_);
173174
setGraphicsEffect(colorize);
174175
}
175176
else if (auto c = dynamic_cast<QGraphicsColorizeEffect*>(effect))
@@ -211,7 +212,7 @@ void ModuleProxyWidget::ensureThisVisible()
211212

212213
void ModuleProxyWidget::ensureItemVisible(QGraphicsItem* item)
213214
{
214-
auto views = scene()->views();
215+
auto views = item->scene()->views();
215216
if (!views.isEmpty())
216217
{
217218
auto netEd = qobject_cast<NetworkEditor*>(views[0]);

src/Interface/Application/ModuleProxyWidget.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ namespace SCIRun
5353
void adjustHeight(int delta);
5454
void adjustWidth(int delta);
5555

56+
//TODO: move to utility
57+
static void ensureItemVisible(QGraphicsItem* item);
58+
5659
public Q_SLOTS:
5760
void highlightIfSelected();
5861
void setDefaultNotePosition(NotePosition position);
@@ -80,11 +83,11 @@ namespace SCIRun
8083
void loadAnimate(qreal val);
8184
void colorAnimate(qreal val);
8285
private:
83-
void ensureItemVisible(QGraphicsItem* item);
8486
bool isSubwidget(QWidget* alienWidget) const;
8587
void updatePressedSubWidget(QGraphicsSceneMouseEvent* event);
8688

8789
ModuleWidget* module_;
90+
QColor animateColor_;
8891
bool grabbedByWidget_, isSelected_;
8992
QWidget* pressedSubWidget_;
9093
QPointF position_;

src/Interface/Application/NetworkEditor.cc

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ boost::optional<ConnectionId> NetworkEditor::requestConnection(const PortDescrip
178178

179179
namespace
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
}
812807
private:
@@ -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

16041633
void NetworkEditor::saveTagGroupRectInFile()

0 commit comments

Comments
 (0)