Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
417c4497
Commit
417c4497
authored
Jun 01, 2010
by
Dan Pascu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored SessionModel's add/remove functionality
parent
d4a70301
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
59 deletions
+12
-59
sessions.py
blink/sessions.py
+12
-59
No files found.
blink/sessions.py
View file @
417c4497
...
...
@@ -376,8 +376,8 @@ class SessionDelegate(QStyledItemDelegate):
class
SessionModel
(
QAbstractListModel
):
session
sAdded
=
pyqtSignal
(
list
)
session
sRemoved
=
pyqtSignal
(
list
)
session
Added
=
pyqtSignal
(
SessionItem
)
session
Removed
=
pyqtSignal
(
SessionItem
)
# The MIME types we accept in drop operations, in the order they should be handled
accepted_mime_types
=
[
'application/x-blink-session-list'
,
'application/x-blink-contact-list'
]
...
...
@@ -447,7 +447,7 @@ class SessionModel(QAbstractListModel):
session_list
.
setSelectionMode
(
session_list
.
NoSelection
)
selection_model
.
clearSelection
()
if
target
.
conference
is
not
None
:
self
.
_
pop
_session
(
source
)
self
.
_
remove
_session
(
source
)
position
=
self
.
sessions
.
index
(
target
.
conference
.
sessions
[
-
1
])
+
1
self
.
beginInsertRows
(
QModelIndex
(),
position
,
position
)
self
.
sessions
.
insert
(
position
,
source
)
...
...
@@ -458,8 +458,8 @@ class SessionModel(QAbstractListModel):
else
:
target_row
=
index
.
row
()
first
,
last
=
(
source
,
target
)
if
source_row
<
target_row
else
(
target
,
source
)
self
.
_
pop
_session
(
source
)
self
.
_
pop
_session
(
target
)
self
.
_
remove
_session
(
source
)
self
.
_
remove
_session
(
target
)
self
.
beginInsertRows
(
QModelIndex
(),
0
,
1
)
self
.
sessions
[
0
:
0
]
=
[
first
,
last
]
self
.
endInsertRows
()
...
...
@@ -485,15 +485,15 @@ class SessionModel(QAbstractListModel):
sibling
=
first
if
source
is
last
else
last
source
.
conference
=
None
sibling
.
conference
=
None
self
.
_
pop
_session
(
first
)
self
.
_
pop
_session
(
last
)
self
.
_
remove
_session
(
first
)
self
.
_
remove
_session
(
last
)
self
.
_add_session
(
first
)
self
.
_add_session
(
last
)
position
=
self
.
sessions
.
index
(
sibling
)
session_list
.
scrollToBottom
()
else
:
source
.
conference
=
None
self
.
_
pop
_session
(
source
)
self
.
_
remove
_session
(
source
)
self
.
_add_session
(
source
)
position
=
self
.
sessions
.
index
(
conference
.
sessions
[
0
])
session_list
.
scrollTo
(
self
.
index
(
position
),
session_list
.
PositionAtCenter
)
...
...
@@ -504,36 +504,6 @@ class SessionModel(QAbstractListModel):
def
_DH_ApplicationXBlinkContactList
(
self
,
mime_data
,
action
,
index
):
return
False
@
staticmethod
def
range_iterator
(
indexes
):
"""Return contiguous ranges from indexes"""
start
=
last
=
None
for
index
in
sorted
(
indexes
):
if
start
is
None
:
start
=
index
elif
index
-
last
>
1
:
yield
(
start
,
last
)
start
=
index
last
=
index
else
:
if
indexes
:
yield
(
start
,
last
)
@
staticmethod
def
reversed_range_iterator
(
indexes
):
"""Return contiguous ranges from indexes starting from the end"""
end
=
last
=
None
for
index
in
reversed
(
sorted
(
indexes
)):
if
end
is
None
:
end
=
index
elif
last
-
index
>
1
:
yield
(
last
,
end
)
end
=
index
last
=
index
else
:
if
indexes
:
yield
(
last
,
end
)
def
_add_session
(
self
,
session
):
position
=
len
(
self
.
sessions
)
self
.
beginInsertRows
(
QModelIndex
(),
position
,
position
)
...
...
@@ -541,40 +511,23 @@ class SessionModel(QAbstractListModel):
self
.
session_list
.
openPersistentEditor
(
self
.
index
(
position
))
self
.
endInsertRows
()
def
_
pop
_session
(
self
,
session
):
def
_
remove
_session
(
self
,
session
):
position
=
self
.
sessions
.
index
(
session
)
self
.
beginRemoveRows
(
QModelIndex
(),
position
,
position
)
del
self
.
sessions
[
position
]
self
.
endRemoveRows
()
return
session
def
_pop_sessions
(
self
,
indexes
):
sessions
=
[]
rows
=
set
(
index
.
row
()
for
index
in
indexes
if
index
.
isValid
())
for
start
,
end
in
self
.
reversed_range_iterator
(
rows
):
self
.
beginRemoveRows
(
QModelIndex
(),
start
,
end
)
sessions
[
0
:
0
]
=
self
.
sessions
[
start
:
end
+
1
]
del
self
.
sessions
[
start
:
end
+
1
]
self
.
endRemoveRows
()
return
sessions
def
addSession
(
self
,
session
):
if
session
in
self
.
sessions
:
return
self
.
_add_session
(
session
)
self
.
session
sAdded
.
emit
([
session
]
)
self
.
session
Added
.
emit
(
session
)
def
removeSession
(
self
,
session
):
if
session
not
in
self
.
sessions
:
return
self
.
_pop_session
(
session
)
self
.
sessionsRemoved
.
emit
([
session
])
def
removeSessions
(
self
,
indexes
):
sessions
=
self
.
_pop_sessions
(
indexes
)
for
session
in
sessions
:
session
.
widget
=
Null
self
.
sessionsRemoved
.
emit
(
sessions
)
self
.
_remove_session
(
session
)
self
.
sessionRemoved
.
emit
(
session
)
def
test
(
self
):
self
.
addSession
(
SessionItem
(
'Dan Pascu'
,
'dan@umts.ro'
,
[]))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment