Commit ee249bfa authored by Edric Milaret's avatar Edric Milaret

transfer: fix segfault in ui

Issue: #81134
Change-Id: I3ebcf567e8a12a92cd02fe84b932e4ab191c776c
parent c54e2278
...@@ -31,13 +31,15 @@ TransferDialog::TransferDialog(QWidget *parent) : ...@@ -31,13 +31,15 @@ TransferDialog::TransferDialog(QWidget *parent) :
this->setWindowFlags(Qt::CustomizeWindowHint); this->setWindowFlags(Qt::CustomizeWindowHint);
this->setWindowFlags(Qt::FramelessWindowHint); this->setWindowFlags(Qt::FramelessWindowHint);
auto activeProxy = new ActiveCallsProxyModel(CallModel::instance()); activeProxy_ = new ActiveCallsProxyModel(CallModel::instance());
ui->activeCallsView->setModel(activeProxy); activeProxy_->setDynamicSortFilter(false);
ui->activeCallsView->setModel(activeProxy_);
ui->activeCallsView->clearSelection(); ui->activeCallsView->clearSelection();
} }
TransferDialog::~TransferDialog() TransferDialog::~TransferDialog()
{ {
removeProxyModel();
delete ui; delete ui;
} }
...@@ -53,8 +55,10 @@ TransferDialog::showEvent(QShowEvent *event) ...@@ -53,8 +55,10 @@ TransferDialog::showEvent(QShowEvent *event)
void void
TransferDialog::on_transferButton_clicked() TransferDialog::on_transferButton_clicked()
{ {
removeProxyModel();
auto callList = CallModel::instance()->getActiveCalls(); auto callList = CallModel::instance()->getActiveCalls();
for (auto c : callList) { Q_FOREACH(Call* c, callList) {
if (c->state() == Call::State::CURRENT) { if (c->state() == Call::State::CURRENT) {
if (not ui->numberBar->text().isEmpty()) { if (not ui->numberBar->text().isEmpty()) {
auto number = PhoneDirectoryModel::instance()->getNumber(ui->numberBar->text()); auto number = PhoneDirectoryModel::instance()->getNumber(ui->numberBar->text());
...@@ -68,18 +72,29 @@ TransferDialog::on_transferButton_clicked() ...@@ -68,18 +72,29 @@ TransferDialog::on_transferButton_clicked()
} }
} }
void TransferDialog::removeProxyModel()
{
//This prevent a crash happening in Qt5.5 in QSortFilterProxyModel
ui->activeCallsView->setModel(nullptr);
if (activeProxy_) {
delete activeProxy_;
activeProxy_ = nullptr;
}
}
void void
TransferDialog::on_activeCallsView_doubleClicked(const QModelIndex &index) TransferDialog::on_activeCallsView_doubleClicked(const QModelIndex &index)
{ {
Q_UNUSED(index)
removeProxyModel();
auto callList = CallModel::instance()->getActiveCalls(); auto callList = CallModel::instance()->getActiveCalls();
for (auto c : callList) { Q_FOREACH(Call* c, callList) {
if (c->state() == Call::State::CURRENT) { if (c->state() == Call::State::CURRENT) {
auto selectedCall = CallModel::instance()->getCall(index); CallModel::instance()->attendedTransfer(c, selectedCall_);
if (c != selectedCall) {
CallModel::instance()->attendedTransfer(c, selectedCall);
this->close(); this->close();
return; return;
}
} }
} }
} }
......
...@@ -36,8 +36,13 @@ public: ...@@ -36,8 +36,13 @@ public:
} }
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{ {
return sourceModel()->index(source_row,0,source_parent) if (not sourceModel() || source_parent.isValid())
.data(static_cast<int>(Call::Role::State)).value<Call::State>() != Call::State::CURRENT; return false;
auto idx = sourceModel()->index(source_row,0,source_parent);
if (not idx.isValid())
return false;
return idx.data(static_cast<int>(Call::Role::State))
.value<Call::State>() != Call::State::CURRENT;
} }
}; };
...@@ -61,5 +66,8 @@ private slots: ...@@ -61,5 +66,8 @@ private slots:
private: private:
Ui::TransferDialog *ui; Ui::TransferDialog *ui;
Call *selectedCall_; Call *selectedCall_;
ActiveCallsProxyModel *activeProxy_;
void removeProxyModel();
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment