OSDN Git Service

[denncoCreator] Implement plugin cell edit feature. The work is in progress.
[dennco/denncoCreator.git] / Source / dcconsole.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on Oct-21, 2012.
18 //
19 #include "dcconsole.h"
20
21 DCConsole::DCConsole() : d_size(100)
22 {
23 }
24
25 void DCConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap)
26 {
27     Q_UNUSED(type);
28     QString msg = QString().vsprintf(fmt,ap);
29
30     d_queue.append(msg);
31     while (d_queue.size() > d_size)
32     {
33         d_queue.dequeue();
34     }
35 #ifdef DEBUG
36     qDebug() << msg << endl;
37 #endif
38 }
39
40 QString DCConsole::getLog(int n) const
41 {
42     if (n < 1)
43     {
44         n = d_queue.size();
45     }
46
47     QString message = "";
48     int p = d_queue.size() - n;
49     if (p < 0) p = 0;
50     for (int i = d_queue.size() - 1; i >= p; i--)
51     {
52         message.append(d_queue.at(i));
53         message.append("\n");
54     }
55     return message;
56 }
57
58 void DCConsole::clearLog()
59 {
60     d_queue.clear();
61 }