+ treeModelPointer = new QStandardItemModel();
+
+ // Auto resize the headers.
+ draggableTreeViewPointer->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+
+ // Indicate that all the rows are the same height, which improves performance.
+ draggableTreeViewPointer->setUniformRowHeights(true);
+
+ // Set the selection mode to allow multiple rows to be selected at once.
+ draggableTreeViewPointer->setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ // Allow dragging of bookmarks to reorder.
+ draggableTreeViewPointer->setDragDropMode(QAbstractItemView::InternalMove);
+
+ // Set the tree model.
+ draggableTreeViewPointer->setModel(treeModelPointer);
+
+ // Get a handle for the tree selection model.
+ treeSelectionModelPointer = draggableTreeViewPointer->selectionModel();
+
+ // Listen for selection changes.
+ connect(treeSelectionModelPointer, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(updateUi()));
+
+ // Repopulate the bookmarks when they are moved.
+ connect(draggableTreeViewPointer, SIGNAL(bookmarksMoved()), this, SLOT(refreshBookmarks()));
+
+ // Get handles for the buttons.
+ QPushButton *addBookmarkButtonPointer = bookmarksDialogUi.addBookmarkButton;
+ editButtonPointer = bookmarksDialogUi.editButton;
+ deleteItemsButtonPointer = bookmarksDialogUi.deleteItemsButton;
+ QDialogButtonBox *dialogButtonBoxPointer = bookmarksDialogUi.dialogButtonBox;
+ QPushButton *closeButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Close);
+
+ // Connect the buttons.
+ connect(addBookmarkButtonPointer, SIGNAL(clicked()), this, SLOT(showAddBookmarkDialog()));
+ connect(editButtonPointer, SIGNAL(clicked()), this, SLOT(showEditDialog()));
+ connect(deleteItemsButtonPointer, SIGNAL(clicked()), this, SLOT(deleteItems()));
+ connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
+
+ // Set the close button to be the default.
+ closeButtonPointer->setDefault(true);
+
+ // Monitor editing of data in the tree model.
+ connect(treeModelPointer, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateBookmarkFromTree(QStandardItem*)));
+
+ // Populate the bookmarks.
+ populateBookmarks();
+}
+
+void BookmarksDialog::deleteItems() const
+{
+ // Get the list of selected model indexes.
+ QList<QModelIndex> selectedModelIndexList = treeSelectionModelPointer->selectedRows(DATABASE_ID_COLUMN);
+
+ // Delete each of the bookmarks.
+ for (const QModelIndex &modelIndex : selectedModelIndexList)
+ {
+ // Delete the bookmark.
+ BookmarksDatabase::deleteBookmark(modelIndex.data().toInt());
+ }
+
+ // Repopulate the bookmarks in this dialog
+ populateBookmarks();
+
+ // Emit the bookmark updated signal to redraw the bookmarks in the menu and toolbar.
+ emit bookmarkUpdated();
+}
+
+void BookmarksDialog::populateBookmarks() const
+{
+ // Clear the current contents of the tree model.
+ treeModelPointer->clear();