Skip to content

Commit baebda5

Browse files
committed
paved the way for contact list display, still have to do the fetching of the contacts part
1 parent c3487c4 commit baebda5

19 files changed

+440
-156
lines changed

SugarCRM.pro

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ SOURCES += main.cpp \
3030
abstractitemdetail.cpp \
3131
searchfield.cpp \
3232
accountlist.cpp \
33-
calendarwidget.cpp
33+
calendarwidget.cpp \
34+
abstractitemlist.cpp \
35+
contactlist.cpp \
36+
contactproxymodel.cpp
3437
HEADERS += mainwindow.h \
3538
sugarcrmsoap.h \
3639
logindialog.h \
@@ -54,7 +57,10 @@ HEADERS += mainwindow.h \
5457
abstractitemdetail.h \
5558
searchfield.h \
5659
accountlist.h \
57-
calendarwidget.h
60+
calendarwidget.h \
61+
abstractitemlist.h \
62+
contactlist.h \
63+
contactproxymodel.h
5864
FORMS += mainwindow.ui
5965
RESOURCES += app.qrc
6066
OTHER_FILES += SugarCrm.qml \

abstractitemlist.cpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/************************************************
2+
*
3+
* Copyright © 2009-2010 Florian Staudacher
4+
5+
*
6+
*
7+
* This file is part of FSugar.
8+
*
9+
* FSugar is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* FSugar is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FSugar. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
***********************************************/
23+
24+
#include "abstractitemlist.h"
25+
#include "abstractitemdetail.h"
26+
27+
AbstractItemList::AbstractItemList(QWidget *parent) :
28+
QWidget(parent)
29+
{
30+
// initialize members
31+
listView = new QListView();
32+
tabView = new QTabWidget();
33+
welcomeText = new QLabel(tr("Waehlen sie in der Liste einen Eintrag aus, um hier die dazugehoerigen Details anzuzeigen."));
34+
search = new SearchField();
35+
36+
listView->setAlternatingRowColors(true);
37+
tabView->setTabsClosable(true);
38+
39+
// layout
40+
QHBoxLayout *layout = new QHBoxLayout();
41+
QVBoxLayout *left = new QVBoxLayout();
42+
stack = new QStackedLayout();
43+
44+
left->setSpacing(4);
45+
left->addWidget(search);
46+
left->addWidget(listView);
47+
48+
stack->addWidget(tabView);
49+
stack->addWidget(welcomeText);
50+
stack->setCurrentWidget(welcomeText);
51+
52+
layout->setSpacing(0);
53+
layout->addLayout(left, 1);
54+
layout->addLayout(stack, 2);
55+
56+
setLayout(layout);
57+
58+
// connect signals and slots
59+
connect(listView, SIGNAL(doubleClicked(QModelIndex)),
60+
this, SLOT(openDetail(QModelIndex)));
61+
connect(search, SIGNAL(searchPhraseChanged(QString)),
62+
this, SLOT(filterList(QString)));
63+
connect(tabView, SIGNAL(tabCloseRequested(int)),
64+
this, SLOT(closeDetail(int)));
65+
}
66+
67+
void AbstractItemList::filterList(QString phrase)
68+
{
69+
getModel()->setFilterRegExp(QRegExp(phrase, Qt::CaseInsensitive, QRegExp::FixedString));
70+
}
71+
72+
void AbstractItemList::closeDetail(const int index)
73+
{
74+
QWidget *tab = tabView->widget(index);
75+
tabView->removeTab(index);
76+
if(!tab->property("doNotDelete").toBool()) {
77+
tab->deleteLater();
78+
}
79+
if(tabView->count() < 1) {
80+
stack->setCurrentWidget(welcomeText);
81+
}
82+
}

abstractitemlist.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/************************************************
2+
*
3+
* Copyright © 2009-2010 Florian Staudacher
4+
5+
*
6+
*
7+
* This file is part of FSugar.
8+
*
9+
* FSugar is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* FSugar is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FSugar. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
***********************************************/
23+
24+
#ifndef ABSTRACTITEMLIST_H
25+
#define ABSTRACTITEMLIST_H
26+
27+
#include <QtGui>
28+
#include "searchfield.h"
29+
30+
class AbstractItemList : public QWidget
31+
{
32+
Q_OBJECT
33+
public:
34+
explicit AbstractItemList(QWidget *parent = 0);
35+
//virtual void setModel(QSortFilterProxyModel *model) = 0;
36+
virtual QSortFilterProxyModel* getModel() = 0;
37+
38+
signals:
39+
40+
public slots:
41+
virtual void openDetail(const QModelIndex index) = 0;
42+
void closeDetail(const int index);
43+
void filterList(QString phrase);
44+
45+
protected:
46+
QListView *listView;
47+
QTabWidget *tabView;
48+
QLabel *welcomeText;
49+
SearchField *search;
50+
QStackedLayout *stack;
51+
52+
};
53+
54+
#endif // ABSTRACTITEMLIST_H

accountlist.cpp

+12-59
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,28 @@
2525
#include "accountdetail.h"
2626

2727
AccountList::AccountList(QWidget *parent) :
28-
QWidget(parent)
28+
AbstractItemList(parent)
2929
{
30-
// initialize members
31-
accountList = new QListView();
32-
accountTabs = new QTabWidget();
33-
welcomeText = new QLabel(tr("Waehlen sie in der Liste einen Eintrag aus, um hier die dazugehoerigen Details anzuzeigen."));
34-
search = new SearchField();
35-
36-
accountList->setAlternatingRowColors(true);
37-
accountTabs->setTabsClosable(true);
38-
39-
// layout
40-
QHBoxLayout *layout = new QHBoxLayout();
41-
QVBoxLayout *left = new QVBoxLayout();
42-
stack = new QStackedLayout();
43-
44-
left->setSpacing(4);
45-
left->addWidget(search);
46-
left->addWidget(accountList);
47-
48-
stack->addWidget(accountTabs);
49-
stack->addWidget(welcomeText);
50-
stack->setCurrentWidget(welcomeText);
51-
52-
layout->setSpacing(0);
53-
layout->addLayout(left, 1);
54-
layout->addLayout(stack, 2);
55-
56-
setLayout(layout);
57-
58-
// connect signals and slots
59-
connect(accountList, SIGNAL(doubleClicked(QModelIndex)),
60-
this, SLOT(openAccountDetails(QModelIndex)));
61-
connect(search, SIGNAL(searchPhraseChanged(QString)),
62-
this, SLOT(filterAccountList(QString)));
63-
connect(accountTabs, SIGNAL(tabCloseRequested(int)),
64-
this, SLOT(closeAccountTab(int)));
6530
}
6631

6732
void AccountList::setModel(AccountProxyModel *model)
6833
{
69-
accountModel = model;
70-
accountList->setModel(accountModel);
34+
itemsModel = model;
35+
listView->setModel(itemsModel);
7136
}
7237

73-
void AccountList::openAccountDetails(const QModelIndex index)
38+
AccountProxyModel* AccountList::getModel()
7439
{
75-
QModelIndex num(accountModel->mapToSource(index));
76-
qDebug() << "[app] now's a good time to open the info for " << num.row();
77-
AccountDetail *item = new AccountDetail(&num);
78-
accountTabs->setCurrentIndex(accountTabs->addTab(item, item->getItem()->name));
79-
80-
// make the tabwidget visible
81-
stack->setCurrentWidget(accountTabs);
40+
return itemsModel;
8241
}
8342

84-
void AccountList::filterAccountList(QString phrase)
43+
void AccountList::openDetail(const QModelIndex index)
8544
{
86-
accountModel->setFilterRegExp(QRegExp(phrase, Qt::CaseInsensitive, QRegExp::FixedString));
87-
}
45+
QModelIndex num(getModel()->mapToSource(index));
46+
qDebug() << "[app] now's a good time to open the info for " << num.row();
47+
AccountDetail *item = new AccountDetail(&num);
48+
tabView->setCurrentIndex(tabView->addTab(item, item->getItem()->name));
8849

89-
void AccountList::closeAccountTab(const int index)
90-
{
91-
QWidget *tab = accountTabs->widget(index);
92-
accountTabs->removeTab(index);
93-
if(!tab->property("doNotDelete").toBool()) {
94-
tab->deleteLater();
95-
}
96-
if(accountTabs->count() < 1) {
97-
stack->setCurrentWidget(welcomeText);
98-
}
50+
// make the tabwidget visible
51+
stack->setCurrentWidget(tabView);
9952
}

accountlist.h

+8-15
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,24 @@
2424
#ifndef ACCOUNTLIST_H
2525
#define ACCOUNTLIST_H
2626

27-
#include <QtGui>
27+
#include "abstractitemlist.h"
2828
#include "accountproxymodel.h"
29-
#include "searchfield.h"
3029

31-
class AccountList : public QWidget
30+
class AccountList : public AbstractItemList
3231
{
3332
Q_OBJECT
3433
public:
35-
explicit AccountList(QWidget *parent = 0);
34+
explicit AccountList(QWidget *parent = 0);
3635
void setModel(AccountProxyModel *model);
36+
AccountProxyModel* getModel();
3737

3838
signals:
3939

4040
public slots:
41-
void openAccountDetails(const QModelIndex index);
42-
void filterAccountList(QString phrase);
43-
void closeAccountTab(const int index);
44-
45-
private:
46-
QListView *accountList;
47-
QTabWidget *accountTabs;
48-
QLabel *welcomeText;
49-
AccountProxyModel *accountModel;
50-
SearchField *search;
51-
QStackedLayout *stack;
41+
void openDetail(const QModelIndex index);
42+
43+
protected:
44+
AccountProxyModel *itemsModel;
5245

5346
};
5447

contactdetail.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323

2424
#include "abstractitemdetail.h"
2525
#include "contactdetail.h"
26+
#include "contactmodel.h"
2627

2728
ContactDetail::ContactDetail(QWidget *parent) :
2829
AbstractItemDetail(parent)
2930
{
3031
}
3132

33+
ContactDetail::ContactDetail(const QModelIndex *index)
34+
{
35+
initDialog();
36+
retrieveItem(index);
37+
fillData();
38+
}
39+
3240
void ContactDetail::initDialog()
3341
{
3442
AbstractItemDetail::initDialog();
@@ -204,3 +212,22 @@ void ContactDetail::createNewNote()
204212
connect(newNote, SIGNAL(saved()),
205213
this, SLOT(displayNotes()));
206214
}
215+
216+
void ContactDetail::retrieveItem(const QModelIndex *_index)
217+
{
218+
ContactModel *model = ContactModel::getInstance();
219+
item = model->getContact(_index->row());
220+
221+
connect(getItem(), SIGNAL(contactsAvailable()),
222+
this, SLOT(displayContacts()));
223+
connect(crm, SIGNAL(entryCreated(QString)),
224+
getItem(), SLOT(getNotes()));
225+
connect(getItem(), SIGNAL(saved()),
226+
this, SLOT(afterSaveAct()));
227+
connect(getItem(), SIGNAL(notesAvailable()),
228+
this, SLOT(displayNotes()));
229+
connect(openEmailBtn, SIGNAL(pressed()),
230+
getItem(), SLOT(openEmail()));
231+
232+
getItem()->getChildren();
233+
}

contactdetail.h

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public slots:
5050
void createNewNote();
5151

5252
private:
53+
void retrieveItem(const QModelIndex *_index);
5354
void fillData();
5455

5556
Contact *item;

contactlist.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/************************************************
2+
*
3+
* Copyright © 2009-2010 Florian Staudacher
4+
5+
*
6+
*
7+
* This file is part of FSugar.
8+
*
9+
* FSugar is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* FSugar is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FSugar. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
***********************************************/
23+
24+
#include "contactlist.h"
25+
#include "contactdetail.h"
26+
27+
ContactList::ContactList(QWidget *parent) :
28+
AbstractItemList(parent)
29+
{
30+
}
31+
32+
void ContactList::setModel(ContactProxyModel *model)
33+
{
34+
itemsModel = model;
35+
listView->setModel(itemsModel);
36+
}
37+
38+
ContactProxyModel* ContactList::getModel()
39+
{
40+
return itemsModel;
41+
}
42+
43+
void ContactList::openDetail(const QModelIndex index)
44+
{
45+
QModelIndex num(getModel()->mapToSource(index));
46+
qDebug() << "[app] now's a good time to open the info for " << num.row();
47+
ContactDetail *item = new ContactDetail(&num);
48+
tabView->setCurrentIndex(tabView->addTab(item, QString(item->getItem()->firstName).append(" ").append(item->getItem()->lastName)));
49+
50+
// make the tabwidget visible
51+
stack->setCurrentWidget(tabView);
52+
}

0 commit comments

Comments
 (0)