forked from fathomssen/redtimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssueSelector.cpp
More file actions
215 lines (159 loc) · 4.99 KB
/
IssueSelector.cpp
File metadata and controls
215 lines (159 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "IssueSelector.h"
#include "logging.h"
using namespace qtredmine;
using namespace redtimer;
using namespace std;
IssueSelector::IssueSelector( SimpleRedmineClient* redmine, MainWindow* mainWindow )
: Window( "qrc:/IssueSelector.qml", mainWindow ),
redmine_( redmine )
{
ENTER();
// Issue selector window initialisation
setModality( Qt::ApplicationModal );
setFlags( Qt::Dialog );
setTitle( "Issue Selector" );
// Set the models
issuesProxyModel_.setSourceModel( &issuesModel_ );
issuesProxyModel_.setSortRole( IssueModel::IssueRoles::IdRole );
issuesProxyModel_.setDynamicSortFilter( true );
issuesProxyModel_.setFilterCaseSensitivity( Qt::CaseInsensitive );
issuesProxyModel_.setFilterRole( IssueModel::IssueRoles::SubjectRole );
ctx_->setContextProperty( "issuesModel", &issuesProxyModel_ );
QSortFilterProxyModel* projectProxyModel = new QSortFilterProxyModel( this );
projectProxyModel->setSourceModel( &projectModel_ );
projectProxyModel->setSortRole( SimpleModel::SimpleRoles::IdRole );
projectProxyModel->setDynamicSortFilter( true );
ctx_->setContextProperty( "projectModel", projectProxyModel );
// Connect the project selected signal to the projectSelected slot
connect( qml("project"), SIGNAL(activated(int)), this, SLOT(projectSelected(int)) );
// Connect the issue selected signal to the issueSelected slot
connect( qml("issues"), SIGNAL(activated(int)), this, SLOT(issueSelected(int)) );
// Connect the search accepted signal to the filterIssues slot
connect( qml("search"), SIGNAL(textChanged()), this, SLOT(filterIssues()) );
// Connect the closed signal to the close slot
connect( this, &Window::closed, [=](){ close(); } );
RETURN();
}
void
IssueSelector::close()
{
ENTER();
Window::close();
this->deleteLater();
RETURN();
}
void
IssueSelector::display()
{
ENTER();
show();
if( projectModel_.rowCount() == 0 )
loadProjects();
RETURN();
}
void
IssueSelector::filterIssues()
{
ENTER();
QString filter = qml("search")->property("text").toString();
issuesProxyModel_.setFilterFixedString( filter );
RETURN();
}
void
IssueSelector::issueSelected( int index )
{
ENTER();
QModelIndex proxyIndex = issuesProxyModel_.index( index, 0 );
int issueId = proxyIndex.data(SimpleModel::IdRole).toInt();
DEBUG()(index)(proxyIndex)(issueId);
selected( issueId );
close();
RETURN();
}
void
IssueSelector::projectSelected( int index )
{
ENTER();
projectId_ = projectModel_.at(index).id();
DEBUG()(index)(projectId_);
loadIssues();
RETURN();
}
void
IssueSelector::loadIssues()
{
ENTER()(projectId_);
++callbackCounter_;
redmine_->retrieveIssues( [&]( Issues issues, RedmineError redmineError, QStringList errors )
{
CBENTER();
if( redmineError != NO_ERROR )
{
QString errorMsg = tr("Could not load issues.");
for( const auto& error : errors )
errorMsg.append("\n").append(error);
message( errorMsg, QtCriticalMsg );
CBRETURN();
}
issuesModel_.clear();
for( const auto& issue : issues )
issuesModel_.push_back( issue );
DEBUG()(issuesModel_);
CBRETURN();
},
RedmineOptions( QString("project_id=%1").arg(projectId_), true ) );
RETURN();
}
void
IssueSelector::loadProjects()
{
ENTER();
// Clear and set first item at once and not wait for callback
projectModel_.clear();
projectModel_.push_back( SimpleItem(NULL_ID, "Choose project") );
++callbackCounter_;
redmine_->retrieveProjects( [=]( Projects projects, RedmineError redmineError, QStringList errors )
{
CBENTER();
if( redmineError != NO_ERROR )
{
QString errorMsg = tr("Could not load projects.");
for( const auto& error : errors )
errorMsg.append("\n").append(error);
message( errorMsg, QtCriticalMsg );
CBRETURN();
}
int currentIndex = 0;
// Reset in case this has changed since calling loadProjects()
projectModel_.clear();
projectModel_.push_back( SimpleItem(NULL_ID, "Choose project") );
for( const auto& project : projects )
{
if( project.id == projectId_ )
currentIndex = projectModel_.rowCount();
projectModel_.push_back( SimpleItem(project) );
}
DEBUG()(projectModel_)(currentIndex);
qml("project")->setProperty( "currentIndex", -1 );
qml("project")->setProperty( "currentIndex", currentIndex );
CBRETURN();
},
QString("limit=100") );
}
int
IssueSelector::getProjectId() const
{
ENTER();
RETURN( projectId_ );
}
void
IssueSelector::setProjectId( int id, bool fixed )
{
ENTER();
projectId_ = id;
loadProjects();
if( fixed )
qml("project")->setProperty( "enabled", false );
loadIssues();
RETURN();
}