Revision control

Copy as Markdown

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include "../include/mainwindow.h"
#include "model.h"
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
menuBar()->addMenu(fileMenu);
//! [0]
QListView *listView = new QListView(this);
listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
listView->setDragEnabled(true);
listView->setAcceptDrops(true);
listView->setDropIndicatorShown(true);
//! [0]
this->listView = listView;
connect(quitAction, &QAction::triggered,
this, &QWidget::close);
setupListItems();
setCentralWidget(listView);
setWindowTitle(tr("List View"));
}
void MainWindow::setupListItems()
{
QStringList items;
items << tr("Oak") << tr("Fir") << tr("Pine") << tr("Birch") << tr("Hazel")
<< tr("Redwood") << tr("Sycamore") << tr("Chestnut")
<< tr("Mahogany");
DragDropListModel *model = new DragDropListModel(items, this);
listView->setModel(model);
}