Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
orderdialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5#include "iconloader_p.h"
6#include "ui_orderdialog.h"
7
8#include <QtDesigner/qextensionmanager.h>
9#include <QtDesigner/abstractformeditor.h>
10#include <QtDesigner/container.h>
11#include <QtCore/qabstractitemmodel.h>
12#include <QtWidgets/qpushbutton.h>
13
15
16using namespace Qt::StringLiterals;
17
18// OrderDialog: Used to reorder the pages of QStackedWidget and QToolBox.
19// Provides up and down buttons as well as DnD via QAbstractItemView::InternalMove mode
20namespace qdesigner_internal {
21
26{
27 m_ui->setupUi(this);
28 m_ui->upButton->setIcon(createIconSet("up.png"_L1));
29 m_ui->downButton->setIcon(createIconSet("down.png"_L1));
32 this, &OrderDialog::slotReset);
33 // Catch the remove operation of a DnD operation in QAbstractItemView::InternalMove mode to enable buttons
34 // Selection mode is 'contiguous' to enable DnD of groups
37
42
43 m_ui->upButton->setEnabled(false);
44 m_ui->downButton->setEnabled(false);
45}
46
48{
49 delete m_ui;
50}
51
56
58{
59 // The QWidget* are stored in a map indexed by the old index.
60 // The old index is set as user data on the item instead of the QWidget*
61 // because DnD is enabled which requires the user data to serializable
63 const qsizetype count = pages.size();
64 for (qsizetype i = 0; i < count; ++i)
65 m_orderMap.insert(int(i), pages.at(i));
66 buildList();
67}
68
70{
72 for (auto it = m_orderMap.cbegin(), cend = m_orderMap.cend(); it != cend; ++it) {
74 const int index = it.key();
75 switch (m_format) {
76 case PageOrderFormat:
77 item->setText(tr("Index %1 (%2)").arg(index).arg(it.value()->objectName()));
78 break;
79 case TabOrderFormat:
80 item->setText(tr("%1 %2").arg(index+1).arg(it.value()->objectName()));
81 break;
82 }
85 }
86
87 if (m_ui->pageList->count() > 0)
89}
90
92{
93 buildList();
94}
95
97{
99 const int count = m_ui->pageList->count();
100 for (int i=0; i < count; ++i) {
101 const int oldIndex = m_ui->pageList->item(i)->data(Qt::UserRole).toInt();
103 }
104 return rc;
105}
106
108{
109 const int row = m_ui->pageList->currentRow();
110 if (row <= 0)
111 return;
112
115}
116
118{
119 const int row = m_ui->pageList->currentRow();
120 if (row == -1 || row == m_ui->pageList->count() - 1)
121 return;
122
125}
126
128{
130}
131
133{
135}
136
137void OrderDialog::enableButtons(int r)
138{
139 m_ui->upButton->setEnabled(r > 0);
140 m_ui->downButton->setEnabled(r >= 0 && r < m_ui->pageList->count() - 1);
141}
142
153
154}
155
156QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.