Merge branch 'master' of git.irl.cs.ucla.edu:ndn/sync
This commit is contained in:
commit
3761759a41
8 files changed
+124
-11
No files matched your search
@@ -102,3 +102,4 @@ SyncAppSocket::getNextSeq (const string &prefix, uint32_t session)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ ChatDialog::ChatDialog(QWidget *parent)
|
||||
DigestTreeScene *scene = new DigestTreeScene();
|
||||
|
||||
treeViewer->setScene(scene);
|
||||
QRectF rect = scene->itemsBoundingRect();
|
||||
scene->setSceneRect(rect);
|
||||
//scene->plot();
|
||||
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
||||
@@ -144,3 +146,21 @@ ChatDialog::settingUpdated(QString nick, QString chatroom, QString prefix)
|
||||
updateLabels();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
fitView();
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::showEvent(QShowEvent *e)
|
||||
{
|
||||
fitView();
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::fitView()
|
||||
{
|
||||
treeViewer->fitInView(treeViewer->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
@@ -26,6 +26,9 @@ private:
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
void updateLabels();
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
void fitView();
|
||||
|
||||
private slots:
|
||||
void returnPressed();
|
||||
|
||||
+71
-10
@@ -10,9 +10,33 @@
|
||||
|
||||
static const double Pi = 3.14159265358979323846264338327950288419717;
|
||||
|
||||
static void
|
||||
testDraw(DigestTreeScene * scene)
|
||||
{
|
||||
std::string prefix[5] = {"/ndn/1", "/ndn/2", "/ndn/3", "/ndn/4", "/ndn/5"};
|
||||
std::string nick[5] = {"tom", "jerry", "jason", "michael", "hurry"};
|
||||
std::vector<Sync::MissingDataInfo> v;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Sync::MissingDataInfo mdi = {prefix[i], Sync::SeqNo(0), Sync::SeqNo(i * (2 << i) )};
|
||||
v.push_back(mdi);
|
||||
}
|
||||
|
||||
scene->processUpdate(v, "12341234@!#%!@");
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
scene-> msgReceived(prefix[i].c_str(), nick[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
DigestTreeScene::DisplayUserPtr DigestTreeScene::DisplayUserNullPtr;
|
||||
|
||||
DigestTreeScene::DigestTreeScene(QWidget *parent)
|
||||
: QGraphicsScene(parent)
|
||||
{
|
||||
previouslyUpdatedUser = DisplayUserNullPtr;
|
||||
testDraw(this);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -44,14 +68,33 @@ DigestTreeScene::processUpdate(std::vector<Sync::MissingDataInfo> &v, QString di
|
||||
if (it != m_roster.end()) {
|
||||
DisplayUserPtr p = it.value();
|
||||
QGraphicsTextItem *item = p->getSeqTextItem();
|
||||
QGraphicsRectItem *rectItem = p->getInnerRectItem();
|
||||
std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
|
||||
item->setPlainText(s.c_str());
|
||||
QRectF textBR = item->boundingRect();
|
||||
QRectF rectBR = rectItem->boundingRect();
|
||||
item->setPos(rectBR.x() + (rectBR.width() - textBR.width())/2, rectBR.y() + (rectBR.height() - textBR.height())/2);
|
||||
}
|
||||
}
|
||||
m_rootDigest->setPlainText(digest);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DigestTreeScene::reDrawNode(DisplayUserPtr p, QColor rimColor)
|
||||
{
|
||||
QGraphicsRectItem *rimItem = p->getRimRectItem();
|
||||
rimItem->setBrush(QBrush(rimColor));
|
||||
QGraphicsRectItem *innerItem = p->getInnerRectItem();
|
||||
innerItem->setBrush(QBrush(Qt::lightGray));
|
||||
QGraphicsTextItem *seqTextItem = p->getSeqTextItem();
|
||||
std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
|
||||
seqTextItem->setPlainText(s.c_str());
|
||||
QRectF textBR = seqTextItem->boundingRect();
|
||||
QRectF innerBR = innerItem->boundingRect();
|
||||
seqTextItem->setPos(innerBR.x() + (innerBR.width() - textBR.width())/2, innerBR.y() + (innerBR.height() - textBR.height())/2);
|
||||
}
|
||||
|
||||
void
|
||||
DigestTreeScene::msgReceived(QString prefix, QString nick)
|
||||
{
|
||||
@@ -62,10 +105,21 @@ DigestTreeScene::msgReceived(QString prefix, QString nick)
|
||||
if (nick != p->getNick()) {
|
||||
p->setNick(nick);
|
||||
QGraphicsTextItem *nickItem = p->getNickTextItem();
|
||||
QGraphicsRectItem *nickRectItem = p->getNickRectItem();
|
||||
nickItem->setPlainText(p->getNick());
|
||||
QRectF rectBR = nickRectItem->boundingRect();
|
||||
QRectF nickBR = nickItem->boundingRect();
|
||||
nickItem->setPos(rectBR.x() + (rectBR.width() - nickBR.width())/2, rectBR.y() + 5);
|
||||
}
|
||||
QGraphicsRectItem *rimItem = p->getRimRectItem();
|
||||
rimItem->setBrush(QBrush(Qt::red));
|
||||
|
||||
reDrawNode(p, Qt::red);
|
||||
|
||||
if (previouslyUpdatedUser != DisplayUserNullPtr)
|
||||
{
|
||||
reDrawNode(previouslyUpdatedUser, Qt::darkBlue);
|
||||
}
|
||||
|
||||
previouslyUpdatedUser = p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +137,7 @@ DigestTreeScene::plot(QString digest)
|
||||
}
|
||||
ogdf::GraphAttributes GA(m_graph);
|
||||
|
||||
int nodeSize = 50;
|
||||
int nodeSize = 40;
|
||||
int siblingDistance = 100, levelDistance = 100;
|
||||
ogdf::TreeLayout layout;
|
||||
layout.siblingDistance(siblingDistance);
|
||||
@@ -92,13 +146,15 @@ DigestTreeScene::plot(QString digest)
|
||||
|
||||
int width = GA.boundingBox().width();
|
||||
int height = GA.boundingBox().height();
|
||||
setSceneRect(QRect(- (width + nodeSize) / 2, - 40, width + nodeSize, height + nodeSize));
|
||||
//setSceneRect(QRect(- (width + nodeSize) / 2, - 50, width + nodeSize, height + nodeSize));
|
||||
GA.setAllWidth(nodeSize);
|
||||
GA.setAllHeight(nodeSize);
|
||||
|
||||
plotEdge(GA);
|
||||
plotNode(GA, rootIndex, digest);
|
||||
|
||||
previouslyUpdatedUser = DisplayUserNullPtr;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@@ -141,19 +197,19 @@ DigestTreeScene::plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString dige
|
||||
int rim = 3;
|
||||
QRectF boundingRect(x, y, w, h);
|
||||
QRectF innerBoundingRect(x + rim, y + rim, w - rim * 2, h - rim * 2);
|
||||
addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
|
||||
|
||||
if (n->index() == rootIndex)
|
||||
{
|
||||
addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkRed));
|
||||
addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
|
||||
|
||||
QRectF digestRect(x - w / 2, y - h - 5, 2 * w, 30);
|
||||
QRectF digestRect(x - w, y - h, 3 * w, 30);
|
||||
addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
|
||||
QGraphicsTextItem *digestItem = addText(digest);
|
||||
QRectF digestBoundingRect = digestItem->boundingRect();
|
||||
digestItem->setDefaultTextColor(Qt::white);
|
||||
digestItem->setFont(QFont("Cursive", 12, QFont::Bold));
|
||||
digestItem->setPos(x + w / 2 - digestBoundingRect.width() / 2, y - h - 15);
|
||||
digestItem->setPos(x - w + (3 * w - digestBoundingRect.width()) / 2, y - h + 5);
|
||||
m_rootDigest = digestItem;
|
||||
}
|
||||
else
|
||||
@@ -170,6 +226,9 @@ DigestTreeScene::plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString dige
|
||||
QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue));
|
||||
p->setRimRectItem(rectItem);
|
||||
|
||||
QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
|
||||
p->setInnerRectItem(innerRectItem);
|
||||
|
||||
std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
|
||||
QGraphicsTextItem *seqItem = addText(s.c_str());
|
||||
seqItem->setFont(QFont("Cursive", 12, QFont::Bold));
|
||||
@@ -177,15 +236,17 @@ DigestTreeScene::plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString dige
|
||||
seqItem->setPos(x + w / 2 - seqBoundingRect.width() / 2, y + h / 2 - seqBoundingRect.height() / 2);
|
||||
p->setSeqTextItem(seqItem);
|
||||
|
||||
QRectF textRect(x - w / 2, y + h + 10, 2 * w, 30);
|
||||
addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
|
||||
QRectF textRect(x - w / 2, y + h, 2 * w, 30);
|
||||
QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
|
||||
p->setNickRectItem(nickRectItem);
|
||||
QGraphicsTextItem *nickItem = addText(p->getNick());
|
||||
QRectF textBoundingRect = nickItem->boundingRect();
|
||||
nickItem->setDefaultTextColor(Qt::white);
|
||||
nickItem->setFont(QFont("Cursive", 12, QFont::Bold));
|
||||
nickItem->setPos(x + w / 2 - textBoundingRect.width() / 2, y + h + 15);
|
||||
nickItem->setPos(x + w / 2 - textBoundingRect.width() / 2, y + h + 5);
|
||||
p->setNickTextItem(nickItem);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QMap>
|
||||
#include <vector>
|
||||
#include <tr1/memory>
|
||||
#include <QColor>
|
||||
|
||||
class QGraphicsTextItem;
|
||||
|
||||
@@ -24,18 +25,22 @@ typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
|
||||
typedef QMap<QString, DisplayUserPtr> Roster;
|
||||
typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
|
||||
typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
|
||||
static DisplayUserPtr DisplayUserNullPtr;
|
||||
|
||||
public:
|
||||
DigestTreeScene(QWidget *parent = 0);
|
||||
void processUpdate(std::vector<Sync::MissingDataInfo> &v, QString digest);
|
||||
void msgReceived(QString prefix, QString nick);
|
||||
private:
|
||||
void plot(QString digest);
|
||||
void plotEdge(ogdf::GraphAttributes &GA);
|
||||
void plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest);
|
||||
void reDrawNode(DisplayUserPtr p, QColor rimColor);
|
||||
private:
|
||||
ogdf::Graph m_graph;
|
||||
Roster m_roster;
|
||||
QGraphicsTextItem *m_rootDigest;
|
||||
DisplayUserPtr previouslyUpdatedUser;
|
||||
|
||||
};
|
||||
|
||||
@@ -70,13 +75,19 @@ public:
|
||||
QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
|
||||
QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
|
||||
QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
|
||||
QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
|
||||
QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
|
||||
void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
|
||||
void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
|
||||
void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
|
||||
void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
|
||||
void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
|
||||
private:
|
||||
QGraphicsTextItem *m_seqTextItem;
|
||||
QGraphicsTextItem *m_nickTextItem;
|
||||
QGraphicsRectItem *m_rimRectItem;
|
||||
QGraphicsRectItem *m_innerRectItem;
|
||||
QGraphicsRectItem *m_nickRectItem;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -82,12 +82,17 @@ public:
|
||||
void fetchString(const std::string &prefix, const SeqNo &seq, CcnxWrapper::StringDataCallback callback, int retry = 0);
|
||||
void fetchRaw(const std::string &prefix, const SeqNo &seq, CcnxWrapper::RawDataCallback callback, int retry = 0);
|
||||
|
||||
void passCallback(const std::vector<MissingDataInfo> &v) {m_newDataCallback(v, this);}
|
||||
// for sync-demo
|
||||
std::string getRootDigest() {return m_syncLogic.getRootDigest();}
|
||||
|
||||
|
||||
private:
|
||||
uint32_t
|
||||
getNextSeq (const std::string &prefix, uint32_t session);
|
||||
|
||||
void
|
||||
passCallback(const std::vector<MissingDataInfo> &v) {m_newDataCallback(v, this);}
|
||||
|
||||
private:
|
||||
typedef boost::unordered_map<std::string, SeqNo> SequenceLog;
|
||||
NewDataCallback m_newDataCallback;
|
||||
|
||||
@@ -109,6 +109,9 @@ public:
|
||||
*/
|
||||
void remove (const std::string &prefix);
|
||||
|
||||
std::string
|
||||
getRootDigest();
|
||||
|
||||
#ifdef _DEBUG
|
||||
Scheduler &
|
||||
getScheduler () { return m_scheduler; }
|
||||
|
||||
@@ -532,5 +532,14 @@ SyncLogic::sendSyncData (const std::string &name, DigestConstPtr digest, StateCo
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
SyncLogic::getRootDigest()
|
||||
{
|
||||
ostringstream os;
|
||||
recursive_mutex::scoped_lock lock (m_stateMutex);
|
||||
os << *m_state->getDigest();
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user