@@ -1222,6 +1222,11 @@ QModelIndex UBDocumentTreeModel::goTo(const QString &dir)
12221222 if (!searchingNode) {
12231223 UBDocumentTreeNode *newChild = new UBDocumentTreeNode (UBDocumentTreeNode::Catalog, curLevelName);
12241224 parentIndex = addNode (newChild, parentIndex);
1225+
1226+ if (!parentIndex.isValid ())
1227+ {
1228+ delete newChild;
1229+ }
12251230 }
12261231 }
12271232
@@ -1266,7 +1271,10 @@ void UBDocumentTreeModel::addDocument(std::shared_ptr<UBDocumentProxy> pProxyDat
12661271 lParent = goTo (docGroupName);
12671272 }
12681273
1269- addNode (freeNode, lParent);
1274+ if (!addNode (freeNode, lParent).isValid ())
1275+ {
1276+ delete freeNode;
1277+ }
12701278}
12711279
12721280void UBDocumentTreeModel::addNewDocument (std::shared_ptr<UBDocumentProxy> pProxyData, const QModelIndex &pParent)
@@ -1281,7 +1289,14 @@ QModelIndex UBDocumentTreeModel::addCatalog(const QString &pName, const QModelIn
12811289 }
12821290
12831291 UBDocumentTreeNode *catalogNode = new UBDocumentTreeNode (UBDocumentTreeNode::Catalog, pName);
1284- return addNode (catalogNode, pParent);
1292+ QModelIndex index = addNode (catalogNode, pParent);
1293+
1294+ if (!index.isValid ())
1295+ {
1296+ delete catalogNode;
1297+ }
1298+
1299+ return index;
12851300}
12861301
12871302void UBDocumentTreeModel::setNewName (const QModelIndex &index, const QString &newName)
@@ -1569,7 +1584,12 @@ void UBDocumentTreeView::dragMoveEvent(QDragMoveEvent *event)
15691584 if (!docModel || !docModel->isDocument (targetIndex) || docModel->inTrash (targetIndex)) {
15701585 event->ignore ();
15711586 event->setDropAction (Qt::IgnoreAction);
1572- docModel->setHighLighted (QModelIndex ());
1587+
1588+ if (docModel)
1589+ {
1590+ docModel->setHighLighted (QModelIndex ());
1591+ }
1592+
15731593 acceptIt = false ;
15741594 } else {
15751595 docModel->setHighLighted (targetIndex);
@@ -1605,8 +1625,8 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
16051625 bool isUBPage = event->mimeData ()->hasFormat (UBApplication::mimeTypeUniboardPage);
16061626
16071627 // issue 1629 - NNE - 20131212
1608- bool targetIsInTrash = docModel->inTrash (targetIndex) || docModel->trashIndex () == targetIndex;
1609- bool targetIsInMyDocuments = docModel->inMyDocuments (targetIndex) || docModel->myDocumentsIndex () == targetIndex;
1628+ bool targetIsInTrash = docModel && (docModel ->inTrash (targetIndex) || docModel->trashIndex () == targetIndex) ;
1629+ bool targetIsInMyDocuments = docModel && (docModel ->inMyDocuments (targetIndex) || docModel->myDocumentsIndex () == targetIndex) ;
16101630
16111631 if (!targetIsInMyDocuments && !targetIsInTrash)
16121632 return ;
@@ -1829,15 +1849,15 @@ QWidget *UBDocumentTreeItemDelegate::createEditor(QWidget *parent, const QStyleO
18291849 const UBDocumentTreeModel *docModel = 0 ;
18301850
18311851 const UBSortFilterProxyModel *proxy = dynamic_cast <const UBSortFilterProxyModel*>(index.model ());
1852+ QModelIndex sourceIndex;
18321853
18331854 if (proxy){
18341855 docModel = dynamic_cast <UBDocumentTreeModel*>(proxy->sourceModel ());
1856+ sourceIndex = proxy->mapToSource (index);
18351857 }else {
18361858 docModel = dynamic_cast <const UBDocumentTreeModel*>(index.model ());
18371859 }
18381860
1839- QModelIndex sourceIndex = proxy->mapToSource (index);
1840-
18411861 if (docModel)
18421862 {
18431863 mExistingFileNames = docModel->nodeNameList (sourceIndex.parent ());
@@ -2225,6 +2245,8 @@ void UBDocumentController::setupViews()
22252245 adaptor->setAssociatedAction (currentExportAction);
22262246 }
22272247
2248+ bool exportMenuAttached = false ;
2249+
22282250#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22292251 foreach (QObject* menuWidget, mMainWindow ->actionExport ->associatedObjects ())
22302252#else
@@ -2239,9 +2261,15 @@ void UBDocumentController::setupViews()
22392261 tb->setPopupMode (QToolButton::InstantPopup);
22402262
22412263 tb->setMenu (exportMenu);
2264+ exportMenuAttached = true ;
22422265 }
22432266 }
22442267
2268+ if (!exportMenuAttached)
2269+ {
2270+ delete exportMenu;
2271+ }
2272+
22452273#ifdef Q_OS_OSX
22462274 mMainWindow ->actionDelete ->setShortcut (QKeySequence (Qt::Key_Backspace));
22472275#else
0 commit comments