Qt: Fix various smalles issues with drag-drop

Cleanup adding a filter and implement some
sanity checks in the drop code

Change-Id: I1778be16abdea3f93ed11fc610962c4a23f10a2f
Reviewed-on: https://code.wireshark.org/review/24505
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2017-11-20 09:56:26 +01:00 committed by Roland Knall
parent 4fbb2df3cd
commit 6917ec769e
4 changed files with 35 additions and 10 deletions

View File

@ -63,6 +63,9 @@ void FilterExpressionFrame::addExpression(const QString filter_text)
editExpression_ = -1;
ui->displayFilterLineEdit->setText(filter_text);
if (! isVisible())
animatedShow();
}
void FilterExpressionFrame::editExpression(int exprIdx)

View File

@ -1744,7 +1744,6 @@ void MainWindow::on_actionDisplayFilterExpression_triggered()
void MainWindow::on_actionNewDisplayFilterExpression_triggered()
{
main_ui_->filterExpressionFrame->addExpression(df_combo_box_->lineEdit()->text());
showAccordionFrame(main_ui_->filterExpressionFrame);
}
// On Qt4 + macOS with unifiedTitleAndToolBarOnMac set it's possible to make

View File

@ -86,6 +86,12 @@ void DragDropToolBar::childEvent(QChildEvent * event)
}
}
void DragDropToolBar::clear()
{
QToolBar::clear();
childCounter = 0;
}
bool DragDropToolBar::eventFilter(QObject * obj, QEvent * event)
{
if ( ! obj->isWidgetType() )
@ -108,6 +114,11 @@ bool DragDropToolBar::eventFilter(QObject * obj, QEvent * event)
if ( ( ev->buttons() & Qt::LeftButton ) && (ev->pos() - dragStartPosition).manhattanLength()
> QApplication::startDragDistance())
{
bool success = false;
int element = elem->property(drag_drop_toolbar_action_).toInt(&success);
if ( ! success )
return false;
ToolbarEntryMimeData * temd =
new ToolbarEntryMimeData(((QToolButton *)elem)->text(), elem->property(drag_drop_toolbar_action_).toInt());
DragLabel * lbl = new DragLabel(temd->labelText(), this);
@ -154,14 +165,6 @@ void DragDropToolBar::dragEnterEvent(QDragEnterEvent *event)
} else {
event->acceptProposedAction();
}
} else if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
if ( event->source() != this )
{
event->setDropAction(Qt::CopyAction);
event->accept();
} else {
event->acceptProposedAction();
}
} else {
event->ignore();
}
@ -174,6 +177,22 @@ void DragDropToolBar::dragMoveEvent(QDragMoveEvent *event)
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()))
{
QAction * actionAtPos = actionAt(event->pos() );
if ( actionAtPos )
{
QWidget * widget = widgetForAction(actionAtPos);
if ( widget )
{
bool success = false;
widget->property(drag_drop_toolbar_action_).toInt(&success);
if ( ! success )
{
event->ignore();
return;
}
}
}
if (event->source() == this) {
event->setDropAction(Qt::MoveAction);
event->accept();
@ -211,7 +230,9 @@ void DragDropToolBar::dropEvent(QDropEvent *event)
widgetForAction(action)->setStyleSheet("QWidget { border: none; };");
newPos = widgetForAction(action)->property(drag_drop_toolbar_action_).toInt();
moveToolbarItems(oldPos, newPos);
emit actionMoved(actions().at(oldPos), oldPos, newPos);
QAction * moveAction = actions().at(oldPos);
emit actionMoved(moveAction, oldPos, newPos);
}
if (event->source() == this) {

View File

@ -34,6 +34,8 @@ public:
explicit DragDropToolBar(QWidget *parent = Q_NULLPTR);
~DragDropToolBar();
virtual void clear();
Q_SIGNALS:
void actionMoved(QAction * action, int oldPos, int newPos);