Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dtk
dtk
Commits
b34822f6
Commit
b34822f6
authored
Mar 05, 2012
by
Julien Wintz
Browse files
Adding log model.
parent
25b58a30
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/dtkLog/CMakeLists.txt
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
## Copyright (C) 2008-2011 - Julien Wintz, Inria.
## Created: Thu Mar 1 14:34:49 2012 (+0100)
## Version: $Id$
## Last-Updated:
Fri
Mar
2
1
5:32:15
2012 (+0100)
## Last-Updated:
Mon
Mar
5
1
1:07:46
2012 (+0100)
## By: Julien Wintz
## Update #: 2
3
## Update #: 2
5
######################################################################
##
### Commentary:
...
...
@@ -28,9 +28,11 @@ set(${PROJECT_NAME}_HEADERS
dtkLogger.h
dtkLogEngine.h
dtkLogDestination.h
dtkLogModel.h
dtkLogView.h
)
set
(
${
PROJECT_NAME
}
_HEADERS_MOC
dtkLogModel.h
dtkLogView.h
dtkLogView_p.h
)
...
...
@@ -38,6 +40,7 @@ set(${PROJECT_NAME}_SOURCES
dtkLogger.cpp
dtkLogEngine.cpp
dtkLogDestination.cpp
dtkLogModel.cpp
dtkLogView.cpp
)
## #################################################################
...
...
src/dtkLog/dtkLogDestination.cpp
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:15:19 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
9:04
:40 2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
2:28
:40 2012 (+0100)
* By: Julien Wintz
* Update #: 5
3
* Update #: 5
9
*/
/* Commentary:
...
...
@@ -18,7 +18,7 @@
*/
#include
"dtkLogDestination.h"
#include
"dtkLog
View_p
.h"
#include
"dtkLog
Model
.h"
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
...
...
@@ -74,28 +74,28 @@ void dtkLogDestinationFile::write(const QString& message)
}
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
View
// dtkLogDestination
Model
// /////////////////////////////////////////////////////////////////
class
dtkLogDestination
View
Private
class
dtkLogDestination
Model
Private
{
public:
dtkLog
ViewList
*
view
;
dtkLog
Model
*
model
;
};
dtkLogDestination
View
::
dtkLogDestination
View
(
dtkLog
ViewList
*
view
)
:
d
(
new
dtkLogDestination
View
Private
)
dtkLogDestination
Model
::
dtkLogDestination
Model
(
dtkLog
Model
*
model
)
:
d
(
new
dtkLogDestination
Model
Private
)
{
d
->
view
=
view
;
d
->
model
=
model
;
}
dtkLogDestination
View
::~
dtkLogDestination
View
(
void
)
dtkLogDestination
Model
::~
dtkLogDestination
Model
(
void
)
{
delete
d
;
d
=
NULL
;
}
void
dtkLogDestination
View
::
write
(
const
QString
&
message
)
void
dtkLogDestination
Model
::
write
(
const
QString
&
message
)
{
d
->
view
->
append
(
message
);
d
->
model
->
append
(
message
);
}
src/dtkLog/dtkLogDestination.h
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:10:22 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
9:01:08
2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
1:11:34
2012 (+0100)
* By: Julien Wintz
* Update #:
35
* Update #:
41
*/
/* Commentary:
...
...
@@ -24,6 +24,8 @@
#include
<QtCore>
class
dtkLogModel
;
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
// /////////////////////////////////////////////////////////////////
...
...
@@ -70,20 +72,19 @@ private:
// dtkLogDestinationList
// /////////////////////////////////////////////////////////////////
class
dtkLogDestinationViewPrivate
;
class
dtkLogViewList
;
class
dtkLogDestinationModelPrivate
;
class
DTKLOG_EXPORT
dtkLogDestination
View
:
public
dtkLogDestination
class
DTKLOG_EXPORT
dtkLogDestination
Model
:
public
dtkLogDestination
{
public:
dtkLogDestination
View
(
dtkLog
ViewList
*
view
);
~
dtkLogDestination
View
(
void
);
dtkLogDestination
Model
(
dtkLog
Model
*
model
);
~
dtkLogDestination
Model
(
void
);
public:
void
write
(
const
QString
&
message
);
private:
dtkLogDestination
View
Private
*
d
;
dtkLogDestination
Model
Private
*
d
;
};
// /////////////////////////////////////////////////////////////////
...
...
src/dtkLog/dtkLogModel.cpp
0 → 100644
View file @
b34822f6
/* dtkLogModel.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Mon Mar 5 10:25:48 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 12:29:52 2012 (+0100)
* By: Julien Wintz
* Update #: 18
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include
"dtkLogModel.h"
class
dtkLogModelPrivate
{
public:
QStringList
logs
;
};
dtkLogModel
::
dtkLogModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
),
d
(
new
dtkLogModelPrivate
)
{
}
void
dtkLogModel
::
append
(
const
QString
&
message
)
{
int
row
=
d
->
logs
.
count
();
beginInsertRows
(
QModelIndex
(),
row
,
row
);
d
->
logs
.
append
(
message
);
endInsertRows
();
}
int
dtkLogModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
if
(
parent
.
isValid
())
return
0
;
return
d
->
logs
.
count
();
}
QVariant
dtkLogModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
index
.
row
()
<
0
||
index
.
row
()
>=
d
->
logs
.
size
())
return
QVariant
();
if
(
role
==
Qt
::
DisplayRole
||
role
==
Qt
::
EditRole
)
return
d
->
logs
.
at
(
index
.
row
());
return
QVariant
();
}
Qt
::
ItemFlags
dtkLogModel
::
flags
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
QAbstractItemModel
::
flags
(
index
)
|
Qt
::
ItemIsDropEnabled
;
return
QAbstractItemModel
::
flags
(
index
)
|
Qt
::
ItemIsEditable
|
Qt
::
ItemIsDragEnabled
|
Qt
::
ItemIsDropEnabled
;
}
bool
dtkLogModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
{
if
(
index
.
row
()
>=
0
&&
index
.
row
()
<
d
->
logs
.
size
()
&&
(
role
==
Qt
::
EditRole
||
role
==
Qt
::
DisplayRole
))
{
d
->
logs
.
replace
(
index
.
row
(),
value
.
toString
());
emit
dataChanged
(
index
,
index
);
return
true
;
}
return
false
;
}
bool
dtkLogModel
::
insertRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
if
(
count
<
1
||
row
<
0
||
row
>
rowCount
(
parent
))
return
false
;
beginInsertRows
(
QModelIndex
(),
row
,
row
+
count
-
1
);
for
(
int
r
=
0
;
r
<
count
;
++
r
)
d
->
logs
.
insert
(
row
,
QString
());
endInsertRows
();
return
true
;
}
bool
dtkLogModel
::
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
if
(
count
<=
0
||
row
<
0
||
(
row
+
count
)
>
rowCount
(
parent
))
return
false
;
beginRemoveRows
(
QModelIndex
(),
row
,
row
+
count
-
1
);
for
(
int
r
=
0
;
r
<
count
;
++
r
)
d
->
logs
.
removeAt
(
row
);
endRemoveRows
();
return
true
;
}
static
bool
ascendingLessThan
(
const
QPair
<
QString
,
int
>
&
s1
,
const
QPair
<
QString
,
int
>
&
s2
)
{
return
s1
.
first
<
s2
.
first
;
}
static
bool
decendingLessThan
(
const
QPair
<
QString
,
int
>
&
s1
,
const
QPair
<
QString
,
int
>
&
s2
)
{
return
s1
.
first
>
s2
.
first
;
}
void
dtkLogModel
::
sort
(
int
,
Qt
::
SortOrder
order
)
{
emit
layoutAboutToBeChanged
();
QList
<
QPair
<
QString
,
int
>
>
list
;
for
(
int
i
=
0
;
i
<
d
->
logs
.
count
();
++
i
)
list
.
append
(
QPair
<
QString
,
int
>
(
d
->
logs
.
at
(
i
),
i
));
if
(
order
==
Qt
::
AscendingOrder
)
qSort
(
list
.
begin
(),
list
.
end
(),
ascendingLessThan
);
else
qSort
(
list
.
begin
(),
list
.
end
(),
decendingLessThan
);
d
->
logs
.
clear
();
QVector
<
int
>
forwarding
(
list
.
count
());
for
(
int
i
=
0
;
i
<
list
.
count
();
++
i
)
{
d
->
logs
.
append
(
list
.
at
(
i
).
first
);
forwarding
[
list
.
at
(
i
).
second
]
=
i
;
}
QModelIndexList
oldList
=
persistentIndexList
();
QModelIndexList
newList
;
for
(
int
i
=
0
;
i
<
oldList
.
count
();
++
i
)
newList
.
append
(
index
(
forwarding
.
at
(
oldList
.
at
(
i
).
row
()),
0
));
changePersistentIndexList
(
oldList
,
newList
);
emit
layoutChanged
();
}
Qt
::
DropActions
dtkLogModel
::
supportedDropActions
(
void
)
const
{
return
QAbstractItemModel
::
supportedDropActions
()
|
Qt
::
MoveAction
;
}
src/dtkLog/dtkLogModel.h
0 → 100644
View file @
b34822f6
/* dtkLogModel.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Mon Mar 5 10:13:44 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 11:14:39 2012 (+0100)
* By: Julien Wintz
* Update #: 27
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKLOGMODEL_H
#define DTKLOGMODEL_H
#include
"dtkLogExport.h"
#include
<QtGui>
class
dtkLogModelPrivate
;
class
DTKLOG_EXPORT
dtkLogModel
:
public
QAbstractListModel
{
Q_OBJECT
public:
dtkLogModel
(
QObject
*
parent
=
0
);
public:
void
append
(
const
QString
&
message
);
public:
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
public:
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
=
Qt
::
EditRole
);
public:
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
;
public:
bool
insertRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
=
QModelIndex
());
bool
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
=
QModelIndex
());
public:
void
sort
(
int
column
,
Qt
::
SortOrder
order
=
Qt
::
AscendingOrder
);
public:
Qt
::
DropActions
supportedDropActions
(
void
)
const
;
private:
dtkLogModelPrivate
*
d
;
};
#endif
src/dtkLog/dtkLogView.cpp
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:13:52 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
9:08:23
2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
2:32:17
2012 (+0100)
* By: Julien Wintz
* Update #:
98
* Update #:
107
*/
/* Commentary:
...
...
@@ -17,6 +17,7 @@
*
*/
#include
"dtkLogModel.h"
#include
"dtkLogView.h"
#include
"dtkLogView_p.h"
...
...
@@ -53,6 +54,8 @@ dtkLogViewTree::~dtkLogViewTree(void)
dtkLogViewList
::
dtkLogViewList
(
QWidget
*
parent
)
:
QListView
(
parent
)
{
this
->
model
=
new
dtkLogModel
(
this
);
this
->
setAttribute
(
Qt
::
WA_MacShowFocusRect
,
false
);
this
->
setFrameShape
(
QFrame
::
NoFrame
);
this
->
setRuntime
();
...
...
@@ -65,16 +68,9 @@ dtkLogViewList::~dtkLogViewList(void)
void
dtkLogViewList
::
setRuntime
(
void
)
{
dtkLogger
::
instance
().
attachView
(
this
);
this
->
setModel
(
&
(
this
->
model
));
}
void
dtkLogViewList
::
append
(
const
QString
&
message
)
{
this
->
list
<<
message
;
dtkLogger
::
instance
().
attachModel
(
this
->
model
);
this
->
model
.
setStringList
(
this
->
list
);
this
->
setModel
(
this
->
model
);
}
// /////////////////////////////////////////////////////////////////
...
...
src/dtkLog/dtkLogView_p.h
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:30:16 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
9:03
:5
2
2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
1:10
:5
5
2012 (+0100)
* By: Julien Wintz
* Update #: 3
5
* Update #: 3
9
*/
/* Commentary:
...
...
@@ -24,6 +24,8 @@
#include
<QtGui>
class
dtkLogModel
;
// /////////////////////////////////////////////////////////////////
// dtkLogViewTree
// /////////////////////////////////////////////////////////////////
...
...
@@ -52,12 +54,8 @@ public:
public:
void
setRuntime
(
void
);
public:
void
append
(
const
QString
&
message
);
private:
QStringList
list
;
QStringListModel
model
;
dtkLogModel
*
model
;
};
// /////////////////////////////////////////////////////////////////
...
...
src/dtkLog/dtkLogger.cpp
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:19:52 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
8:57:59
2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
1:13:23
2012 (+0100)
* By: Julien Wintz
* Update #: 8
6
* Update #: 8
7
*/
/* Commentary:
...
...
@@ -65,21 +65,21 @@ void dtkLogger::detachFile(const QString& path)
d
->
files
.
remove
(
path
);
}
void
dtkLogger
::
attach
View
(
dtkLog
ViewList
*
view
)
void
dtkLogger
::
attach
Model
(
dtkLog
Model
*
model
)
{
d
->
views
[
view
]
=
dtkLogDestinationPointer
(
new
dtkLogDestination
View
(
view
));
d
->
models
[
model
]
=
dtkLogDestinationPointer
(
new
dtkLogDestination
Model
(
model
));
d
->
destinations
<<
d
->
views
[
view
];
d
->
destinations
<<
d
->
models
[
model
];
}
void
dtkLogger
::
detach
View
(
dtkLog
ViewList
*
view
)
void
dtkLogger
::
detach
Model
(
dtkLog
Model
*
model
)
{
if
(
!
d
->
view
s
.
contains
(
view
))
if
(
!
d
->
model
s
.
contains
(
model
))
return
;
d
->
destinations
.
removeOne
(
d
->
views
[
view
]);
d
->
destinations
.
removeOne
(
d
->
models
[
model
]);
d
->
view
s
.
remove
(
view
);
d
->
model
s
.
remove
(
model
);
}
dtkLogger
::
dtkLogger
(
void
)
:
d
(
new
dtkLoggerPrivate
)
...
...
src/dtkLog/dtkLogger.h
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:18:31 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
8:47:3
4 2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
1:13:4
4 2012 (+0100)
* By: Julien Wintz
* Update #:
29
* Update #:
30
*/
/* Commentary:
...
...
@@ -27,7 +27,7 @@
class
dtkLoggerPrivate
;
class
dtkLogDestination
;
class
dtkLog
ViewList
;
class
dtkLog
Model
;
class
DTKLOG_EXPORT
dtkLogger
{
...
...
@@ -49,8 +49,8 @@ public:
void
detachFile
(
const
QString
&
path
);
public:
void
attach
View
(
dtkLog
ViewList
*
view
);
void
detach
View
(
dtkLog
ViewList
*
view
);
void
attach
Model
(
dtkLog
Model
*
model
);
void
detach
Model
(
dtkLog
Model
*
model
);
private:
dtkLogger
(
void
);
...
...
src/dtkLog/dtkLogger_p.h
View file @
b34822f6
...
...
@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:26:54 2012 (+0100)
* Version: $Id$
* Last-Updated:
Fri
Mar
2
1
8:56:14
2012 (+0100)
* Last-Updated:
Mon
Mar
5
1
1:12:53
2012 (+0100)
* By: Julien Wintz
* Update #: 4
1
* Update #: 4
3
*/
/* Commentary:
...
...
@@ -33,9 +33,9 @@ public:
dtkLog
::
Level
level
;
public:
dtkLogDestinationPointer
console
;
QHash
<
QString
,
dtkLogDestinationPointer
>
files
;
QHash
<
dtkLog
ViewList
*
,
dtkLogDestinationPointer
>
view
s
;
dtkLogDestinationPointer
console
;
QHash
<
QString
,
dtkLogDestinationPointer
>
files
;
QHash
<
dtkLog
Model
*
,
dtkLogDestinationPointer
>
model
s
;
public:
QList
<
dtkLogDestinationPointer
>
destinations
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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