summaryrefslogtreecommitdiffstats
path: root/examples/listModel/model.cpp
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-04-30 11:40:36 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-04-30 11:40:36 +0200
commit07dde5ac4c48fb0acf8a65b88fc0f927b4fc2058 (patch)
tree695a0ca095d1f4e61ea8b395c5de1517182993aa /examples/listModel/model.cpp
parent3da06abf4ca89b3d03e44eadc82a1bdf126a1b99 (diff)
Reorganize the examples a little bit. Split the model examples from the widget examples.
Diffstat (limited to 'examples/listModel/model.cpp')
-rw-r--r--examples/listModel/model.cpp512
1 files changed, 512 insertions, 0 deletions
diff --git a/examples/listModel/model.cpp b/examples/listModel/model.cpp
new file mode 100644
index 0000000..3be8314
--- /dev/null
+++ b/examples/listModel/model.cpp
@@ -0,0 +1,512 @@
+/****************************************************************************
+**
+** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Itemviews NG project on Trolltech Labs.
+**
+** This file may be used under the terms of the GNU General Public
+** License version 2.0 or 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of
+** this file. Please review the following information to ensure GNU
+** General Public Licensing requirements will be met:
+** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#include "model.h"
+
+Model::Model(QObject *parent)
+ : QtListModelInterface(parent)
+{
+ init();
+}
+
+Model::~Model()
+{
+}
+
+int Model::count() const
+{
+ return strings.count();
+}
+
+QHash<int,QVariant> Model::data(int index, const QList<int> &roles) const
+{
+ QHash<int,QVariant> hash;
+ if (index >= 0 && index < strings.count())
+ for (int i = 0; i < roles.count(); ++i)
+ if (roles.at(i) == Qt::DisplayRole)
+ hash.insert(Qt::DisplayRole, strings.at(index));
+ return hash;
+}
+
+bool Model::setData(int index, const QHash<int,QVariant> &values)
+{
+ QHash<int,QVariant>::const_iterator it = values.find(Qt::DisplayRole);
+ if (it != values.end()) {
+ strings[index] = it.value().toString();
+ emit itemsChanged(index, 1, QList<int>() << Qt::DisplayRole);
+ return true;
+ }
+ return false;
+}
+
+bool Model::insertItems(int index, int count)
+{
+ for (int i = 0; i < count; ++i)
+ strings.insert(index, "<empty>");
+ emit itemsInserted(index, count);
+ return true;
+}
+
+bool Model::removeItems(int index, int count)
+{
+ for (int i = 0; i < count; ++i)
+ strings.removeAt(index);
+ emit itemsRemoved(index, index);
+ return true;
+}
+
+bool Model::moveItems(int from, int to, int count)
+{
+ QStringList movedStrings;
+ for (int i = 0; i < count; ++i)
+ movedStrings.append(strings.takeAt((from)));
+ for (int j = 0; j < count; ++j)
+ strings.insert(to, movedStrings.takeFirst());
+ emit itemsMoved(from, to, count);
+ return true;
+}
+
+void Model::init()
+{
+ strings << "Michael + Jennifer"
+ << "Christopher + Amanda"
+ << "Jason + Jessica"
+ << "David + Melissa"
+ << "James + Sarah"
+ << "Matthew + Heather"
+ << "Joshua + Nicole"
+ << "John + Amy"
+ << "Robert + Elizabeth"
+ << "Joseph + Michelle"
+ << "Daniel + Kimberly"
+ << "Brian + Angela"
+ << "Justin + Stephanie"
+ << "William + Tiffany"
+ << "Ryan + Christina"
+ << "Eric + Lisa"
+ << "Nicholas + Rebecca"
+ << "Jeremy + Crystal"
+ << "Andrew + Kelly"
+ << "Timothy + Erin"
+ << "Jonathan + Laura"
+ << "Adam + Amber"
+ << "Kevin + Rachel"
+ << "Anthony + Jamie"
+ << "Thomas + April"
+ << "Richard + Mary"
+ << "Jeffrey + Sara"
+ << "Steven + Andrea"
+ << "Charles + Shannon"
+ << "Brandon + Megan"
+ << "Mark + Emily"
+ << "Benjamin + Julie"
+ << "Scott + Danielle"
+ << "Aaron + Erica"
+ << "Paul + Katherine"
+ << "Nathan + Maria"
+ << "Travis + Kristin"
+ << "Patrick + Lauren"
+ << "Chad + Kristen"
+ << "Stephen + Ashley"
+ << "Kenneth + Christine"
+ << "Gregory + Brandy"
+ << "Jacob + Tara"
+ << "Dustin + Katie"
+ << "Jesse + Monica"
+ << "Jose + Carrie"
+ << "Shawn + Alicia"
+ << "Sean + Courtney"
+ << "Bryan + Misty"
+ << "Derek + Kathryn"
+ << "Bradley + Patricia"
+ << "Edward + Holly"
+ << "Donald + Stacy"
+ << "Samuel + Karen"
+ << "Peter + Anna"
+ << "Keith + Tracy"
+ << "Kyle + Brooke"
+ << "Ronald + Samantha"
+ << "Juan + Allison"
+ << "George + Melanie"
+ << "Jared + Leslie"
+ << "Douglas + Brandi"
+ << "Gary + Cynthia"
+ << "Erik + Susan"
+ << "Phillip + Natalie"
+ << "Joel + Jill"
+ << "Raymond + Dawn"
+ << "Corey + Dana"
+ << "Shane + Vanessa"
+ << "Larry + Veronica"
+ << "Marcus + Lindsay"
+ << "Zachary + Tina"
+ << "Craig + Kristina"
+ << "Derrick + Stacey"
+ << "Todd + Wendy"
+ << "Jeremiah + Lori"
+ << "Antonio + Catherine"
+ << "Carlos + Kristy"
+ << "Shaun + Heidi"
+ << "Dennis + Sandra"
+ << "Frank + Jacqueline"
+ << "Philip + Kathleen"
+ << "Cory + Christy"
+ << "Brent + Leah"
+ << "Gabriel + Valerie"
+ << "Nathaniel + Pamela"
+ << "Randy + Erika"
+ << "Luis + Tanya"
+ << "Curtis + Natasha"
+ << "Jeffery + Katrina"
+ << "Russell + Lindsey"
+ << "Alexander + Melinda"
+ << "Casey + Monique"
+ << "Jerry + Denise"
+ << "Wesley + Teresa"
+ << "Brett + Tammy"
+ << "Luke + Tonya"
+ << "Lucas + Julia"
+ << "Seth + Candice"
+ << "Billy + Gina"
+ << "Terry + Alison"
+ << "Carl + Nichole"
+ << "Mario + Theresa"
+ << "Ian + Victoria"
+ << "Jamie + Margaret"
+ << "Troy + Beth"
+ << "Victor + Renee"
+ << "Tony + Tamara"
+ << "Bobby + Linda"
+ << "Jesus + Robin"
+ << "Vincent + Nancy"
+ << "Alan + Anne"
+ << "Johnny + Sabrina"
+ << "Tyler + Meghan"
+ << "Adrian + Brenda"
+ << "Brad + Jenny"
+ << "Ricardo + Jaime"
+ << "Marc + Diana"
+ << "Christian + Cheryl"
+ << "Danny + Barbara"
+ << "Rodney + Krista"
+ << "Ricky + Kristi"
+ << "Martin + Latoya"
+ << "Allen + Bethany"
+ << "Lee + Michele"
+ << "Jimmy + Kelli"
+ << "Jon + Kara"
+ << "Miguel + Miranda"
+ << "Lawrence + Sharon"
+ << "Willie + Tasha"
+ << "Clinton + Mindy"
+ << "Micheal + Mandy"
+ << "Andre + Molly"
+ << "Roger + Candace"
+ << "Henry + Casey"
+ << "Randall + Ann"
+ << "Kristopher + Colleen"
+ << "Walter + Cassandra"
+ << "Jorge + Suzanne"
+ << "Joe + Meredith"
+ << "Jay + Latasha"
+ << "Albert + Rachael"
+ << "Cody + Regina"
+ << "Manuel + Donna"
+ << "Roberto + Marie"
+ << "Wayne + Deborah"
+ << "Arthur + Carolyn"
+ << "Gerald + Nina"
+ << "Jermaine + Deanna"
+ << "Isaac + Cindy"
+ << "Louis + Alisha"
+ << "Lance + Bridget"
+ << "Roy + Carla"
+ << "Francisco + Kendra"
+ << "Trevor + Desiree"
+ << "Alex + Tabitha"
+ << "Bruce + Kari"
+ << "Evan + Yolanda"
+ << "Jack + Summer"
+ << "Jordan + Virginia"
+ << "Frederick + Trisha"
+ << "Maurice + Rebekah"
+ << "Darren + Joanna"
+ << "Mitchell + Felicia"
+ << "Ruben + Joy"
+ << "Reginald + Bonnie"
+ << "Darrell + Jodi"
+ << "Jaime + Jaclyn"
+ << "Hector + Angel"
+ << "Omar + Adrienne"
+ << "Jonathon + Jillian"
+ << "Angel + Janet"
+ << "Ronnie + Paula"
+ << "Johnathan + Aimee"
+ << "Barry + Ebony"
+ << "Oscar + Abigail"
+ << "Eddie + Debra"
+ << "Jerome + Martha"
+ << "Terrance + Rhonda"
+ << "Ernest + Autumn"
+ << "Neil + Shanna"
+ << "Damien + Robyn"
+ << "Mathew + Carmen"
+ << "Shannon + Toni"
+ << "Calvin + Shelly"
+ << "Javier + Angelica"
+ << "Alejandro + Priscilla"
+ << "Edwin + Shawna"
+ << "Garrett + Kristine"
+ << "Eugene + Sherry"
+ << "Raul + Brittany"
+ << "Kurt + Marissa"
+ << "Clint + Claudia"
+ << "Clayton + Janelle"
+ << "Leonard + Laurie"
+ << "Fernando + Stefanie"
+ << "Tommy + Ana"
+ << "Dale + Kate"
+ << "Geoffrey + Melody"
+ << "Marvin + Caroline"
+ << "Steve + Diane"
+ << "Clifford + Tamika"
+ << "Beau + Cara"
+ << "Tyrone + Alexis"
+ << "Theodore + Rosa"
+ << "Colin + Kellie"
+ << "Harold + Tracey"
+ << "Rafael + Ruth"
+ << "Kelly + Sonia"
+ << "Terrence + Naomi"
+ << "Austin + Cristina"
+ << "Joey + Audrey"
+ << "Jarrod + Hannah"
+ << "Glenn + Sheila"
+ << "Ramon + Sonya"
+ << "Cameron + Jasmine"
+ << "Grant + Alyssa"
+ << "Melvin + Leigh"
+ << "Brendan + Whitney"
+ << "Jessie + Krystal"
+ << "Stanley + Yvonne"
+ << "Armando + Stacie"
+ << "Pedro + Anita"
+ << "Dwayne + Shauna"
+ << "Karl + Shelley"
+ << "Levi + Traci"
+ << "Eduardo + Rose"
+ << "Micah + Kerri"
+ << "Ralph + Tia"
+ << "Ross + Christie"
+ << "Byron + Olivia"
+ << "Dominic + Carol"
+ << "Marco + Adriana"
+ << "Chris + Brianne"
+ << "Caleb + Kelley"
+ << "Devin + Kristie"
+ << "Andy + Marisa"
+ << "Blake + Gloria"
+ << "Sergio + Jenna"
+ << "Erick + Leticia"
+ << "Noah + Charlene"
+ << "Howard + Terri"
+ << "Francis + Charity"
+ << "Tyson + Morgan"
+ << "Cedric + Latisha"
+ << "Heath + Nikki"
+ << "Ivan + Jana"
+ << "Leon + Angie"
+ << "Alberto + Jacquelyn"
+ << "Earl + Jeanette"
+ << "Damon + Karla"
+ << "Edgar + Christa"
+ << "Franklin + Lynn"
+ << "Alvin + Becky"
+ << "Alfred + Kathy"
+ << "Courtney + Tricia"
+ << "Clarence + Janice"
+ << "Harry + Annie"
+ << "Darryl + Kerry"
+ << "Nicolas + Ellen"
+ << "Ray + Amie"
+ << "Gilbert + Keri"
+ << "Marshall + Annette"
+ << "Cesar + Sylvia"
+ << "Dylan + Rachelle"
+ << "Alfredo + Alissa"
+ << "Dean + Frances"
+ << "Warren + Lesley"
+ << "Clifton + Abby"
+ << "Julio + Bobbie"
+ << "Enrique + Gretchen"
+ << "Kirk + Shana"
+ << "Abraham + Lakisha"
+ << "Bernard + Jami"
+ << "Daryl + Helen"
+ << "Arturo + Latonya"
+ << "Preston + Lacey"
+ << "Roderick + Dorothy"
+ << "Elijah + Keisha"
+ << "Julian + Maureen"
+ << "Antoine + Jennie"
+ << "Ashley + Yvette"
+ << "Orlando + Mayra"
+ << "Wade + Roxanne"
+ << "Andres + Alexandra"
+ << "Norman + Johanna"
+ << "Drew + Lydia"
+ << "Duane + Evelyn"
+ << "Spencer + Sandy"
+ << "Vernon + Sherri"
+ << "Morgan + Charlotte"
+ << "Ethan + Irene"
+ << "Leroy + Jody"
+ << "Demetrius + Tameka"
+ << "Lonnie + Chasity"
+ << "Brock + Connie"
+ << "Nelson + Eva"
+ << "Nickolas + Esther"
+ << "Dallas + Hillary"
+ << "Rene + Rita"
+ << "Israel + Raquel"
+ << "Bryce + Lorena"
+ << "Toby + Jessie"
+ << "Lewis + Juanita"
+ << "Salvador + Faith"
+ << "Ernesto + Billie"
+ << "Gerardo + Brandie"
+ << "Bradford + Angelina"
+ << "Marcos + Hope"
+ << "Fredrick + Staci"
+ << "Taylor + Miriam"
+ << "Lamar + Jane"
+ << "Bryant + Amelia"
+ << "Kelvin + Cassie"
+ << "Terrell + Elaine"
+ << "Jody + Maribel"
+ << "Angelo + Jocelyn"
+ << "Jayson + Joni"
+ << "Glen + Grace"
+ << "Rocky + Norma"
+ << "Don + Rochelle"
+ << "Charlie + Carly"
+ << "Neal + Elisabeth"
+ << "Lorenzo + Ginger"
+ << "Fred + Tanisha"
+ << "Damian + Hilary"
+ << "Jamal + Sally"
+ << "Trent + Alice"
+ << "Rickey + Meagan"
+ << "Kenny + Joyce"
+ << "Herbert + Lakeisha"
+ << "Jake + Carissa"
+ << "Rodolfo + Jenifer"
+ << "Lloyd + Devon"
+ << "Stuart + Beverly"
+ << "Greg + Jolene"
+ << "Donnie + Renata"
+ << "Derick + Randi"
+ << "Brady + Elisa"
+ << "Jeff + Tabatha"
+ << "Felix + Sheri"
+ << "Marlon + Brianna"
+ << "Allan + Kirsten"
+ << "Eli + Joanne"
+ << "Gordon + Tracie"
+ << "Quincy + Leanne"
+ << "Desmond + Belinda"
+ << "Ben + Jean"
+ << "Darnell + Jackie"
+ << "Dwight + Mia"
+ << "Logan + Karina"
+ << "Julius + Chrystal"
+ << "Dana + Ericka"
+ << "Leslie + Camille"
+ << "Rusty + Bobbi"
+ << "Kent + Corinne"
+ << "Darius + Ruby"
+ << "Dusty + Alma"
+ << "Rudy + Betty"
+ << "Pablo + Marisol"
+ << "Freddie + Kasey"
+ << "Lamont + Cecilia"
+ << "Jimmie + Darlene"
+ << "Max + Lee"
+ << "Roland + Caitlin"
+ << "Abel + Sophia"
+ << "Kendrick + Patrice"
+ << "Quentin + Alana"
+ << "Lester + Sasha"
+ << "Leo + Bianca"
+ << "Kareem + Elena"
+ << "Noel + Serena"
+ << "Rolando + Elisha"
+ << "Tracy + Aisha"
+ << "Jackie + Alisa"
+ << "Jamar + Jodie"
+ << "Josh + Eileen"
+ << "Darin + Terra"
+ << "Simon + Christi"
+ << "Gene + Gabriela"
+ << "Alfonso + Ryan"
+ << "Jamaal + Shirley"
+ << "Johnnie + Kim"
+ << "Perry + Briana"
+ << "Scotty + Trina"
+ << "Floyd + Joann"
+ << "Robin + Hollie"
+ << "Graham + Judith"
+ << "Rick + Antoinette"
+ << "Carlton + Guadalupe"
+ << "Dewayne + Lakesha"
+ << "Cornelius + Celeste"
+ << "Devon + Marilyn"
+ << "Kerry + Lara"
+ << "Chadwick + Rosemary"
+ << "Guy + Marsha"
+ << "Gilberto + Chandra"
+ << "Felipe + Katharine"
+ << "Bret + Kimberley"
+ << "Emmanuel + Cathy"
+ << "Cecil + Gabrielle"
+ << "Zachariah + Nora"
+ << "Rogelio + Allyson"
+ << "Antwan + Claire"
+ << "Mike + Melisa"
+ << "Milton + Lacy"
+ << "Branden + Penny"
+ << "Frankie + Judy"
+ << "Terence + Michael"
+ << "Guillermo + Nadia"
+ << "Jarrett + Mandi"
+ << "Jonah + Chelsea"
+ << "Ty + Betsy"
+ << "Loren + Lora"
+ << "Oliver + Marcia"
+ << "Kurtis + Dena"
+ << "Waylon + Emma"
+ << "Clyde + Daisy"
+ << "Gustavo + Tami"
+ << "Elias + Kenya"
+ << "Ismael + Esmeralda";
+}