added remove buttons for ongoing search entries

This commit is contained in:
csoler 2018-06-20 23:26:37 +02:00
parent 91fd38d46f
commit c79ceba4ee
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 83 additions and 3 deletions

View File

@ -59,6 +59,8 @@
#define ROLE_SUBSCRIBE_FLAGS Qt::UserRole + 8 #define ROLE_SUBSCRIBE_FLAGS Qt::UserRole + 8
#define ROLE_COLOR Qt::UserRole + 9 #define ROLE_COLOR Qt::UserRole + 9
#define ROLE_SAVED_ICON Qt::UserRole + 10 #define ROLE_SAVED_ICON Qt::UserRole + 10
#define ROLE_SEARCH_STRING Qt::UserRole + 11
#define ROLE_REQUEST_ID Qt::UserRole + 12
#define FILTER_NAME_INDEX 0 #define FILTER_NAME_INDEX 0
#define FILTER_DESC_INDEX 1 #define FILTER_DESC_INDEX 1
@ -397,6 +399,32 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
return item; return item;
} }
void GroupTreeWidget::removeSearchItem(QTreeWidgetItem *item)
{
ui->treeWidget->takeTopLevelItem(ui->treeWidget->indexOfTopLevelItem(item)) ;
}
QTreeWidgetItem *GroupTreeWidget::addSearchItem(const QString& search_string, uint32_t id, const QIcon& icon)
{
QTreeWidgetItem *item = addCategoryItem(search_string,icon,true);
item->setData(COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ;
item->setData(COLUMN_DATA,ROLE_REQUEST_ID ,id) ;
return item;
}
bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
{
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
if (item == NULL)
return false;
search_req_id = item->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
return search_req_id > 0;
}
QString GroupTreeWidget::itemId(QTreeWidgetItem *item) QString GroupTreeWidget::itemId(QTreeWidgetItem *item)
{ {
if (item == NULL) { if (item == NULL) {

View File

@ -82,6 +82,10 @@ public:
// Add a new category item // Add a new category item
QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand); QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand);
// Add a new search item
QTreeWidgetItem *addSearchItem(const QString& search_string, uint32_t id, const QIcon &icon) ;
void removeSearchItem(QTreeWidgetItem *item);
// Get id of item // Get id of item
QString itemId(QTreeWidgetItem *item); QString itemId(QTreeWidgetItem *item);
QString itemIdAt(QPoint &point); QString itemIdAt(QPoint &point);
@ -90,6 +94,8 @@ public:
// Set the unread count of an item // Set the unread count of an item
void setUnreadCount(QTreeWidgetItem *item, int unreadCount); void setUnreadCount(QTreeWidgetItem *item, int unreadCount);
bool isSearchRequestItem(QPoint &point,uint32_t& search_req_id);
QTreeWidgetItem *getItemFromId(const QString &id); QTreeWidgetItem *getItemFromId(const QString &id);
QTreeWidgetItem *activateId(const QString &id, bool focus); QTreeWidgetItem *activateId(const QString &id, bool focus);

View File

@ -46,6 +46,7 @@
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/images/edit_16.png"
#define IMAGE_SHARE ":/images/share-icon-16.png" #define IMAGE_SHARE ":/images/share-icon-16.png"
#define IMAGE_TABNEW ":/images/tab-new.png" #define IMAGE_TABNEW ":/images/tab-new.png"
#define IMAGE_DELETE ":/images/delete.png"
#define IMAGE_COMMENT "" #define IMAGE_COMMENT ""
#define TOKEN_TYPE_GROUP_SUMMARY 1 #define TOKEN_TYPE_GROUP_SUMMARY 1
@ -252,16 +253,55 @@ void GxsGroupFrameDialog::todo()
QMessageBox::information(this, "Todo", text(TEXT_TODO)); QMessageBox::information(this, "Todo", text(TEXT_TODO));
} }
void GxsGroupFrameDialog::removeCurrentSearch()
{
QAction *action = dynamic_cast<QAction*>(sender()) ;
if(!action)
return ;
TurtleRequestId search_request_id = action->data().toUInt();
auto it = mSearchGroups.find(search_request_id) ;
if(it == mSearchGroups.end())
return ;
ui->groupTreeWidget->removeSearchItem(it->second) ;
mSearchGroups.erase(it);
}
void GxsGroupFrameDialog::removeAllSearches()
{
for(auto it(mSearchGroups.begin());it!=mSearchGroups.end();++it)
ui->groupTreeWidget->removeSearchItem(it->second) ;
mSearchGroups.clear();
}
void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point) void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
{ {
// First separately handle the case of search top level items
TurtleRequestId search_request_id = 0 ;
if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id))
{
QMenu contextMnu(this);
contextMnu.addAction(QIcon(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id);
contextMnu.addAction(QIcon(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches()));
contextMnu.exec(QCursor::pos());
return ;
}
QString id = ui->groupTreeWidget->itemIdAt(point); QString id = ui->groupTreeWidget->itemIdAt(point);
if (id.isEmpty()) return; if (id.isEmpty()) return;
mGroupId = RsGxsGroupId(id.toStdString()); mGroupId = RsGxsGroupId(id.toStdString());
int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString())); int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString()));
bool isAdmin = IS_GROUP_ADMIN(subscribeFlags); bool isAdmin = IS_GROUP_ADMIN(subscribeFlags);
bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags); bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags); bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
QMenu contextMnu(this); QMenu contextMnu(this);
@ -1088,11 +1128,14 @@ TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string)
void GxsGroupFrameDialog::searchNetwork(const QString& search_string) void GxsGroupFrameDialog::searchNetwork(const QString& search_string)
{ {
if(search_string.isNull())
return ;
uint32_t request_id = distantSearch(search_string); uint32_t request_id = distantSearch(search_string);
if(request_id == 0) if(request_id == 0)
return ; return ;
mSearchGroups[request_id] = ui->groupTreeWidget->addCategoryItem(tr("Search for")+ " \"" + search_string + "\"", QIcon(icon(ICON_SEARCH)), true); mSearchGroups[request_id] = ui->groupTreeWidget->addSearchItem(tr("Search for")+ " \"" + search_string + "\"",(uint32_t)request_id,QIcon(icon(ICON_SEARCH)));
} }

View File

@ -130,7 +130,10 @@ private slots:
void sharePublishKey(); void sharePublishKey();
void loadComment(const RsGxsGroupId &grpId, const QVector<RsGxsMessageId>& msg_versions,const RsGxsMessageId &most_recent_msgId, const QString &title); void loadComment(const RsGxsGroupId &grpId, const QVector<RsGxsMessageId>& msg_versions,const RsGxsMessageId &most_recent_msgId, const QString &title);
void searchNetwork(const QString &search_string) ; void searchNetwork(const QString &search_string) ;
void removeAllSearches();
void removeCurrentSearch();
private: private:
virtual QString text(TextType type) = 0; virtual QString text(TextType type) = 0;