hgcacheproxymodel/tsrc/fute/HgCacheProxyModelTestApp/src/mywindow.cpp
changeset 1 e48454f237ca
child 2 49c70dcc3f17
equal deleted inserted replaced
0:89c329efa980 1:e48454f237ca
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 *  Version     : %version: 1 %
       
    17 */
       
    18 #include "mywindow.h"
       
    19 #include <hbmenu.h>
       
    20 #include <hbaction.h>
       
    21 #include <hbmainwindow.h>
       
    22 #include <hbslider.h>
       
    23 #include <QTimer>
       
    24 #include <QtGui>
       
    25 #include <QDebug>
       
    26 #include <QPushButton>
       
    27 #include <QApplication>
       
    28 #include <QGraphicsLinearLayout>
       
    29 #include <QCoreApplication>
       
    30 #include <hbgridview.h>
       
    31 #include <hbinstance.h>
       
    32 #include <QFileSystemWatcher>
       
    33 #include <hgwidgets/hgcacheproxymodel.h>
       
    34 
       
    35 #include "mydataprovider.h"
       
    36 #include "hglogger.h"
       
    37 
       
    38 
       
    39 const QStringList KViewNames = (QStringList() << "GridView" << "ListView" );
       
    40 
       
    41 MyWindow::MyWindow()
       
    42     : HbMainWindow(), 
       
    43     mView(0),
       
    44     mModel(0),
       
    45     mMyDataProvider(0),
       
    46     mTimer(new QTimer(this))
       
    47 {
       
    48     mMainView = new HbView();
       
    49     addView( mMainView );
       
    50 
       
    51     mMainView->setMenu( createMainMenu() ); 
       
    52     
       
    53     mMyDataProvider = new MyDataProvider(this);
       
    54     mModel = new HgCacheProxyModel(this);
       
    55     mModel->setDataProvider(mMyDataProvider, 120, 20);
       
    56 
       
    57     connect(mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
       
    58     
       
    59     HbAction action;
       
    60 	action.setData ( QVariant(1) );	//select Grid
       
    61 	processAction(&action);
       
    62 }
       
    63 
       
    64 MyWindow::~MyWindow()
       
    65 {
       
    66 //	delete mMyDataProvider;
       
    67 }
       
    68 
       
    69 HbMenu *MyWindow::createMainMenu()
       
    70 {
       
    71     HbMenu* mainMenu = new HbMenu( );
       
    72     connect(mainMenu, SIGNAL(triggered(HbAction*)),this, SLOT(processAction(HbAction*)));
       
    73 
       
    74     HbMenu *viewSubMenu = mainMenu->addMenu("Change view");
       
    75     QString temporaryString;
       
    76     int i(0);
       
    77     foreach (temporaryString , KViewNames) {
       
    78         HbAction* subAction = viewSubMenu->addAction(temporaryString);
       
    79         subAction->setData (QVariant(++i));
       
    80     }
       
    81     
       
    82     HbMenu *sortSubMenu = mainMenu->addMenu("Sort");
       
    83     HbAction* action = sortSubMenu->addAction("Sort1");
       
    84     action->setData(QVariant(101));
       
    85     action = sortSubMenu->addAction("Sort2");
       
    86     action->setData(QVariant(102));    
       
    87     action = sortSubMenu->addAction("Sort3");
       
    88     action->setData(QVariant(103));
       
    89     HbMenu *sort4SubMenu = sortSubMenu->addMenu("Sort4 (String)");
       
    90     action = sort4SubMenu->addAction("CaseSensitive");
       
    91     action->setData(QVariant(104));
       
    92     action = sort4SubMenu->addAction("CaseInsensitive");
       
    93     action->setData(QVariant(105));
       
    94     
       
    95     HbMenu *filterSubMenu = mainMenu->addMenu("Filter");
       
    96     action = filterSubMenu->addAction("Disable filter");
       
    97     action->setData(QVariant(201));
       
    98     action = filterSubMenu->addAction("Filter ITEM* (Case Sensitive)");
       
    99     action->setData(QVariant(202));
       
   100     action = filterSubMenu->addAction("Filter ITEM1*(Case Insensitive)");
       
   101     action->setData(QVariant(203));
       
   102     
       
   103     action = mainMenu->addAction("Reset");
       
   104     action->setData(QVariant(1000));
       
   105     action = mainMenu->addAction("Enable dynamic Sort/Filter");
       
   106     action->setData(QVariant(1001));    
       
   107 
       
   108     action = mainMenu->addAction("Test");
       
   109     action->setData(QVariant(1002));
       
   110 
       
   111     action = mainMenu->addAction("Stop Test");
       
   112     action->setData(QVariant(1003));
       
   113     
       
   114     return mainMenu;
       
   115 }
       
   116 
       
   117 
       
   118 void MyWindow::processAction( HbAction* action )
       
   119 {
       
   120     int command = action->data().toInt();
       
   121     if ( command == 1) {
       
   122         HbGridView* view = new HbGridView();
       
   123 		if ( orientation() == Qt::Horizontal ) {
       
   124 			view->setColumnCount( 5 );
       
   125 			view->setRowCount( 3 );
       
   126 		}else {
       
   127 			view->setColumnCount( 3 );
       
   128 			view->setRowCount( 5 );			
       
   129 		}
       
   130         view->setTextVisible(false);
       
   131 		view->setUniformItemSizes( true );
       
   132 		view->setItemRecycling( true );
       
   133 		//this could be done to change mode, for images it doesn't make sence, becouse images thumbnails are created by default only for medium and fullsize
       
   134 //		AbstractDataProvider *data = mModel->DataProvider();
       
   135 //		MyDataProvider *prov = static_cast<MyDataProvider*>(data); //of course we have already poiter to that - mMyDataProvider, but it is example how to get it from model
       
   136 //		prov->changeIconSize(ThumbnailManager::ThumbnailMedium);
       
   137 		view->setModel(mModel);
       
   138 		mMainView->setWidget( view );
       
   139         mView = view;
       
   140     } else if (command == 2) {
       
   141         HbListView* view = new HbListView();
       
   142 		view->setUniformItemSizes( true );
       
   143 		view->setItemRecycling( true );
       
   144 		//this could be done to change mode, for images it doesn't make sence, becouse images thumbnails are created by default only for medium and fullsize
       
   145 //		AbstractDataProvider *data = mModel->DataProvider();
       
   146 //		MyDataProvider *prov = static_cast<MyDataProvider*>(data); //of course we have already poiter to that - mMyDataProvider, but it is example how to get it from model
       
   147 //		prov->changeIconSize(ThumbnailManager::ThumbnailSmall);
       
   148 		view->setModel(mModel);
       
   149 		mMainView->setWidget( view );
       
   150         mView = view;
       
   151 	} else if (command == 101) { //sort by KSort1Role
       
   152         mModel->setSortRole(Qt::UserRole+2);
       
   153         mModel->sort(0);
       
   154 	} else if (command == 102) { //sort by KSort2Role
       
   155         mModel->setSortRole(Qt::UserRole+3);
       
   156         mModel->sort(0);
       
   157     } else if (command == 103) { //sort by KSort3Role
       
   158         mModel->setSortRole(Qt::UserRole+4);
       
   159         mModel->sort(0);
       
   160     } else if (command == 104) { //sort by DisplayRole CaseSensitive
       
   161         mModel->setSortRole(Qt::DisplayRole);
       
   162         mModel->setSortCaseSensitivity(Qt::CaseSensitive);  
       
   163         mModel->sort(0);
       
   164     } else if (command == 105) { //sort by DisplayRole CaseInsensitive
       
   165         mModel->setSortRole(Qt::DisplayRole);
       
   166         mModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
   167         mModel->sort(0);
       
   168     } else if (command == 201) { //disable filter
       
   169         QRegExp reg = QRegExp();
       
   170 //        mModel->setFilterRegExp(reg);
       
   171     } else if (command == 202) { //Filter ITEM* (Case Sensitive)
       
   172         QRegExp reg = QRegExp("ITEM*", Qt::CaseSensitive, QRegExp::Wildcard);
       
   173 //        mModel->setFilterCaseSensitivity(Qt::CaseSensitive);
       
   174 //        mModel->setFilterRegExp(reg);        
       
   175     } else if (command == 203) { //Filter ITEM1*(Case Insensitive)
       
   176         QRegExp reg = QRegExp("ITEM1*", Qt::CaseInsensitive, QRegExp::Wildcard);
       
   177 //        mModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
       
   178 //        mModel->setFilterRegExp(reg);
       
   179     } else if (command == 1000) { //reset
       
   180         mMyDataProvider->resetModel();
       
   181     } else if (command == 1001) { //reset
       
   182         bool current = !mModel->dynamicSortFilter();
       
   183         mModel->setDynamicSortFilter(current);
       
   184         if (current){
       
   185             action->setText("Disable dynamic Sort/Filter");
       
   186         }else{
       
   187             action->setText("Enable dynamic Sort/Filter");            
       
   188         }
       
   189     } else if (command == 1002) {
       
   190         mTestVal = 500;
       
   191         timeout();
       
   192     } else if (command == 1003) {
       
   193         mTestVal = 0;
       
   194     }
       
   195 }
       
   196 
       
   197 void MyWindow::setIndex(int /*index*/)
       
   198 {
       
   199     update();
       
   200 }
       
   201 
       
   202 void MyWindow::timeout()
       
   203 {   
       
   204     HbAction action;
       
   205     action.setData ( QVariant(101 + mTestVal%4) );
       
   206     processAction(&action);
       
   207 
       
   208     if (mTestVal>0){
       
   209         mTestVal--;
       
   210         mTimer->start(1000);
       
   211     }
       
   212 }
       
   213 
       
   214 //eof