Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSessionManagerDialog Class Reference

#include <KisSessionManagerDialog.h>

+ Inheritance diagram for KisSessionManagerDialog:

Public Member Functions

 KisSessionManagerDialog (QWidget *parent=nullptr)
 

Protected Member Functions

bool event (QEvent *event) override
 

Private Slots

void slotClose ()
 
void slotDeleteSession ()
 
void slotModelAboutToBeReset (QModelIndex)
 
void slotModelReset ()
 
void slotModelSelectionChanged (QItemSelection selected, QItemSelection deselected)
 
void slotNewSession ()
 
void slotRenameSession ()
 
void slotSessionDoubleClicked (QModelIndex item)
 
void slotSwitchSession ()
 

Private Member Functions

KisSessionResourceSP getSelectedSession () const
 
void updateButtons ()
 

Private Attributes

int m_lastSessionId
 
KisResourceModelm_model
 

Static Private Attributes

static int refreshEventType = -1
 

Detailed Description

Definition at line 19 of file KisSessionManagerDialog.h.

Constructor & Destructor Documentation

◆ KisSessionManagerDialog()

KisSessionManagerDialog::KisSessionManagerDialog ( QWidget * parent = nullptr)
explicit

Definition at line 18 of file KisSessionManagerDialog.cpp.

19 : QDialog(parent)
20{
21 setupUi(this);
22
23 // Register the custom event type that is used to defer UI updates
24 if (refreshEventType == -1) {
25 refreshEventType = QEvent::registerEventType();
26 }
27
28 connect(btnNew, SIGNAL(clicked()), this, SLOT(slotNewSession()));
29 connect(btnRename, SIGNAL(clicked()), this, SLOT(slotRenameSession()));
30 connect(btnSwitchTo, SIGNAL(clicked()), this, SLOT(slotSwitchSession()));
31 connect(btnDelete, SIGNAL(clicked()), this, SLOT(slotDeleteSession()));
32 connect(btnClose, SIGNAL(clicked()), this, SLOT(slotClose()));
33 connect(this, SIGNAL(finished(int)), this, SLOT(slotClose()));
34
36 lstSessions->setModel(m_model);
37 lstSessions->setModelColumn(KisAbstractResourceModel::Name);
38 lstSessions->setEditTriggers(QAbstractItemView::NoEditTriggers);
39
40 connect(lstSessions, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotSessionDoubleClicked(QModelIndex)));
41
42 connect(lstSessions->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotModelSelectionChanged(QItemSelection, QItemSelection)));
43
45}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
void slotSessionDoubleClicked(QModelIndex item)
void slotModelSelectionChanged(QItemSelection selected, QItemSelection deselected)
const QString Sessions

References connect(), m_model, KisAbstractResourceModel::Name, refreshEventType, ResourceType::Sessions, slotClose(), slotDeleteSession(), slotModelSelectionChanged(), slotNewSession(), slotRenameSession(), slotSessionDoubleClicked(), slotSwitchSession(), and updateButtons().

Member Function Documentation

◆ event()

bool KisSessionManagerDialog::event ( QEvent * event)
overrideprotected

Definition at line 47 of file KisSessionManagerDialog.cpp.

48{
49 if (event->type() == (QEvent::Type) refreshEventType) {
50 // Do the actual work of updating the button state when receiving a custom event
51 bool hasSelectedSession = getSelectedSession() != nullptr;
52 btnDelete->setEnabled(hasSelectedSession);
53 btnSwitchTo->setEnabled(hasSelectedSession);
54 btnRename->setEnabled(hasSelectedSession);
55 return true;
56 } else {
57 return QDialog::event(event);
58 }
59}
KisSessionResourceSP getSelectedSession() const
bool event(QEvent *event) override

References event(), getSelectedSession(), and refreshEventType.

◆ getSelectedSession()

KisSessionResourceSP KisSessionManagerDialog::getSelectedSession ( ) const
private

Definition at line 124 of file KisSessionManagerDialog.cpp.

125{
126 QModelIndex idx = lstSessions->currentIndex();
127 if (idx.isValid()) {
128 KoResourceSP res = m_model->resourceForIndex(idx); // lstSessions uses the same index as m_model
129 return res.dynamicCast<KisSessionResource>();
130 }
131 return nullptr;
132}
KoResourceSP resourceForIndex(QModelIndex index=QModelIndex()) const override
resourceForIndex returns a properly versioned and id'ed resource object

References m_model, and KisResourceModel::resourceForIndex().

◆ slotClose

void KisSessionManagerDialog::slotClose ( )
privateslot

Definition at line 142 of file KisSessionManagerDialog.cpp.

143{
144 hide();
146 if (w && !w->isVisible()) {
147 w->show();
148 }
149}
Main window for Krita.
static KisPart * instance()
Definition KisPart.cpp:131
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483

References KisPart::currentMainwindow(), and KisPart::instance().

◆ slotDeleteSession

void KisSessionManagerDialog::slotDeleteSession ( )
privateslot

Definition at line 134 of file KisSessionManagerDialog.cpp.

135{
136 QModelIndex idx = lstSessions->currentIndex();
137 if (idx.isValid()) {
138 m_model->setResourceInactive(lstSessions->currentIndex());
139 }
140}
bool setResourceInactive(const QModelIndex &index)

References m_model, and KisAbstractResourceModel::setResourceInactive().

◆ slotModelAboutToBeReset

void KisSessionManagerDialog::slotModelAboutToBeReset ( QModelIndex )
privateslot

Definition at line 151 of file KisSessionManagerDialog.cpp.

152{
153 QModelIndex idx = lstSessions->currentIndex();
154 if (idx.isValid()) {
155 m_lastSessionId = m_model->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
156 }
157}

References KisAbstractResourceModel::Id, m_lastSessionId, and m_model.

◆ slotModelReset

void KisSessionManagerDialog::slotModelReset ( )
privateslot

Definition at line 159 of file KisSessionManagerDialog.cpp.

160{
161 for (int i = 0; i < m_model->rowCount(); i++) {
162 QModelIndex idx = m_model->index(i, 0);
163 int id = m_model->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
164 if (id == m_lastSessionId) {
165 lstSessions->setCurrentIndex(idx);
166 }
167 }
168
170}

References KisAbstractResourceModel::Id, m_lastSessionId, m_model, and updateButtons().

◆ slotModelSelectionChanged

void KisSessionManagerDialog::slotModelSelectionChanged ( QItemSelection selected,
QItemSelection deselected )
privateslot

Definition at line 172 of file KisSessionManagerDialog.cpp.

173{
174 (void) selected;
175 (void) deselected;
176
178}
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)

References updateButtons(), and void().

◆ slotNewSession

void KisSessionManagerDialog::slotNewSession ( )
privateslot

Definition at line 68 of file KisSessionManagerDialog.cpp.

69{
70 QString name;
71
72 name = QInputDialog::getText(this,
73 i18n("Create session"),
74 i18n("Session name:"), QLineEdit::Normal,
75 name);
76 if (name.isEmpty()) return;
77
78 KisSessionResourceSP session(new KisSessionResource(QString(name)));
79
80 QString filename = name.split(" ").join("_") + session->defaultFileExtension();
81 session->setFilename(filename);
82 session->setName(name);
83 session->storeCurrentWindows();
84
86
88
89}
void setCurrentSession(KisSessionResourceSP session)
Definition KisPart.cpp:686
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
const char * name(StandardAction id)

References KisResourceUserOperations::addResourceWithUserInput(), KisPart::instance(), and KisPart::setCurrentSession().

◆ slotRenameSession

void KisSessionManagerDialog::slotRenameSession ( )
privateslot

Definition at line 91 of file KisSessionManagerDialog.cpp.

92{
93 QString name = QInputDialog::getText(this,
94 i18n("Rename session"),
95 i18n("New name:"), QLineEdit::Normal
96 );
97 if (name.isNull() || name.isEmpty()) return;
98
100 if (!session) return;
101
104}
static bool renameResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString resourceName)

References getSelectedSession(), KisResourceUserOperations::renameResourceWithUserInput(), and ResourceType::Sessions.

◆ slotSessionDoubleClicked

void KisSessionManagerDialog::slotSessionDoubleClicked ( QModelIndex item)
privateslot

Definition at line 106 of file KisSessionManagerDialog.cpp.

107{
109 slotClose();
110}

References slotClose(), and slotSwitchSession().

◆ slotSwitchSession

void KisSessionManagerDialog::slotSwitchSession ( )
privateslot

Definition at line 112 of file KisSessionManagerDialog.cpp.

113{
115
116 if (session) {
117 bool closed = KisPart::instance()->closeSession(true);
118 if (closed) {
120 }
121 }
122}
bool closeSession(bool keepWindows=false)
Definition KisPart.cpp:406
bool restoreSession(const QString &sessionName)
Definition KisPart.cpp:668

References KisPart::closeSession(), getSelectedSession(), KisPart::instance(), and KisPart::restoreSession().

◆ updateButtons()

void KisSessionManagerDialog::updateButtons ( )
private

Definition at line 61 of file KisSessionManagerDialog.cpp.

62{
63 // Defer updating the buttons by posting a custom event with low priority to avoid locking against
64 // a non-recursive session lock that may be already held by the thread
65 QApplication::postEvent(this, new QEvent((QEvent::Type) refreshEventType), Qt::LowEventPriority);
66}

References refreshEventType.

Member Data Documentation

◆ m_lastSessionId

int KisSessionManagerDialog::m_lastSessionId
private

Definition at line 48 of file KisSessionManagerDialog.h.

◆ m_model

KisResourceModel* KisSessionManagerDialog::m_model
private

Definition at line 50 of file KisSessionManagerDialog.h.

◆ refreshEventType

int KisSessionManagerDialog::refreshEventType = -1
staticprivate

Definition at line 52 of file KisSessionManagerDialog.h.


The documentation for this class was generated from the following files: