//QueryView class
void QueryView::initUI()
{
/* ---other UI code --- */
fTableWidget->setGeometry(15,169,251,232);
fTableWidget->setColumnWidth(0,198);
fTableWidget->setColumnWidth(1,54);
fTableWidget
->setFrameStyle
(QFrame::NoFrame);
fTableWidget->setShowGrid(false);
fTableWidget->horizontalHeader()->hide();
fTableWidget->verticalHeader()->hide();
fTableWidget->verticalHeader()->setDefaultSectionSize(24);
fTableWidget->setObjectName("fTableWidget");
fTableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void QueryVieww::bindSignalsAndSlots()
{
connect(queryButton, SIGNAL(clicked()), this, SLOT(doQuery()));
}
void QueryView::doQuery()
{
QueryAction *action = new QueryAction(text, this);
action->execute();
}
{
int rowNum = fTableWidget->rowCount();
fTableWidget->setRowCount(rowNum+1);
textSnippet->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
textSnippet->setCursor(Qt::PointingHandCursor);
textSnippet->setFixedHeight(24);
textSnippet->setFixedWidth(198);
button2->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
button2->setCursor(Qt::PointingHandCursor);
button2->setFixedHeight(24);
button2->setFixedWidth(54);
button2->setText(text2);
fTableWidget->setCellWidget(rowNum,0,textSnippet);
fTableWidget->setCellWidget(rowNum,1,button2);
//here text is added last because ellipsis text needs the width of the button, so first attaching it to the view,
//then extracting its width and showing ellipsis at 5 px from the end, i.e 198-5 = 193
QString elidedText
= metrics.
elidedText(text1, Qt
::ElideRight,
193);
textSnippet->setText(elidedText);
}
//QueryAction class
QueryAction
::QueryAction(QString queryText, QueryView
*view
){
fQueryText = queryText;
fView = view;
}
QueryAction::execute()
{
//search a binary tree with queryText, if query matches, update view immediately
while (rootNode != NULL)
{
data = rootNode.data;
if (data.text == fQueryText)
{
fView->updateTable(data.keyData, data.valueData);
}
//traverse to left and right of rootNode
}
}
//QueryView class
void QueryView::initUI()
{
queryButton = new QPushButton(this);
textBox = new QLineEdit(this);
/* ---other UI code --- */
fTableWidget = new QTableWidget(1,2,this);
fTableWidget->setGeometry(15,169,251,232);
fTableWidget->setColumnWidth(0,198);
fTableWidget->setColumnWidth(1,54);
fTableWidget->setFrameStyle(QFrame::NoFrame);
fTableWidget->setShowGrid(false);
fTableWidget->horizontalHeader()->hide();
fTableWidget->verticalHeader()->hide();
fTableWidget->verticalHeader()->setDefaultSectionSize(24);
fTableWidget->setObjectName("fTableWidget");
fTableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void QueryVieww::bindSignalsAndSlots()
{
connect(queryButton, SIGNAL(clicked()), this, SLOT(doQuery()));
}
void QueryView::doQuery()
{
QString text = textBox->text();
QueryAction *action = new QueryAction(text, this);
action->execute();
}
void QueryView::updateTable(QString text1, QString text2)
{
int rowNum = fTableWidget->rowCount();
fTableWidget->setRowCount(rowNum+1);
QPushButton *textSnippet = new QPushButton();
textSnippet->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
textSnippet->setCursor(Qt::PointingHandCursor);
textSnippet->setFixedHeight(24);
textSnippet->setFixedWidth(198);
QPushButton *button2 = new QPushButton();
button2->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
button2->setCursor(Qt::PointingHandCursor);
button2->setFixedHeight(24);
button2->setFixedWidth(54);
button2->setText(text2);
fTableWidget->setCellWidget(rowNum,0,textSnippet);
fTableWidget->setCellWidget(rowNum,1,button2);
//here text is added last because ellipsis text needs the width of the button, so first attaching it to the view,
//then extracting its width and showing ellipsis at 5 px from the end, i.e 198-5 = 193
QFontMetrics metrics(textSnippet->font());
QString elidedText = metrics.elidedText(text1, Qt::ElideRight, 193);
textSnippet->setText(elidedText);
}
//QueryAction class
QueryAction::QueryAction(QString queryText, QueryView *view)
{
fQueryText = queryText;
fView = view;
}
QueryAction::execute()
{
//search a binary tree with queryText, if query matches, update view immediately
while (rootNode != NULL)
{
data = rootNode.data;
if (data.text == fQueryText)
{
fView->updateTable(data.keyData, data.valueData);
}
//traverse to left and right of rootNode
}
}
To copy to clipboard, switch view to plain text mode
QueryAction::execute()
{
//search a binary tree with queryText, if query matches, update view immediately
std::vector<RootNode.Data> temp;
while (rootNode != NULL)
{
data = rootNode.data;
if (data.text == fQueryText)
{
//commented out, no updating on the fly
//fView->updateTable(data.keyData, data.valueData);
temp.push_back(data);
}
//traverse to left and right of rootNode
}
//now that all the data are there, populate UI in one go
for (int i = 0; i < temp.size(); i++)
fView->updateTable(temp[i]);
}
QueryAction::execute()
{
//search a binary tree with queryText, if query matches, update view immediately
std::vector<RootNode.Data> temp;
while (rootNode != NULL)
{
data = rootNode.data;
if (data.text == fQueryText)
{
//commented out, no updating on the fly
//fView->updateTable(data.keyData, data.valueData);
temp.push_back(data);
}
//traverse to left and right of rootNode
}
//now that all the data are there, populate UI in one go
for (int i = 0; i < temp.size(); i++)
fView->updateTable(temp[i]);
}
To copy to clipboard, switch view to plain text mode
Bookmarks