Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
d44a611f
Commit
d44a611f
authored
Apr 14, 2017
by
Nicolas Carion
Browse files
clang-format source files
parent
387199e1
Changes
250
Expand all
Hide whitespace changes
Inline
Side-by-side
renderer/kdenlive_render.cpp
View file @
d44a611f
...
...
@@ -17,14 +17,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include
<stdio
.h
>
#include
"renderjob
.h
"
#include
<QCoreApplication>
#include
<Q
StringList
>
#include
<Q
Debug
>
#include
<QFileInfo>
#include
<QString>
#include
<QStringList>
#include
<QUrl>
#include
<QDebug>
#include
"renderjob.h"
#include
<stdio.h>
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -115,11 +115,13 @@ int main(int argc, char **argv)
for
(
int
i
=
0
;
i
<
args
.
count
();
++
i
)
{
if
(
args
.
at
(
i
).
startsWith
(
QLatin1String
(
"meta.attr"
)))
{
QString
data
=
args
.
at
(
i
);
args
.
replace
(
i
,
data
.
section
(
QLatin1Char
(
'='
),
0
,
0
)
+
QStringLiteral
(
"=
\"
"
)
+
QUrl
::
fromPercentEncoding
(
data
.
section
(
QLatin1Char
(
'='
),
1
).
toUtf8
())
+
QLatin1Char
(
'\"'
));
args
.
replace
(
i
,
data
.
section
(
QLatin1Char
(
'='
),
0
,
0
)
+
QStringLiteral
(
"=
\"
"
)
+
QUrl
::
fromPercentEncoding
(
data
.
section
(
QLatin1Char
(
'='
),
1
).
toUtf8
())
+
QLatin1Char
(
'\"'
));
}
}
qDebug
()
<<
"//STARTING RENDERING: "
<<
erase
<<
','
<<
usekuiserver
<<
','
<<
render
<<
','
<<
profile
<<
','
<<
rendermodule
<<
','
<<
player
<<
','
<<
src
<<
','
<<
dest
<<
','
<<
preargs
<<
','
<<
args
<<
','
<<
in
<<
','
<<
out
;
qDebug
()
<<
"//STARTING RENDERING: "
<<
erase
<<
','
<<
usekuiserver
<<
','
<<
render
<<
','
<<
profile
<<
','
<<
rendermodule
<<
','
<<
player
<<
','
<<
src
<<
','
<<
dest
<<
','
<<
preargs
<<
','
<<
args
<<
','
<<
in
<<
','
<<
out
;
auto
*
job
=
new
RenderJob
(
doerase
,
usekuiserver
,
pid
,
render
,
profile
,
rendermodule
,
player
,
src
,
dest
,
preargs
,
args
,
in
,
out
);
if
(
!
locale
.
isEmpty
())
{
job
->
setLocale
(
locale
);
...
...
@@ -137,8 +139,10 @@ int main(int argc, char **argv)
app
.
exec
();
delete
dualjob
;
}
else
{
fprintf
(
stderr
,
"Kdenlive video renderer for MLT.
\n
Usage: "
"kdenlive_render [-erase] [-kuiserver] [-locale:LOCALE] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] [arg2] ...]
\n
"
fprintf
(
stderr
,
"Kdenlive video renderer for MLT.
\n
Usage: "
"kdenlive_render [-erase] [-kuiserver] [-locale:LOCALE] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] "
"[arg2] ...]
\n
"
" -erase: if that parameter is present, src file will be erased at the end
\n
"
" -kuiserver: if that parameter is present, use KDE job tracker
\n
"
" -locale:LOCALE : set a locale for rendering. For example, -locale:fr_FR.UTF-8 will use a french locale (comma as numeric separator)
\n
"
...
...
@@ -153,4 +157,3 @@ int main(int argc, char **argv)
" args: space separated libavformat arguments
\n
"
);
}
}
renderer/renderjob.cpp
View file @
d44a611f
...
...
@@ -19,38 +19,23 @@
#include
"renderjob.h"
#include
<QtDBus>
#include
<QFile>
#include
<QThread>
#include
<QStringList>
#include
<QThread>
#include
<QtDBus>
// Can't believe I need to do this to sleep.
class
SleepThread
:
QThread
{
public:
void
run
()
override
{}
static
void
msleep
(
unsigned
long
msecs
)
{
QThread
::
msleep
(
msecs
);
}
static
void
msleep
(
unsigned
long
msecs
)
{
QThread
::
msleep
(
msecs
);
}
};
RenderJob
::
RenderJob
(
bool
erase
,
bool
usekuiserver
,
int
pid
,
const
QString
&
renderer
,
const
QString
&
profile
,
const
QString
&
rendermodule
,
const
QString
&
player
,
const
QString
&
scenelist
,
const
QString
&
dest
,
const
QStringList
&
preargs
,
const
QStringList
&
args
,
int
in
,
int
out
)
:
QObject
(),
m_scenelist
(
scenelist
),
m_dest
(
dest
),
m_progress
(
0
),
m_prog
(
renderer
),
m_player
(
player
),
m_jobUiserver
(
nullptr
),
m_kdenliveinterface
(
nullptr
),
m_usekuiserver
(
usekuiserver
),
m_logfile
(
dest
+
QStringLiteral
(
".txt"
)),
m_erase
(
erase
),
m_seconds
(
0
),
m_frame
(
0
),
m_pid
(
pid
),
m_dualpass
(
false
)
RenderJob
::
RenderJob
(
bool
erase
,
bool
usekuiserver
,
int
pid
,
const
QString
&
renderer
,
const
QString
&
profile
,
const
QString
&
rendermodule
,
const
QString
&
player
,
const
QString
&
scenelist
,
const
QString
&
dest
,
const
QStringList
&
preargs
,
const
QStringList
&
args
,
int
in
,
int
out
)
:
QObject
(),
m_scenelist
(
scenelist
),
m_dest
(
dest
),
m_progress
(
0
),
m_prog
(
renderer
),
m_player
(
player
),
m_jobUiserver
(
nullptr
),
m_kdenliveinterface
(
nullptr
),
m_usekuiserver
(
usekuiserver
),
m_logfile
(
dest
+
QStringLiteral
(
".txt"
)),
m_erase
(
erase
),
m_seconds
(
0
),
m_frame
(
0
),
m_pid
(
pid
),
m_dualpass
(
false
)
{
m_renderProcess
=
new
QProcess
;
m_renderProcess
->
setReadChannel
(
QProcess
::
StandardError
);
...
...
@@ -149,7 +134,7 @@ void RenderJob::receivedStderr()
m_kdenliveinterface
->
callWithArgumentList
(
QDBus
::
NoBlock
,
QStringLiteral
(
"setRenderingProgress"
),
m_dbusargs
);
}
if
(
m_jobUiserver
)
{
m_jobUiserver
->
call
(
QStringLiteral
(
"setPercent"
),
(
uint
)
m_progress
);
m_jobUiserver
->
call
(
QStringLiteral
(
"setPercent"
),
(
uint
)
m_progress
);
int
seconds
=
m_startTime
.
secsTo
(
QTime
::
currentTime
());
if
(
seconds
==
m_seconds
)
{
return
;
...
...
@@ -157,9 +142,10 @@ void RenderJob::receivedStderr()
if
(
seconds
<
0
)
{
seconds
+=
24
*
60
*
60
;
}
m_jobUiserver
->
call
(
QStringLiteral
(
"setDescriptionField"
),
(
uint
)
0
,
QString
(),
tr
(
"Remaining time: "
)
+
QTime
(
0
,
0
,
0
).
addSecs
((
int
)(
seconds
*
(
100
-
m_progress
)
/
m_progress
)).
toString
(
QStringLiteral
(
"hh:mm:ss"
)));
//m_jobUiserver->call("setSpeed", (frame - m_frame) / (seconds - m_seconds));
m_jobUiserver
->
call
(
QStringLiteral
(
"setDescriptionField"
),
(
uint
)
0
,
QString
(),
tr
(
"Remaining time: "
)
+
QTime
(
0
,
0
,
0
).
addSecs
((
int
)(
seconds
*
(
100
-
m_progress
)
/
m_progress
)).
toString
(
QStringLiteral
(
"hh:mm:ss"
)));
// m_jobUiserver->call("setSpeed", (frame - m_frame) / (seconds - m_seconds));
m_frame
=
frame
;
m_seconds
=
seconds
;
}
...
...
@@ -177,7 +163,7 @@ void RenderJob::start()
QTime
t
;
t
.
start
();
while
(
!
interface
->
isServiceRegistered
(
QStringLiteral
(
"org.kde.JobViewServer"
))
&&
t
.
elapsed
()
<
3000
)
{
SleepThread
::
msleep
(
100
);
//Sleep 100 ms
SleepThread
::
msleep
(
100
);
//
Sleep 100 ms
}
}
else
{
qWarning
()
<<
"Failed to start kuiserver"
;
...
...
@@ -186,8 +172,9 @@ void RenderJob::start()
if
(
interface
->
isServiceRegistered
(
QStringLiteral
(
"org.kde.JobViewServer"
)))
{
QDBusInterface
kuiserver
(
QStringLiteral
(
"org.kde.JobViewServer"
),
QStringLiteral
(
"/JobViewServer"
),
QStringLiteral
(
"org.kde.JobViewServer"
));
QDBusReply
<
QDBusObjectPath
>
objectPath
=
kuiserver
.
asyncCall
(
QStringLiteral
(
"requestView"
),
QLatin1String
(
"kdenlive"
),
QLatin1String
(
"kdenlive"
),
0x0001
);
QString
reply
=
((
QDBusObjectPath
)
objectPath
).
path
();
QDBusReply
<
QDBusObjectPath
>
objectPath
=
kuiserver
.
asyncCall
(
QStringLiteral
(
"requestView"
),
QLatin1String
(
"kdenlive"
),
QLatin1String
(
"kdenlive"
),
0x0001
);
QString
reply
=
((
QDBusObjectPath
)
objectPath
).
path
();
// Use of the KDE JobViewServer is an ugly hack, it is not reliable
QString
dbusView
=
QStringLiteral
(
"org.kde.JobViewV2"
);
...
...
@@ -195,11 +182,12 @@ void RenderJob::start()
if
((
m_jobUiserver
!=
nullptr
)
&&
m_jobUiserver
->
isValid
())
{
m_startTime
=
QTime
::
currentTime
();
if
(
!
m_args
.
contains
(
QStringLiteral
(
"pass=2"
)))
{
m_jobUiserver
->
call
(
QStringLiteral
(
"setPercent"
),
(
uint
)
0
);
m_jobUiserver
->
call
(
QStringLiteral
(
"setPercent"
),
(
uint
)
0
);
}
m_jobUiserver
->
call
(
QStringLiteral
(
"setInfoMessage"
),
tr
(
"Rendering %1"
).
arg
(
QFileInfo
(
m_dest
).
fileName
()));
QDBusConnection
::
sessionBus
().
connect
(
QStringLiteral
(
"org.kde.JobViewServer"
),
reply
,
dbusView
,
QStringLiteral
(
"cancelRequested"
),
this
,
SLOT
(
slotAbort
()));
QDBusConnection
::
sessionBus
().
connect
(
QStringLiteral
(
"org.kde.JobViewServer"
),
reply
,
dbusView
,
QStringLiteral
(
"cancelRequested"
),
this
,
SLOT
(
slotAbort
()));
}
}
}
...
...
@@ -238,20 +226,16 @@ void RenderJob::initKdenliveDbusInterface()
if
(
kdenliveId
.
isEmpty
())
{
return
;
}
m_kdenliveinterface
=
new
QDBusInterface
(
kdenliveId
,
QStringLiteral
(
"/kdenlive/MainWindow_1"
),
QStringLiteral
(
"org.kde.kdenlive.rendering"
),
connection
,
this
);
m_kdenliveinterface
=
new
QDBusInterface
(
kdenliveId
,
QStringLiteral
(
"/kdenlive/MainWindow_1"
),
QStringLiteral
(
"org.kde.kdenlive.rendering"
),
connection
,
this
);
if
(
m_kdenliveinterface
)
{
m_dbusargs
.
append
(
m_dest
);
m_dbusargs
.
append
((
int
)
0
);
m_dbusargs
.
append
((
int
)
0
);
if
(
!
m_args
.
contains
(
QStringLiteral
(
"pass=2"
)))
{
m_kdenliveinterface
->
callWithArgumentList
(
QDBus
::
NoBlock
,
QStringLiteral
(
"setRenderingProgress"
),
m_dbusargs
);
}
connect
(
m_kdenliveinterface
,
SIGNAL
(
abortRenderJob
(
QString
)),
this
,
SLOT
(
slotAbort
(
QString
)));
connect
(
m_kdenliveinterface
,
SIGNAL
(
abortRenderJob
(
QString
)),
this
,
SLOT
(
slotAbort
(
QString
)));
}
}
...
...
@@ -265,14 +249,13 @@ void RenderJob::slotCheckProcess(QProcess::ProcessState state)
void
RenderJob
::
slotIsOver
(
QProcess
::
ExitStatus
status
,
bool
isWritable
)
{
if
(
m_jobUiserver
)
{
m_jobUiserver
->
call
(
QStringLiteral
(
"setDescriptionField"
),
(
uint
)
1
,
tr
(
"Rendered file"
),
m_dest
);
//m_jobUiserver->call(QStringLiteral("terminate"), QString());
m_jobUiserver
->
call
(
QStringLiteral
(
"setDescriptionField"
),
(
uint
)
1
,
tr
(
"Rendered file"
),
m_dest
);
// m_jobUiserver->call(QStringLiteral("terminate"), QString());
}
if
(
!
isWritable
)
{
QString
error
=
tr
(
"Cannot write to %1, check permissions."
).
arg
(
m_dest
);
if
(
m_kdenliveinterface
)
{
m_dbusargs
[
1
]
=
(
int
)
-
2
;
m_dbusargs
[
1
]
=
(
int
)
-
2
;
m_dbusargs
.
append
(
error
);
m_kdenliveinterface
->
callWithArgumentList
(
QDBus
::
NoBlock
,
QStringLiteral
(
"setRenderingFinished"
),
m_dbusargs
);
}
...
...
@@ -286,7 +269,7 @@ void RenderJob::slotIsOver(QProcess::ExitStatus status, bool isWritable)
if
(
status
==
QProcess
::
CrashExit
||
m_renderProcess
->
error
()
!=
QProcess
::
UnknownError
||
m_renderProcess
->
exitCode
()
!=
0
)
{
// rendering crashed
if
(
m_kdenliveinterface
)
{
m_dbusargs
[
1
]
=
(
int
)
-
2
;
m_dbusargs
[
1
]
=
(
int
)
-
2
;
m_dbusargs
.
append
(
m_errorMessage
);
m_kdenliveinterface
->
callWithArgumentList
(
QDBus
::
NoBlock
,
QStringLiteral
(
"setRenderingFinished"
),
m_dbusargs
);
}
...
...
@@ -298,7 +281,7 @@ void RenderJob::slotIsOver(QProcess::ExitStatus status, bool isWritable)
qApp
->
quit
();
}
else
{
if
(
!
m_dualpass
&&
(
m_kdenliveinterface
!=
nullptr
))
{
m_dbusargs
[
1
]
=
(
int
)
-
1
;
m_dbusargs
[
1
]
=
(
int
)
-
1
;
m_dbusargs
.
append
(
QString
());
m_kdenliveinterface
->
callWithArgumentList
(
QDBus
::
NoBlock
,
QStringLiteral
(
"setRenderingFinished"
),
m_dbusargs
);
}
...
...
@@ -315,7 +298,7 @@ void RenderJob::slotIsOver(QProcess::ExitStatus status, bool isWritable)
if
(
m_dualpass
)
{
emit
renderingFinished
();
deleteLater
();
}
else
{
}
else
{
m_logfile
.
remove
();
qApp
->
quit
();
}
...
...
src/abstractmodel/abstracttreemodel.cpp
View file @
d44a611f
...
...
@@ -22,9 +22,7 @@
#include
"abstracttreemodel.hpp"
#include
"treeitem.hpp"
AbstractTreeModel
::
AbstractTreeModel
(
QObject
*
parent
)
:
QAbstractItemModel
(
parent
)
AbstractTreeModel
::
AbstractTreeModel
(
QObject
*
parent
)
:
QAbstractItemModel
(
parent
)
{
rootItem
=
new
TreeItem
(
QList
<
QVariant
>
(),
this
);
}
...
...
@@ -36,10 +34,9 @@ AbstractTreeModel::~AbstractTreeModel()
int
AbstractTreeModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
{
if
(
parent
.
isValid
())
return
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
())
->
columnCount
();
return
rootItem
->
columnCount
();
if
(
parent
.
isValid
())
return
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
())
->
columnCount
();
return
rootItem
->
columnCount
();
}
QVariant
AbstractTreeModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
...
...
@@ -51,7 +48,7 @@ QVariant AbstractTreeModel::data(const QModelIndex &index, int role) const
if
(
role
!=
Qt
::
DisplayRole
)
{
return
QVariant
();
}
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
return
item
->
dataColumn
(
index
.
column
());
}
...
...
@@ -60,7 +57,7 @@ Qt::ItemFlags AbstractTreeModel::flags(const QModelIndex &index) const
const
auto
flags
=
QAbstractItemModel
::
flags
(
index
);
if
(
index
.
isValid
())
{
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
if
(
item
->
depth
()
==
1
)
{
return
flags
&
~
Qt
::
ItemIsSelectable
;
}
...
...
@@ -68,61 +65,51 @@ Qt::ItemFlags AbstractTreeModel::flags(const QModelIndex &index) const
return
flags
;
}
QVariant
AbstractTreeModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
QVariant
AbstractTreeModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
{
if
(
orientation
==
Qt
::
Horizontal
&&
role
==
Qt
::
DisplayRole
)
return
rootItem
->
dataColumn
(
section
);
if
(
orientation
==
Qt
::
Horizontal
&&
role
==
Qt
::
DisplayRole
)
return
rootItem
->
dataColumn
(
section
);
return
QVariant
();
}
QModelIndex
AbstractTreeModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
QModelIndex
AbstractTreeModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
TreeItem
*
parentItem
;
if
(
!
parent
.
isValid
())
parentItem
=
rootItem
;
else
parentItem
=
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
());
parentItem
=
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
());
TreeItem
*
childItem
=
parentItem
->
child
(
row
);
if
(
childItem
)
return
createIndex
(
row
,
column
,
childItem
);
return
QModelIndex
();
if
(
childItem
)
return
createIndex
(
row
,
column
,
childItem
);
return
QModelIndex
();
}
QModelIndex
AbstractTreeModel
::
parent
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
QModelIndex
();
if
(
!
index
.
isValid
())
return
QModelIndex
();
TreeItem
*
childItem
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
childItem
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
parentItem
=
childItem
->
parentItem
();
if
(
parentItem
==
rootItem
)
return
QModelIndex
();
if
(
parentItem
==
rootItem
)
return
QModelIndex
();
return
createIndex
(
parentItem
->
row
(),
0
,
parentItem
);
}
int
AbstractTreeModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
TreeItem
*
parentItem
;
if
(
parent
.
column
()
>
0
)
return
0
;
if
(
parent
.
column
()
>
0
)
return
0
;
if
(
!
parent
.
isValid
())
parentItem
=
rootItem
;
else
parentItem
=
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
());
parentItem
=
static_cast
<
TreeItem
*>
(
parent
.
internalPointer
());
return
parentItem
->
childCount
();
}
...
...
src/abstractmodel/treeitem.cpp
View file @
d44a611f
...
...
@@ -22,7 +22,7 @@
#include
"treeitem.hpp"
#include
"abstracttreemodel.hpp"
TreeItem
::
TreeItem
(
const
QList
<
QVariant
>
&
data
,
AbstractTreeModel
*
model
,
TreeItem
*
parent
)
TreeItem
::
TreeItem
(
const
QList
<
QVariant
>
&
data
,
AbstractTreeModel
*
model
,
TreeItem
*
parent
)
{
m_parentItem
=
parent
;
m_itemData
=
data
;
...
...
@@ -35,7 +35,7 @@ TreeItem::~TreeItem()
qDeleteAll
(
m_childItems
);
}
TreeItem
*
TreeItem
::
appendChild
(
const
QList
<
QVariant
>
&
data
)
TreeItem
*
TreeItem
::
appendChild
(
const
QList
<
QVariant
>
&
data
)
{
m_model
->
notifyRowAboutToAppend
(
this
);
auto
*
child
=
new
TreeItem
(
data
,
m_model
,
this
);
...
...
@@ -101,8 +101,7 @@ TreeItem *TreeItem::parentItem()
int
TreeItem
::
row
()
const
{
if
(
m_parentItem
)
return
m_parentItem
->
m_childItems
.
indexOf
(
const_cast
<
TreeItem
*>
(
this
));
if
(
m_parentItem
)
return
m_parentItem
->
m_childItems
.
indexOf
(
const_cast
<
TreeItem
*>
(
this
));
return
-
1
;
}
...
...
@@ -111,4 +110,3 @@ int TreeItem::depth() const
{
return
m_depth
;
}
src/assets/assetlist/model/assetfilter.cpp
View file @
d44a611f
...
...
@@ -20,24 +20,21 @@
***************************************************************************/
#include
"assetfilter.hpp"
#include
"assettreemodel.hpp"
#include
"abstractmodel/treeitem.hpp"
#include
"assettreemodel.hpp"
AssetFilter
::
AssetFilter
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
,
m_name_enabled
(
false
)
AssetFilter
::
AssetFilter
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
),
m_name_enabled
(
false
)
{
}
void
AssetFilter
::
setFilterName
(
bool
enabled
,
const
QString
&
pattern
)
void
AssetFilter
::
setFilterName
(
bool
enabled
,
const
QString
&
pattern
)
{
m_name_enabled
=
enabled
;
m_name_value
=
pattern
;
invalidateFilter
();
}
bool
AssetFilter
::
filterName
(
TreeItem
*
item
)
const
bool
AssetFilter
::
filterName
(
TreeItem
*
item
)
const
{
if
(
!
m_name_enabled
)
{
return
true
;
...
...
@@ -52,10 +49,10 @@ bool AssetFilter::filterName(TreeItem* item) const
bool
AssetFilter
::
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
sourceParent
)
const
{
QModelIndex
row
=
sourceModel
()
->
index
(
sourceRow
,
0
,
sourceParent
);
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
row
.
internalPointer
());
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
row
.
internalPointer
());
if
(
item
->
dataColumn
(
AssetTreeModel
::
idCol
)
==
QStringLiteral
(
"root"
))
{
//In that case, we have a category. We hide it if it does not have children.
//
In that case, we have a category. We hide it if it does not have children.
QModelIndex
category
=
sourceModel
()
->
index
(
sourceRow
,
0
,
sourceParent
);
bool
accepted
=
false
;
for
(
int
i
=
0
;
i
<
sourceModel
()
->
rowCount
(
category
)
&&
!
accepted
;
++
i
)
{
...
...
@@ -72,8 +69,7 @@ bool AssetFilter::isVisible(const QModelIndex &sourceIndex)
return
filterAcceptsRow
(
sourceIndex
.
row
(),
parent
);
}
bool
AssetFilter
::
applyAll
(
TreeItem
*
item
)
const
bool
AssetFilter
::
applyAll
(
TreeItem
*
item
)
const
{
return
filterName
(
item
);
}
src/assets/assetlist/model/assettreemodel.cpp
View file @
d44a611f
...
...
@@ -20,21 +20,19 @@
***************************************************************************/
#include
"assettreemodel.hpp"
#include
"abstractmodel/treeitem.hpp"
#include
"effects/effectsrepository.hpp"
#include
"transitions/transitionsrepository.hpp"
#include
"abstractmodel/treeitem.hpp"
int
AssetTreeModel
::
nameCol
=
0
;
int
AssetTreeModel
::
idCol
=
1
;
int
AssetTreeModel
::
typeCol
=
2
;
int
AssetTreeModel
::
favCol
=
3
;
AssetTreeModel
::
AssetTreeModel
(
QObject
*
parent
)
:
AbstractTreeModel
(
parent
)
AssetTreeModel
::
AssetTreeModel
(
QObject
*
parent
)
:
AbstractTreeModel
(
parent
)
{
}
QHash
<
int
,
QByteArray
>
AssetTreeModel
::
roleNames
()
const
{
QHash
<
int
,
QByteArray
>
roles
;
...
...
@@ -43,48 +41,45 @@ QHash<int, QByteArray> AssetTreeModel::roleNames() const
return
roles
;
}
QString
AssetTreeModel
::
getName
(
const
QModelIndex
&
index
)
const
QString
AssetTreeModel
::
getName
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
{
return
QString
();
}
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
if
(
item
->
depth
()
==
1
)
{
return
item
->
dataColumn
(
0
).
toString
();
}
return
item
->
dataColumn
(
AssetTreeModel
::
nameCol
).
toString
();
}
return
item
->
dataColumn
(
AssetTreeModel
::
nameCol
).
toString
();
}
QString
AssetTreeModel
::
getDescription
(
const
QModelIndex
&
index
)
const
QString
AssetTreeModel
::
getDescription
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
{
return
QString
();
}
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
if
(
item
->
depth
()
==
1
)
{
return
QString
();
}
auto
id
=
item
->
dataColumn
(
AssetTreeModel
::
idCol
).
toString
();
if
(
EffectsRepository
::
get
()
->
exists
(
id
)){
return
EffectsRepository
::
get
()
->
getDescription
(
id
);
}
if
(
TransitionsRepository
::
get
()
->
exists
(
id
)){
return
TransitionsRepository
::
get
()
->
getDescription
(
id
);
}
return
QString
();
}
auto
id
=
item
->
dataColumn
(
AssetTreeModel
::
idCol
).
toString
();
if
(
EffectsRepository
::
get
()
->
exists
(
id
))
{
return
EffectsRepository
::
get
()
->
getDescription
(
id
);
}
if
(
TransitionsRepository
::
get
()
->
exists
(
id
))
{
return
TransitionsRepository
::
get
()
->
getDescription
(
id
);
}
return
QString
();
}
QVariant
AssetTreeModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
!
index
.
isValid
())
{
return
QVariant
();
}
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
if
(
role
==
IdRole
)
{
TreeItem
*
item
=
static_cast
<
TreeItem
*>
(
index
.
internalPointer
());
if
(
role
==
IdRole
)
{
return
item
->
dataColumn
(
AssetTreeModel
::
idCol
);
}
...
...
@@ -94,12 +89,12 @@ QVariant AssetTreeModel::data(const QModelIndex &index, int role) const
return
item
->
dataColumn
(
index
.
column
());
}
QList
<
QModelIndex
>
AssetTreeModel
::
getChildrenIndexes
()
QList
<
QModelIndex
>
AssetTreeModel
::
getChildrenIndexes
()
{
QList
<
QModelIndex
>
indexes
;
for
(
int
i
=
0
;
i
!=
rootItem
->
childCount
();
++
i
)
{
QList
<
QModelIndex
>
indexes
;
for
(
int
i
=
0
;
i
!=
rootItem
->
childCount
();
++
i
)
{
TreeItem
*
child
=
rootItem
->
child
(
i
);
indexes
<<
createIndex
(
i
,
0
,
child
);
indexes
<<
createIndex
(
i
,
0
,
child
);
}
return
indexes
;
...
...
src/assets/assetlist/view/assetlistwidget.cpp
View file @
d44a611f
...
...
@@ -23,12 +23,11 @@
#include
"assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include
<KDeclarative/KDeclarative>
#include
<QStandardPaths>
#include
<QQmlContext>
#include
<QQuickItem>
#include
<QStandardPaths>
AssetListWidget
::
AssetListWidget
(
QWidget
*
parent
)
:
QQuickWidget
(
parent
)
AssetListWidget
::
AssetListWidget
(
QWidget
*
parent
)
:
QQuickWidget
(
parent
)
{
}
...
...
@@ -44,33 +43,31 @@ void AssetListWidget::setup()
setFocusPolicy
(
Qt
::
StrongFocus
);
}
QString
AssetListWidget
::
getName
(
const
QModelIndex
&
index
)
const
QString
AssetListWidget
::
getName
(
const
QModelIndex
&
index
)
const
{
return
m_model
->
getName
(
m_proxyModel
->
mapToSource
(
index
));
}
QString
AssetListWidget
::
getDescription
(
const
QModelIndex
&
index
)
const
QString
AssetListWidget
::
getDescription
(
const
QModelIndex
&
index
)
const
{
return
m_model
->
getDescription
(
m_proxyModel
->
mapToSource
(
index
));
}
void
AssetListWidget
::
setFilterName
(
const
QString
&
pattern
)
void
AssetListWidget
::
setFilterName
(
const
QString
&
pattern
)
{
m_proxyModel
->
setFilterName
(
!
pattern
.
isEmpty
(),
pattern
);
if
(
!
pattern
.
isEmpty
())
{
QVariantList
mapped
;
foreach
(
const
QModelIndex
&
ix
,
m_model
->
getChildrenIndexes
())
{
foreach
(
const
QModelIndex
&
ix
,
m_model
->
getChildrenIndexes
())
{
mapped
<<
m_proxyModel
->
mapFromSource
(
ix
);
}
QMetaObject
::
invokeMethod
(
rootObject
(),
"expandNodes"
,
Qt
::
QueuedConnection
,
Q_ARG
(
QVariant
,
mapped
));
}
}
QVariantMap
AssetListWidget
::
getMimeData
(
const
QString
&
assetId
)
const
{
QVariantMap
mimeData
;
mimeData
.
insert
(
getMimeType
(
assetId
),
assetId
);
return
mimeData
;
}
src/assets/assetlist/view/qmltypes/asseticonprovider.cpp
View file @
d44a611f
...
...
@@ -22,14 +22,13 @@
#include
"asseticonprovider.hpp"
#include
"effects/effectsrepository.hpp"
#include
"transitions/transitionsrepository.hpp"
#include
"utils/KoIconUtils.h"
#include
<QDebug>
#include
<QFont>
#include
<QIcon>
#include
<QPainter>
#include
<QFont>
#include
"utils/KoIconUtils.h"
AssetIconProvider
::
AssetIconProvider
(
bool
effect
)