src/settingseditor/librarieseditor.cpp

Sun, 26 Jun 2022 20:27:04 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 26 Jun 2022 20:27:04 +0300
changeset 261
6a875faebde2
parent 259
c27612f0eac0
child 264
76a025db4948
permissions
-rw-r--r--

pi is no longer a template

7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QFileDialog>
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
2 #include <QMenu>
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include <QMessageBox>
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "librarieseditor.h"
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "ui_librarieseditor.h"
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
7 LibrariesEditor::LibrariesEditor(QWidget* parent) :
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 QWidget{parent},
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ui{*new Ui_LibrariesEditor}
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 this->ui.setupUi(this);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 connect(
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->ui.newLibrarySearch,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 &QPushButton::clicked,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 this,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 &LibrariesEditor::searchPathForNewLibrary);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 connect(
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 this->ui.newLibraryAdd,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 &QPushButton::clicked,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 this,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 &LibrariesEditor::addNewLibrary);
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
22 this->ui.librariesTable->setContextMenuPolicy(Qt::CustomContextMenu);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
23 connect(
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
24 this->ui.librariesTable,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
25 &QWidget::customContextMenuRequested,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
26 this,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
27 &LibrariesEditor::showContextMenu);
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
28 this->setEnabled(false);
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 LibrariesEditor::~LibrariesEditor()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 delete &this->ui;
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 void LibrariesEditor::searchPathForNewLibrary()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 const QString path = QFileDialog::getExistingDirectory(this, tr("Browse LDraw library"));
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 if (not path.isEmpty())
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 this->ui.newLibraryPath->setText(path);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 void LibrariesEditor::addNewLibrary()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
47 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
48 const QDir dir{this->ui.newLibraryPath->text()};
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
49 if (not dir.exists())
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
50 {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
51 QMessageBox::critical(
206
654661eab7f3 More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
52 this,
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 tr("Library does not exist"),
206
654661eab7f3 More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
54 tr("The directory %1 does not exist.").arg(quoted(dir.path()))
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
55 );
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
56 }
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
57 else
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
59 if (not dir.isReadable())
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
60 {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
61 QMessageBox::warning(this,
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 tr("Unreadable library"),
206
654661eab7f3 More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
63 tr("The directory %1 cannot be read.").arg(quoted(dir.path()))
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
64 );
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
65 }
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
66 model->addLibrary({Library::OfficialLibrary, dir});
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
67 this->ui.newLibraryPath->clear();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
72 void LibrariesEditor::showContextMenu(const QPoint position)
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
73 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
74 const std::size_t libraryIndex = this->currentLibraryIndex();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
75 LibrariesModel* model = this->currentModel();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
76 if (model != nullptr and model->isValidIndex(libraryIndex))
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
77 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
78 QMenu* contextMenu = new QMenu{this};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
79 QAction* removeAction = new QAction{tr("Remove library")};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
80 connect(
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
81 removeAction,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
82 &QAction::triggered,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
83 this,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
84 &LibrariesEditor::removeCurrentLibrary);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
85 QMenu* roleMenu = new QMenu{tr("Set role"), contextMenu};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
86 for (const Library::Role role : Library::allRoles)
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
87 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
88 QAction* setRoleAction = new QAction{Library::libraryRoleName(role)};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
89 setRoleAction->setData(role);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
90 roleMenu->addAction(setRoleAction);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
91 connect(
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
92 setRoleAction,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
93 &QAction::triggered,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
94 this,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
95 &LibrariesEditor::setCurrentLibraryRole);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
96 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
97 QAction* moveUpAction = new QAction{tr("Move up")};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
98 connect(
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
99 moveUpAction,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
100 &QAction::triggered,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
101 this,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
102 &LibrariesEditor::moveCurrentLibraryUp);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
103 QAction* moveDownAction = new QAction{tr("Move down")};
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
104 connect(
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
105 moveDownAction,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
106 &QAction::triggered,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
107 this,
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
108 &LibrariesEditor::moveCurrentLibraryDown);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
109 contextMenu->addMenu(roleMenu);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
110 contextMenu->addSeparator();
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
111 contextMenu->addAction(moveDownAction);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
112 contextMenu->addAction(moveUpAction);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
113 contextMenu->addAction(removeAction);
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
114 contextMenu->popup(this->ui.librariesTable->mapToGlobal(position));
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
115 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
116 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
117
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
118 void LibrariesEditor::setCurrentLibraryRole()
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
119 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
120 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
121 const std::size_t libraryIndex = currentLibraryIndex();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
122 QObject* senderObject = sender();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
123 QAction* senderAction = qobject_cast<QAction*>(senderObject);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
124 const Library::Role role = senderAction->data().value<Library::Role>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
125 model->setLibraryRole(libraryIndex, role);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
126 }
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
127 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
128
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
129 void LibrariesEditor::removeCurrentLibrary()
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
130 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
131 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
132 model->removeLibrary(currentLibraryIndex());
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
133 }
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
134 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
135
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
136 void LibrariesEditor::moveCurrentLibraryUp()
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
137 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
138 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
139 const std::size_t libraryIndex = this->currentLibraryIndex();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
140 model->moveLibrary(libraryIndex, libraryIndex - 1);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
141 }
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
142 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
143
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
144 void LibrariesEditor::moveCurrentLibraryDown()
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
145 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
146 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
147 const std::size_t libraryIndex = this->currentLibraryIndex();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
148 model->moveLibrary(libraryIndex + 1, libraryIndex);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
149 }
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
150 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
151
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
152 LibrariesModel *LibrariesEditor::currentModel()
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
153 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
154 return qobject_cast<LibrariesModel*>(this->ui.librariesTable->model());
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
155 }
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
156
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
157 std::size_t LibrariesEditor::currentLibraryIndex() const
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
158 {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
159 const int row = this->ui.librariesTable->selectionModel()->currentIndex().row();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
160 return static_cast<std::size_t>(row);
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
161 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
162
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
163 void LibrariesEditor::saveSettings()
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
164 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
165 if (LibrariesModel* model = this->currentModel()) {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
166 model->storeToSettings();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
167 }
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
168 }
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
169
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
170 void LibrariesEditor::setModel(LibrariesModel *model)
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
171 {
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
172 this->ui.librariesTable->setModel(model);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
173 this->setEnabled(model != nullptr);
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
174 }

mercurial